Skip to content

Is this value a JS WeakMap? This module works cross-realm/iframe, and despite ES6 @@toStringTag.

License

Notifications You must be signed in to change notification settings

inspect-js/is-weakmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7947f89 · Nov 12, 2024

History

53 Commits
Mar 8, 2024
Nov 10, 2019
Dec 11, 2021
Nov 2, 2022
Nov 11, 2019
May 8, 2021
Mar 8, 2024
Nov 11, 2019
Mar 8, 2024
Mar 8, 2024
Mar 11, 2024
Nov 12, 2024
Mar 11, 2024

Repository files navigation

is-weakmap Version Badge

github actions coverage License Downloads

npm badge

Is this value a JS WeakMap? This module works cross-realm/iframe, and despite ES6 @@toStringTag.

Example

var isWeakMap = require('is-weakmap');
assert(!isWeakMap(function () {}));
assert(!isWeakMap(null));
assert(!isWeakMap(function* () { yield 42; return Infinity; });
assert(!isWeakMap(Symbol('foo')));
assert(!isWeakMap(1n));
assert(!isWeakMap(Object(1n)));

assert(!isWeakMap(new Set()));
assert(!isWeakMap(new WeakSet()));
assert(!isWeakMap(new Map()));

assert(isWeakMap(new WeakMap()));

class MyWeakMap extends WeakMap {}
assert(isWeakMap(new MyWeakMap()));

Tests

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