Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jridgewell/set-array
https://github.com/jridgewell/set-array
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jridgewell/set-array
- Owner: jridgewell
- License: mit
- Created: 2022-04-23T22:19:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-29T06:06:52.000Z (10 months ago)
- Last Synced: 2024-10-13T21:12:53.850Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 382 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jridgewell/set-array
> Like a Set, but provides the index of the `key` in the backing array
This is designed to allow synchronizing a second array with the contents of the backing array, like
how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`, and there
are never duplicates.## Installation
```sh
npm install @jridgewell/set-array
```## Usage
```js
import { SetArray, get, put, pop } from '@jridgewell/set-array';const sa = new SetArray();
let index = put(sa, 'first');
assert.strictEqual(index, 0);index = put(sa, 'second');
assert.strictEqual(index, 1);assert.deepEqual(sa.array, [ 'first', 'second' ]);
index = get(sa, 'first');
assert.strictEqual(index, 0);pop(sa);
index = get(sa, 'second');
assert.strictEqual(index, undefined);
assert.deepEqual(sa.array, [ 'first' ]);
```