
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
weakmap-polyfill
Advanced tools
Supply Chain Security
Vulnerability
Quality
Maintenance
License
The weakmap-polyfill npm package provides a polyfill for the WeakMap object, which is a collection of key/value pairs where the keys are objects and the values can be arbitrary values. This polyfill is useful for environments that do not natively support WeakMap.
Creating a WeakMap
This feature allows you to create a new instance of a WeakMap using the polyfill.
const WeakMapPolyfill = require('weakmap-polyfill');
const wm = new WeakMapPolyfill();
Setting a value
This feature allows you to set a value in the WeakMap for a specific object key.
const obj = {};
wm.set(obj, 'value');
Getting a value
This feature allows you to retrieve a value from the WeakMap using an object key.
const value = wm.get(obj);
Checking for a key
This feature allows you to check if a specific object key exists in the WeakMap.
const hasKey = wm.has(obj);
Deleting a key
This feature allows you to remove a key/value pair from the WeakMap.
wm.delete(obj);
core-js is a modular standard library for JavaScript that includes polyfills for various ECMAScript features, including WeakMap. It provides a comprehensive set of polyfills for modern JavaScript features, making it a more extensive solution compared to weakmap-polyfill.
es6-weak-map is another polyfill for the WeakMap object. It provides similar functionality to weakmap-polyfill but is specifically focused on WeakMap, making it a more lightweight alternative to core-js.
ECMAScript6 WeakMap polyfill.
$ npm install --save weakmap-polyfill
Import or require weakmap-polyfill
, then WeakMap will be defined in the global scope if native WeakMap is not supported in running environment.
import
import 'weakmap-polyfill';
const weakMap = new WeakMap();
require
require('weakmap-polyfill');
var weakMap = new WeakMap();
<script src="weakmap-polyfill.min.js"></script>
<script>
var weakMap = new WeakMap();
</script>
This polyfill has following few limitations.
iterable
argument is not supported. (23.3.1.1 WeakMap ( [ iterable ] ))MIT
FAQs
ECMAScript6 WeakMap polyfill
The npm package weakmap-polyfill receives a total of 208,176 weekly downloads. As such, weakmap-polyfill popularity was classified as popular.
We found that weakmap-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.