You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
839 B

1 month ago
  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. ```