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

1.0.3 • 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

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: Tue, 07 Nov 2023 15:11:36 GMT
  • Dependencies: none

Credits

These definitions were written by BendingBender.

Readme

Keywords

none

Package Sidebar

Install

npm i @types/unbox-primitive

Weekly Downloads

16,063

Version

1.0.3

License

MIT

Unpacked Size

4.72 kB

Total Files

5

Last publish

Collaborators

  • types