# which-collection

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

Latest version **1.0.2** (published 2024-03-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install which-collection
pnpm add which-collection
yarn add which-collection
bun add which-collection
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2024-03-08 |
| First published | 2019-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 4 |
| Unpacked size | 19.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | map, set, weakmap, weakset, collection.es6, es2015 |

## Links

- npm: https://www.npmjs.com/package/which-collection
- Repository: https://github.com/inspect-js/which-collection
- Homepage: https://github.com/inspect-js/which-collection#readme
- Issues: https://github.com/inspect-js/which-collection/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/which-collection

## Dependencies (4)

- [is-map](https://npm.io/package/is-map.md) ^2.0.3
- [is-set](https://npm.io/package/is-set.md) ^2.0.3
- [is-weakmap](https://npm.io/package/is-weakmap.md) ^2.0.2
- [is-weakset](https://npm.io/package/is-weakset.md) ^2.0.3

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2024-03-08
- 1.0.1 — 2020-01-26
- 1.0.0 — 2019-11-13

## README

# which-collection <sup>[![Version Badge][2]][1]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![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()));
```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[1]: https://npmjs.org/package/which-collection
[2]: https://versionbadg.es/inspect-js/which-collection.svg
[5]: https://david-dm.org/inspect-js/which-collection.svg
[6]: https://david-dm.org/inspect-js/which-collection
[7]: https://david-dm.org/inspect-js/which-collection/dev-status.svg
[8]: https://david-dm.org/inspect-js/which-collection#info=devDependencies
[11]: https://nodei.co/npm/which-collection.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/which-collection.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/which-collection.svg
[downloads-url]: https://npm-stat.com/charts.html?package=which-collection
[codecov-image]: https://codecov.io/gh/inspect-js/which-collection/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/inspect-js/which-collection/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/which-collection
[actions-url]: https://github.com/inspect-js/which-collection/actions

---
_Source: https://npm.io/package/which-collection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
