JSPM

map.prototype.getorinsertcomputed

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q23771F
  • License MIT

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

Package Exports

  • map.prototype.getorinsertcomputed
  • map.prototype.getorinsertcomputed/auto
  • map.prototype.getorinsertcomputed/implementation
  • map.prototype.getorinsertcomputed/package.json
  • map.prototype.getorinsertcomputed/polyfill
  • map.prototype.getorinsertcomputed/shim

Readme

map.prototype.getorinsertcomputed Version Badge

github actions coverage License Downloads

npm badge

An ESnext spec-compliant Map.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 map.prototype.getorinsertcomputed

Usage/Examples

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

var map = new Map();
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('map.prototype.getorinsertcomputed/polyfill');
var shim = require('map.prototype.getorinsertcomputed/shim');
var assert = require('assert');
/* when Map.prototype.getOrInsertComputed is not present */
delete Map.prototype.getOrInsertComputed;
var shimmed = shim();

assert.equal(shimmed, getPolyfill());

var map = new Map();
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('map.prototype.getorinsertcomputed/shim');
var assert = require('assert');
/* when Map.prototype.getOrInsertComputed is present */
var shimmed = shim();

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

var map = new Map();
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