mirror-rhinstaller-node-cache/which-collection
2026-07-21 13:39:22 +00:00
..
test 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
.eslintrc 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
.nycrc 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
CHANGELOG.md 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
index.d.ts 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
index.js 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
LICENSE 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
package.json 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
README.md 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00
tsconfig.json 70a54663980edde26ebea82117fe36be1872d66a4e0b8026c243e93fe6b54685 package.json 2026-07-21 13:39:22 +00:00

which-collection Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

Which kind of Collection (Map, Set, WeakMap, WeakSet) is this JavaScript value? Works cross-realm, without instanceof, and despite Symbol.toStringTag.

Example

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()));

Tests

Simply clone the repo, npm install, and run npm test