@cowprotocol/cow-sdk
Version:
<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>
65 lines (55 loc) • 2.7 kB
Markdown
[![Build Status][3]][4]
[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][11]][1]
Which kind of Collection (Map, Set, WeakMap, WeakSet) is this JavaScript value? Works cross-realm, without `instanceof`, and despite Symbol.toStringTag.
## Example
```js
var whichCollection = require('which-collection');
var assert = require('assert');
assert.equal(false, whichCollection(undefined));
assert.equal(false, whichCollection(null));
assert.equal(false, whichCollection(false));
assert.equal(false, whichCollection(true));
assert.equal(false, whichCollection([]));
assert.equal(false, whichCollection({}));
assert.equal(false, whichCollection(/a/g));
assert.equal(false, whichCollection(new RegExp('a', 'g')));
assert.equal(false, whichCollection(new Date()));
assert.equal(false, whichCollection(42));
assert.equal(false, whichCollection(NaN));
assert.equal(false, whichCollection(Infinity));
assert.equal(false, whichCollection(new Number(42)));
assert.equal(false, whichCollection(42n));
assert.equal(false, whichCollection(Object(42n)));
assert.equal(false, whichCollection('foo'));
assert.equal(false, whichCollection(Object('foo')));
assert.equal(false, whichCollection(function () {}));
assert.equal(false, whichCollection(function* () {}));
assert.equal(false, whichCollection(x => x * x));
assert.equal(false, whichCollection([]));
assert.equal('Map', whichCollection(new Map()));
assert.equal('Set', whichCollection(new Set()));
assert.equal('WeakMap', whichCollection(new WeakMap()));
assert.equal('WeakSet', whichCollection(new WeakSet()));
```
Simply clone the repo, `npm install`, and run `npm test`
[]: https://npmjs.org/package/which-collection
[]: http://versionbadg.es/inspect-js/which-collection.svg
[]: https://travis-ci.org/inspect-js/which-collection.svg
[]: https://travis-ci.org/inspect-js/which-collection
[]: https://david-dm.org/inspect-js/which-collection.svg
[]: https://david-dm.org/inspect-js/which-collection
[]: https://david-dm.org/inspect-js/which-collection/dev-status.svg
[]: https://david-dm.org/inspect-js/which-collection#info=devDependencies
[]: https://ci.testling.com/inspect-js/which-collection.png
[]: https://ci.testling.com/inspect-js/which-collection
[]: https://nodei.co/npm/which-collection.png?downloads=true&stars=true
[]: http://img.shields.io/npm/l/which-collection.svg
[]: LICENSE
[]: http://img.shields.io/npm/dm/which-collection.svg
[]: http://npm-stat.com/charts.html?package=which-collection