which-collection (1.0.2)

Published 2026-02-24 14:08:36 +00:00 by atheaadmin

Installation

registry=
npm install which-collection@1.0.2
"which-collection": "1.0.2"

About this package

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

Dependencies

Dependencies

ID Version
is-map ^2.0.3
is-set ^2.0.3
is-weakmap ^2.0.2
is-weakset ^2.0.3

Development Dependencies

ID Version
@arethetypeswrong/cli ^0.15.0
@ljharb/eslint-config ^21.1.0
@types/for-each ^0.3.3
@types/object-inspect ^1.8.4
@types/tape ^5.6.4
aud ^2.0.4
auto-changelog ^2.4.0
eslint =8.8.0
for-each ^0.3.3
in-publish ^2.0.1
npmignore ^0.3.1
nyc ^10.3.2
object-inspect ^1.13.1
safe-publish-latest ^2.0.0
tape ^5.7.5
typescript next

Keywords

map set weakmap weakset collection.es6 es2015
Details
npm
2026-02-24 14:08:36 +00:00
0
Jordan Harband
MIT
latest
7.1 KiB
Assets (1)
Versions (1) View all
1.0.2 2026-02-24