Nomad Packaging Mechanism

    @types/unbox-primitive
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    Installation

    npm install --save @types/unbox-primitive

    Summary

    This package contains type definitions for unbox-primitive (https://github.com/ljharb/unbox-primitive#readme).

    Details

    Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/unbox-primitive.

    index.d.ts

    // Type definitions for unbox-primitive 1.0
    // Project: https://github.com/ljharb/unbox-primitive#readme
    // Definitions by: BendingBender <https://github.com/BendingBender>
    // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
    
    export = unboxPrimitive;
    
    /**
     * Unbox a boxed JS primitive value. This function works cross-realm/iframe,
     * does not depend on `instanceof` or mutable properties, and works despite ES6 `Symbol.toStringTag`.
     *
     * @example
     * import unboxPrimitive = require('unbox-primitive');
     * import * as assert from 'node:assert';
     *
     * assert.equal(unboxPrimitive(new Boolean(false)), false);
     * assert.equal(unboxPrimitive(new String('f')), 'f');
     * assert.equal(unboxPrimitive(new Number(42)), 42);
     * const s = Symbol();
     * assert.equal(unboxPrimitive(Object(s)), s);
     * assert.equal(unboxPrimitive(Object(BigInt(42))), BigInt(42));
     */
    declare function unboxPrimitive<T extends unboxPrimitive.Boxed>(value: T): unboxPrimitive.Unbox<T>;
    
    declare namespace unboxPrimitive {
        type Boxed = String | Number | Boolean | Symbol | BigInt;
        type Unbox<T extends Boxed> = T extends String
            ? string
            : T extends Number
            ? number
            : T extends Boolean
            ? boolean
            : T extends Symbol
            ? symbol
            : T extends BigInt
            ? bigint
            : never;
    }

    Additional Details

    • Last updated: Fri, 04 Nov 2022 14:32:47 GMT
    • Dependencies: none
    • Global values: none

    Credits

    These definitions were written by BendingBender.

    Keywords

    none

    Install

    npm i @types/unbox-primitive

    DownloadsWeekly Downloads

    22,551

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    5.3 kB

    Total Files

    5

    Last publish

    Collaborators

    • types