source: imaps-frontend/node_modules/which-boxed-primitive/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.0 KB
Line 
1# which-boxed-primitive <sup>[![Version Badge][2]][1]</sup>
2
3[![dependency status][5]][6]
4[![dev dependency status][7]][8]
5[![License][license-image]][license-url]
6[![Downloads][downloads-image]][downloads-url]
7
8[![npm badge][11]][1]
9
10Which kind of boxed JS primitive is this? This module works cross-realm/iframe, does not depend on `instanceof` or mutable properties, and works despite ES6 Symbol.toStringTag.
11
12## Example
13
14```js
15var whichBoxedPrimitive = require('which-boxed-primitive');
16var assert = require('assert');
17
18// unboxed primitives return `null`
19// boxed primitives return the builtin constructor name
20
21assert.equal(whichBoxedPrimitive(undefined), null);
22assert.equal(whichBoxedPrimitive(null), null);
23
24assert.equal(whichBoxedPrimitive(false), null);
25assert.equal(whichBoxedPrimitive(true), null);
26assert.equal(whichBoxedPrimitive(new Boolean(false)), 'Boolean');
27assert.equal(whichBoxedPrimitive(new Boolean(true)), 'Boolean');
28
29assert.equal(whichBoxedPrimitive(42), null);
30assert.equal(whichBoxedPrimitive(NaN), null);
31assert.equal(whichBoxedPrimitive(Infinity), null);
32assert.equal(whichBoxedPrimitive(new Number(42)), 'Number');
33assert.equal(whichBoxedPrimitive(new Number(NaN)), 'Number');
34assert.equal(whichBoxedPrimitive(new Number(Infinity)), 'Number');
35
36assert.equal(whichBoxedPrimitive(''), null);
37assert.equal(whichBoxedPrimitive('foo'), null);
38assert.equal(whichBoxedPrimitive(new String('')), 'String');
39assert.equal(whichBoxedPrimitive(new String('foo')), 'String');
40
41assert.equal(whichBoxedPrimitive(Symbol()), null);
42assert.equal(whichBoxedPrimitive(Object(Symbol()), 'Symbol');
43
44assert.equal(whichBoxedPrimitive(42n), null);
45assert.equal(whichBoxedPrimitive(Object(42n), 'BigInt');
46
47// non-boxed-primitive objects return `undefined`
48assert.equal(whichBoxedPrimitive([]), undefined);
49assert.equal(whichBoxedPrimitive({}), undefined);
50assert.equal(whichBoxedPrimitive(/a/g), undefined);
51assert.equal(whichBoxedPrimitive(new RegExp('a', 'g')), undefined);
52assert.equal(whichBoxedPrimitive(new Date()), undefined);
53assert.equal(whichBoxedPrimitive(function () {}), undefined);
54assert.equal(whichBoxedPrimitive(function* () {}), undefined);
55assert.equal(whichBoxedPrimitive(x => x * x), undefined);
56assert.equal(whichBoxedPrimitive([]), undefined);
57
58```
59
60## Tests
61Simply clone the repo, `npm install`, and run `npm test`
62
63[1]: https://npmjs.org/package/which-boxed-primitive
64[2]: https://versionbadg.es/inspect-js/which-boxed-primitive.svg
65[5]: https://david-dm.org/inspect-js/which-boxed-primitive.svg
66[6]: https://david-dm.org/inspect-js/which-boxed-primitive
67[7]: https://david-dm.org/inspect-js/which-boxed-primitive/dev-status.svg
68[8]: https://david-dm.org/inspect-js/which-boxed-primitive#info=devDependencies
69[11]: https://nodei.co/npm/which-boxed-primitive.png?downloads=true&stars=true
70[license-image]: https://img.shields.io/npm/l/which-boxed-primitive.svg
71[license-url]: LICENSE
72[downloads-image]: https://img.shields.io/npm/dm/which-boxed-primitive.svg
73[downloads-url]: https://npm-stat.com/charts.html?package=which-boxed-primitive
Note: See TracBrowser for help on using the repository browser.