Security News
OpenJS: “XZ Utils Cyberattack Likely Not an Isolated Incident”
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
is-weakmap
Advanced tools
Weekly downloads
Package description
The is-weakmap npm package is a utility that allows developers to check if a given value is a WeakMap. WeakMaps are collections of key/value pairs where the keys are weakly referenced, meaning they can be garbage collected if there is no other reference to the object. This package provides a straightforward way to determine if an object is an instance of a WeakMap, which can be useful in various programming scenarios where type checking is necessary.
Checking if a value is a WeakMap
This feature allows developers to check if a given value is an instance of WeakMap. The function returns true if the value is a WeakMap, and false otherwise. This can be particularly useful when working with data structures and ensuring that certain operations or functions are only applied to WeakMaps.
const isWeakMap = require('is-weakmap');
const wm = new WeakMap();
console.log(isWeakMap(wm)); // true
const obj = {};
console.log(isWeakMap(obj)); // false
Similar to is-weakmap, is-map checks if a given value is a Map. While is-weakmap focuses on WeakMaps, is-map targets Maps, which are collections of key/value pairs but with keys that are not weakly referenced. Both packages serve similar purposes in type checking but for different types of collections.
Part of the Lodash library, lodash.isweakmap provides a similar functionality to is-weakmap by checking if a value is a WeakMap. Lodash is a broader utility library that offers a wide range of functions for different types of checks and operations, making lodash.isweakmap a part of a larger ecosystem. Compared to is-weakmap, which is focused solely on WeakMaps, lodash.isweakmap benefits from being part of the well-established Lodash library.
Readme
Is this value a JS WeakMap? This module works cross-realm/iframe, and despite ES6 @@toStringTag.
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()));
Simply clone the repo, npm install
, and run npm test
FAQs
Is this value a JS WeakMap? This module works cross-realm/iframe, and despite ES6 @@toStringTag.
The npm package is-weakmap receives a total of 12,623,383 weekly downloads. As such, is-weakmap popularity was classified as popular.
We found that is-weakmap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.
Company News
Come meet the Socket team at BSidesSF and RSA! We're sponsoring several fun networking events and we would love to see you there.
Security News
OSI is starting a conversation aimed at removing the excuse of the SaaS loophole for companies navigating licensing and the complexities of doing business with open source.