aa9c692fb198e3cdb259bfe105f74338975a26f97ddd8516447bfed4af083107e4ab906a17523dabfdc3f67e81753b72daa594be99336d0ec443410cec6772 839 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # @jridgewell/set-array
  2. > Like a Set, but provides the index of the `key` in the backing array
  3. This is designed to allow synchronizing a second array with the contents of the backing array, like
  4. how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`, and there
  5. are never duplicates.
  6. ## Installation
  7. ```sh
  8. npm install @jridgewell/set-array
  9. ```
  10. ## Usage
  11. ```js
  12. import { SetArray, get, put, pop } from '@jridgewell/set-array';
  13. const sa = new SetArray();
  14. let index = put(sa, 'first');
  15. assert.strictEqual(index, 0);
  16. index = put(sa, 'second');
  17. assert.strictEqual(index, 1);
  18. assert.deepEqual(sa.array, [ 'first', 'second' ]);
  19. index = get(sa, 'first');
  20. assert.strictEqual(index, 0);
  21. pop(sa);
  22. index = get(sa, 'second');
  23. assert.strictEqual(index, undefined);
  24. assert.deepEqual(sa.array, [ 'first' ]);
  25. ```