Skip to content

Commit 3bd9daa

Browse files
committed
Initial implementation, tests, readme
1 parent b4cb4f2 commit 3bd9daa

21 files changed

+470
-4
lines changed

.eslintrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"id-length": "off",
8+
"new-cap": ["error", {
9+
"capIsNewExceptions": [
10+
"CanonicalizeKeyedCollectionKey",
11+
],
12+
}]
13+
},
14+
}

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [ljharb]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: npm/map.prototype.getorinsert
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/node-aught.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Tests: node.js < 10'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/node.yml@main
8+
with:
9+
range: '< 10'
10+
type: minors
11+
command: npm run tests-only
12+
13+
node:
14+
name: 'node < 10'
15+
needs: [tests]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- run: 'echo tests completed'

.github/workflows/node-pretest.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Tests: pretest/posttest'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/pretest.yml@main

.github/workflows/node-tens.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: 'Tests: node.js >= 10'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/node.yml@main
8+
with:
9+
range: '>= 10'
10+
type: minors
11+
command: npm run tests-only
12+
13+
node:
14+
name: 'node >= 10'
15+
needs: [tests]
16+
runs-on: ubuntu-latest
17+
steps:
18+
- run: 'echo tests completed'

.github/workflows/rebase.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Automatic Rebase
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
_:
7+
uses: ljharb/actions/.github/workflows/rebase.yml@main
8+
secrets:
9+
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Require “Allow Edits”
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
_:
7+
name: "Require “Allow Edits”"
8+
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: ljharb/require-allow-edits@main

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ npm-shrinkwrap.json
140140
package-lock.json
141141
yarn.lock
142142

143+
.npmignore

.nycrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"all": true,
3+
"check-coverage": false,
4+
"reporter": ["text-summary", "text", "html", "json"],
5+
"lines": 86,
6+
"statements": 85.93,
7+
"functions": 82.43,
8+
"branches": 76.06,
9+
"exclude": [
10+
"coverage",
11+
"test"
12+
]
13+
}

README.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,88 @@
1-
# Map.prototype.getOrInsert
2-
ES Proposal spec-compliant shim for Map.prototype.getOrInsert
1+
# map.prototype.getorinsert <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2+
3+
[![github actions][actions-image]][actions-url]
4+
[![coverage][codecov-image]][codecov-url]
5+
[![License][license-image]][license-url]
6+
[![Downloads][downloads-image]][downloads-url]
7+
8+
[![npm badge][npm-badge-png]][package-url]
9+
10+
An ESnext spec-compliant `Map.prototype.getOrInsert` shim/polyfill/replacement that works as far down as ES3.
11+
12+
This package implements the [es-shim API](https://github.com/es-shims/api) v3 interface. It works in an ES3-supported environment and complies with the proposed [spec](https://tc39.github.io/proposal-array-grouping/).
13+
14+
## Getting started
15+
16+
```sh
17+
npm install --save map.prototype.getorinsert
18+
```
19+
20+
## Usage/Examples
21+
22+
```js
23+
var getOrInsert = require('map.prototype.getorinsert');
24+
var assert = require('assert');
25+
26+
var map = new Map();
27+
var key = {};
28+
var value = {};
29+
30+
assert.equal(map.has(key), false);
31+
assert.equal(getOrInsert(map, key, value), value);
32+
assert.equal(map.has(key), true);
33+
```
34+
35+
```js
36+
var getPolyfill = require('map.prototype.getorinsert/polyfill');
37+
var shim = require('map.prototype.getorinsert/shim');
38+
var assert = require('assert');
39+
/* when Map.prototype.getOrInsert is not present */
40+
delete Map.prototype.getOrInsert;
41+
var shimmed = shim();
42+
43+
assert.equal(shimmed, getPolyfill());
44+
45+
var map = new Map();
46+
var key = {};
47+
var value = {};
48+
49+
assert.equal(map.has(key), false);
50+
assert.equal(map.getOrInsert(key, value), value);
51+
assert.equal(map.has(key), true);
52+
```
53+
54+
```js
55+
var shim = require('map.prototype.getorinsert/shim');
56+
var assert = require('assert');
57+
/* when Map.prototype.getOrInsert is present */
58+
var shimmed = shim();
59+
60+
assert.equal(shimmed, Map.prototype.getOrInsert);
61+
62+
var map = new Map();
63+
var key = {};
64+
var value = {};
65+
66+
assert.equal(map.has(key), false);
67+
assert.equal(map.getOrInsert(key, value), value);
68+
assert.equal(map.has(key), true);
69+
```
70+
71+
## Tests
72+
Simply clone the repo, `npm install`, and run `npm test`
73+
74+
[package-url]: https://npmjs.org/package/map.prototype.getorinsert
75+
[npm-version-svg]: https://versionbadg.es/es-shims/Map.prototype.getOrInsert.svg
76+
[deps-svg]: https://david-dm.org/es-shims/Map.prototype.getOrInsert.svg
77+
[deps-url]: https://david-dm.org/es-shims/Map.prototype.getOrInsert
78+
[dev-deps-svg]: https://david-dm.org/es-shims/Map.prototype.getOrInsert/dev-status.svg
79+
[dev-deps-url]: https://david-dm.org/es-shims/Map.prototype.getOrInsert#info=devDependencies
80+
[npm-badge-png]: https://nodei.co/npm/map.prototype.getorinsert.png?downloads=true&stars=true
81+
[license-image]: https://img.shields.io/npm/l/map.prototype.getorinsert.svg
82+
[license-url]: LICENSE
83+
[downloads-image]: https://img.shields.io/npm/dm/map.prototype.getorinsert.svg
84+
[downloads-url]: https://npm-stat.com/charts.html?package=map.prototype.getorinsert
85+
[codecov-image]: https://codecov.io/gh/es-shims/Map.prototype.getOrInsert/branch/main/graphs/badge.svg
86+
[codecov-url]: https://app.codecov.io/gh/es-shims/Map.prototype.getOrInsert/
87+
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Map.prototype.getOrInsert
88+
[actions-url]: https://github.com/es-shims/Map.prototype.getOrInsert/actions

0 commit comments

Comments
 (0)