source: imaps-frontend/node_modules/which-collection/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: 2.8 KB
Line 
1# which-collection <sup>[![Version Badge][2]][1]</sup>
2
3[![github actions][actions-image]][actions-url]
4[![coverage][codecov-image]][codecov-url]
5[![dependency status][5]][6]
6[![dev dependency status][7]][8]
7[![License][license-image]][license-url]
8[![Downloads][downloads-image]][downloads-url]
9
10[![npm badge][11]][1]
11
12Which kind of Collection (Map, Set, WeakMap, WeakSet) is this JavaScript value? Works cross-realm, without `instanceof`, and despite Symbol.toStringTag.
13
14## Example
15
16```js
17var whichCollection = require('which-collection');
18var assert = require('assert');
19
20assert.equal(false, whichCollection(undefined));
21assert.equal(false, whichCollection(null));
22assert.equal(false, whichCollection(false));
23assert.equal(false, whichCollection(true));
24assert.equal(false, whichCollection([]));
25assert.equal(false, whichCollection({}));
26assert.equal(false, whichCollection(/a/g));
27assert.equal(false, whichCollection(new RegExp('a', 'g')));
28assert.equal(false, whichCollection(new Date()));
29assert.equal(false, whichCollection(42));
30assert.equal(false, whichCollection(NaN));
31assert.equal(false, whichCollection(Infinity));
32assert.equal(false, whichCollection(new Number(42)));
33assert.equal(false, whichCollection(42n));
34assert.equal(false, whichCollection(Object(42n)));
35assert.equal(false, whichCollection('foo'));
36assert.equal(false, whichCollection(Object('foo')));
37assert.equal(false, whichCollection(function () {}));
38assert.equal(false, whichCollection(function* () {}));
39assert.equal(false, whichCollection(x => x * x));
40assert.equal(false, whichCollection([]));
41
42assert.equal('Map', whichCollection(new Map()));
43assert.equal('Set', whichCollection(new Set()));
44assert.equal('WeakMap', whichCollection(new WeakMap()));
45assert.equal('WeakSet', whichCollection(new WeakSet()));
46```
47
48## Tests
49Simply clone the repo, `npm install`, and run `npm test`
50
51[1]: https://npmjs.org/package/which-collection
52[2]: https://versionbadg.es/inspect-js/which-collection.svg
53[5]: https://david-dm.org/inspect-js/which-collection.svg
54[6]: https://david-dm.org/inspect-js/which-collection
55[7]: https://david-dm.org/inspect-js/which-collection/dev-status.svg
56[8]: https://david-dm.org/inspect-js/which-collection#info=devDependencies
57[11]: https://nodei.co/npm/which-collection.png?downloads=true&stars=true
58[license-image]: https://img.shields.io/npm/l/which-collection.svg
59[license-url]: LICENSE
60[downloads-image]: https://img.shields.io/npm/dm/which-collection.svg
61[downloads-url]: https://npm-stat.com/charts.html?package=which-collection
62[codecov-image]: https://codecov.io/gh/inspect-js/which-collection/branch/main/graphs/badge.svg
63[codecov-url]: https://app.codecov.io/gh/inspect-js/which-collection/
64[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/which-collection
65[actions-url]: https://github.com/inspect-js/which-collection/actions
Note: See TracBrowser for help on using the repository browser.