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