source: imaps-frontend/node_modules/which-builtin-type/README.md

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 3.4 KB
Line 
1# which-builtin-type <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![License][license-image]][license-url]
6[![Downloads][downloads-image]][downloads-url]
7
8[![npm badge][npm-badge-png]][package-url]
9
10What is the type of this builtin JavaScript value? Works cross-realm, without `instanceof`, and can not be fooled by a `constructor` property.
11
12## Example
13
14```js
15var whichBuiltinType = require('which-builtin-type');
16var assert = require('assert');
17
18assert.equal(undefined, whichBuiltinType(undefined));
19assert.equal(null, whichBuiltinType(null));
20assert.equal('Boolean', whichBuiltinType(false));
21assert.equal('Boolean', whichBuiltinType(true));
22assert.equal('Array', whichBuiltinType([]));
23assert.equal('Object', whichBuiltinType({}));
24assert.equal('RegExp', whichBuiltinType(/a/g));
25assert.equal('RegExp', whichBuiltinType(new RegExp('a', 'g')));
26assert.equal('Date', whichBuiltinType(new Date()));
27assert.equal('Number', whichBuiltinType(42));
28assert.equal('Number', whichBuiltinType(NaN));
29assert.equal('Number', whichBuiltinType(Infinity));
30assert.equal('Number', whichBuiltinType(new Number(42)));
31assert.equal('String', whichBuiltinType('foo'));
32assert.equal('String', whichBuiltinType(Object('foo')));
33assert.equal('Function', whichBuiltinType(function () {}));
34assert.equal('GeneratorFunction', whichBuiltinType(function* () {}));
35assert.equal('Function', whichBuiltinType(x => x * x));
36assert.equal('Array', whichBuiltinType([]));
37assert.equal('Int8Array', whichBuiltinType(new Int8Array()));
38assert.equal('Uint8Array', whichBuiltinType(new Uint8Array()));
39assert.equal('Uint8ClampedArray', whichBuiltinType(new Uint8ClampedArray()));
40assert.equal('Int16Array', whichBuiltinType(new Int16Array()));
41assert.equal('Uint16Array', whichBuiltinType(new Uint16Array()));
42assert.equal('Int32Array', whichBuiltinType(new Int32Array()));
43assert.equal('Uint32Array', whichBuiltinType(new Uint32Array()));
44assert.equal('Float32Array', whichBuiltinType(new Float32Array()));
45assert.equal('Float64Array', whichBuiltinType(new Float64Array()));
46assert.equal('BigInt64Array', whichBuiltinType(new BigInt64Array()));
47assert.equal('BigUint64Array', whichBuiltinType(new BigUint64Array()));
48```
49
50## Tests
51Simply clone the repo, `npm install`, and run `npm test`
52
53[package-url]: https://npmjs.org/package/which-builtin-type
54[npm-version-svg]: https://versionbadg.es/inspect-js/which-builtin-type.svg
55[deps-svg]: https://david-dm.org/inspect-js/which-builtin-type.svg
56[deps-url]: https://david-dm.org/inspect-js/which-builtin-type
57[dev-deps-svg]: https://david-dm.org/inspect-js/which-builtin-type/dev-status.svg
58[dev-deps-url]: https://david-dm.org/inspect-js/which-builtin-type#info=devDependencies
59[npm-badge-png]: https://which-builtin-type/which-builtin-type.png?downloads=true&stars=true
60[license-image]: https://img.shields.io/npm/l/which-builtin-type.svg
61[license-url]: LICENSE
62[downloads-image]: https://img.shields.io/npm/dm/which-builtin-type.svg
63[downloads-url]: https://npm-stat.com/charts.html?package=which-builtin-type
64[codecov-image]: https://codecov.io/gh/inspect-js/which-builtin-type/branch/main/graphs/badge.svg
65[codecov-url]: https://app.codecov.io/gh/inspect-js/which-builtin-type/
66[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/which-builtin-type
67[actions-url]: https://github.com/inspect-js/which-builtin-type/actions
Note: See TracBrowser for help on using the repository browser.