https://github.com/nodesource/index-list
Build up an indexed list of strings. Useful for minimising the size of categorical data when transferring it over the wire.
https://github.com/nodesource/index-list
Last synced: 8 months ago
JSON representation
Build up an indexed list of strings. Useful for minimising the size of categorical data when transferring it over the wire.
- Host: GitHub
- URL: https://github.com/nodesource/index-list
- Owner: nodesource
- License: other
- Archived: true
- Created: 2015-06-16T17:01:23.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-06-16T17:13:06.000Z (over 10 years ago)
- Last Synced: 2025-04-13T21:38:42.078Z (9 months ago)
- Language: JavaScript
- Size: 117 KB
- Stars: 7
- Watchers: 10
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# index-list




Build up an indexed list of strings. Useful for minimising the size of categorical data when transferring it over the wire.
## Usage
[](https://nodei.co/npm/index-list/)
### `list = IndexList([initial], [options])`
Creates a new indexed list.
### `list.push(elements...)`
Adds one or more new elements to the end of the list.
### `list.toJSON()`
Creates a serialized version of the input data, ready to be stringified into
JSON, which can later be loaded with `IndexList.load()`.
Note that while this is generally more compact, you can
reduce the size further by storing the `items` as binary
data using a `Uint32Array` or similar. Alternatively you
can convert that data into base64 and expand before loading
it again.
### `IndexList.load(json)`
Loads a previously serialized `IndexList`, returning a new
instance.
``` javascript
var list = IndexList(data)
var copy = IndexList.load(list.toJSON())
// copy.expand() ~= list.expand()
```
### `list.expand()`
Creates an expanded copy of the stored values, representing the original
input data.
``` javascript
var list = IndexList(['hello', 'world', 'again', 'hello', 'hello', 'world', 'again', 'again'])
// list.toJSON() ~= { items: [0, 1, 2, 0, 0, 1, 2, 2], index: ['hello', 'world', 'again'] }
// list.expand() ~= ['hello', 'world', 'again', 'hello', 'hello', 'world', 'again', 'again']
```
## License
MIT. See [LICENSE.md](http://github.com/nodesource/index-list/blob/master/LICENSE.md) for details.