Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

which-collection

inspect-js74.3mMIT1.0.2TypeScript support: included

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

map, set, weakmap, weakset, collection.es6, es2015

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.2 - 2024-03-08

Commits

  • [actions] reuse common workflows a5b2949
  • [Tests] migrate tests to Github Actions 283ec03
  • add types bf576db
  • [actions] use node/install instead of node/run; use codecov action 24968a2
  • [Dev Deps] update eslint, @ljharb/eslint-config, object-inspect, safe-publish-latest, tape f60b277
  • [Tests] run nyc on all tests 5700269
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape eb1f1a4
  • [actions] remove redundant finisher cd5b8fc
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape f5786fa
  • [actions] update rebase action to use reusable workflow 7ac7b67
  • [actions] update codecov uploader b074105
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, object-inspect, tape ec640d6
  • [actions] add "Allow Edits" workflow 65d842e
  • [readme] remove travis badge f106289
  • [Dev Deps] update @ljharb/eslint-config, aud, npmignore, object-inspect, tape e784a1f
  • [meta] use npmignore to autogenerate an npmignore file 95b503f
  • [readme] add actions and codecov badges 121ba2d
  • [Deps] update is-map, is-set, is-weakmap, is-weakset 4aa150f
  • [meta] simplify "exports" 2afaed7
  • [Deps] update is-map, is-set ce44763
  • [actions] switch Automatic Rease workflow to pull_request_target event b16b664
  • [Dev Deps] update auto-changelog, tape 2b9c953
  • [meta] add missing engines.node dcdbfde
  • [Dev Deps] update auto-changelog; add aud 8e7f28d
  • [meta] add sideEffects flag 3e0376b
  • [Deps] update is-weakset 7b3e922
  • [Tests] only audit prod deps 3339fea

v1.0.1 - 2020-01-26

Commits

  • [actions] add automatic rebasing / merge commit blocking c3820b2
  • [patch] add "exports" 10983b5
  • [Deps] update is-map, is-set, is-weakmap, is-weakset 1565925
  • [Dev Deps] update eslint, @ljharb/eslint-config, tape 92ef871
  • [Dev Deps] update @ljharb/eslint-config 61e9cde

v1.0.0 - 2019-11-13

Commits