Socket
Book a DemoInstallSign in
Socket

weakmap.prototype.getorinsertcomputed

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weakmap.prototype.getorinsertcomputed

ES Proposal spec-compliant shim for WeakMap.prototype.getOrInsertComputed

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

weakmap.prototype.getorinsertcomputed Version Badge

github actions coverage License Downloads

npm badge

An ESnext spec-compliant WeakMap.prototype.getOrInsertComputed shim/polyfill/replacement that works as far down as ES3.

This package implements the es-shim API v3 interface. It works in an ES3-supported environment and complies with the proposed spec.

Getting started

npm install --save weakmap.prototype.getorinsertcomputed

Usage/Examples

var getOrInsertComputed = require('weakmap.prototype.getorinsertcomputed');
var assert = require('assert');

var map = new WeakMap();
var key = {};
var value = {};

assert.equal(map.has(key), false);
assert.equal(getOrInsertComputed(map, key, () => value), value);
assert.equal(map.has(key), true);
var getPolyfill = require('weakmap.prototype.getorinsertcomputed/polyfill');
var shim = require('weakmap.prototype.getorinsertcomputed/shim');
var assert = require('assert');
/* when WeakMap.prototype.getOrInsertComputed is not present */
delete WeakMap.prototype.getOrInsertComputed;
var shimmed = shim();

assert.equal(shimmed, getPolyfill());

var map = new WeakMap();
var key = {};
var value = {};

assert.equal(map.has(key), false);
assert.equal(map.getOrInsertComputed(key, () => value), value);
assert.equal(map.has(key), true);
var shim = require('weakmap.prototype.getorinsertcomputed/shim');
var assert = require('assert');
/* when WeakMap.prototype.getOrInsertComputed is present */
var shimmed = shim();

assert.equal(shimmed, WeakMap.prototype.getOrInsertComputed);

var map = new WeakMap();
var key = {};
var value = {};

assert.equal(map.has(key), false);
assert.equal(map.getOrInsertComputed(key, () => value), value);
assert.equal(map.has(key), true);

Tests

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

Keywords

javascript

FAQs

Package last updated on 03 May 2025

Did you know?

Socket

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.

Install

Related posts