source: imaps-frontend/node_modules/@jridgewell/set-array/README.md@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 839 bytes
RevLine 
[d565449]1# @jridgewell/set-array
2
3> Like a Set, but provides the index of the `key` in the backing array
4
5This is designed to allow synchronizing a second array with the contents of the backing array, like
6how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`, and there
7are never duplicates.
8
9## Installation
10
11```sh
12npm install @jridgewell/set-array
13```
14
15## Usage
16
17```js
18import { SetArray, get, put, pop } from '@jridgewell/set-array';
19
20const sa = new SetArray();
21
22let index = put(sa, 'first');
23assert.strictEqual(index, 0);
24
25index = put(sa, 'second');
26assert.strictEqual(index, 1);
27
28assert.deepEqual(sa.array, [ 'first', 'second' ]);
29
30index = get(sa, 'first');
31assert.strictEqual(index, 0);
32
33pop(sa);
34index = get(sa, 'second');
35assert.strictEqual(index, undefined);
36assert.deepEqual(sa.array, [ 'first' ]);
37```
Note: See TracBrowser for help on using the repository browser.