
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
weakmap-polyfill
Advanced tools
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
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.