{"name":"index-encoder","version":"3.5.0","description":"Encode multiple values into sorted keys","main":"index.js","dependencies":{"b4a":"^1.6.4"},"devDependencies":{"brittle":"^3.2.1","hyperbee":"^2.10.5","hypercore":"^11.0.0","lunte":"^1.0.0","prettier":"^3.6.2","prettier-config-holepunch":"^2.0.0"},"scripts":{"format":"prettier --write .","lint":"prettier --check . && lunte","test":"npm run test:node && npm run test:bare","test:node":"brittle-node test.js","test:bare":"brittle-bare test.js"},"repository":{"type":"git","url":"git+https://github.com/holepunchto/index-encoder.git"},"author":{"name":"Mathias Buus","url":"@mafintosh"},"license":"Apache-2.0","bugs":{"url":"https://github.com/holepunchto/index-encoder/issues"},"homepage":"https://github.com/holepunchto/index-encoder","gitHead":"c7bbb900a83309089f20ba41d32158acd11beb7d","_id":"index-encoder@3.5.0","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-idZ1cxtZz2dRV6rUiaP9Xo99UjXbSzjcMacoQmxUMu/A7fEQcNPngvwDJYeWelQUS5XFlY71/or70lKn6XnwbQ==","shasum":"11dc1cb2b32b3c156ad722e5da8079a390939b39","tarball":"http://registry-npm.ywwl.com/index-encoder/download/index-encoder-3.5.0.tgz","fileCount":9,"unpackedSize":35276,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC5KAj+rcLoYzzC+hB3+Ku7DSGlYahHJh0Zha3VIBbNPQIgNfW7TojB8+rIZCVAa1ji6mbfTqG0cwbLDWvcyC8h1cI="}],"size":9784,"noattachment":false,"key":"/index-encoder/-/index-encoder-3.5.0.tgz"},"_npmUser":{"name":"mafintosh","email":"mathiasbuus@gmail.com"},"directories":{},"maintainers":[{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/index-encoder_3.5.0_1772400460161_0.4057396367319994"},"_hasShrinkwrap":false,"readme":"# index-encoder\n\nEncode multiple values into sorted keys\n\n```\nnpm install index-encoder\n```\n\n## Usage\n\n```js\nconst IndexEncoder = require('index-encoder')\n\nconst idx = new IndexEncoder([IndexEncoder.STRING, IndexEncoder.UINT])\n\nconst buf = idx.encode(['foo', 42])\nconsole.log(idx.decode(buf)) // ['foo', 42]\n\n// pass any compact encoding name to map it to the relevant encoding\nconst uintType = IndexEncoder.lookup('uint')\nconst bufferType = IndexEncoder.lookup('buffer')\nconst alsoBufferType = IndexEncoder.lookup('fixed32')\n```\n\n## API\n\n#### `const idx = new IndexEncoder(encodings, { prefix = -1 })`\n\nCreate an index encoder using the array of `encodings`. The index encoder will produce a buffer encoding in the same order as `encodings`. A `prefix` can be defined to differentiate encoded buffers with the same `encodings`.\n\n#### `const buf = idx.encode(keys)`\n\nEncode the provided `keys` as a buffer. `keys` must be in the same order as the `encodings` when constructing the index encoder. `keys` can have less elements than the defined `encodings` to create a prefix buffer. When used with [`hyperbee`](https://github.com/holepunchto/hyperbee), this can be used to search for only a subset of the total keys.\n\n#### `const range = idx.encodeRange(query)`\n\nEncodes the `query` object values into their buffer equivalent values. Useful for creating range queries for [`hyperbee`](https://github.com/holepunchto/hyperbee?tab=readme-ov-file#const-stream--dbcreatereadstreamrange-options) based on the index encoder.\n\nThe `query` specifies the range you want to read:\n\n```\n{\n  gt,  // Return values only > than this\n  gte, // Return values >= than this\n  lt,  // Return values < than this\n  lte: // Return values <= than this\n}\n```\n\nReturned query will be bounded by the `prefix` if defined and the query is unbounded. This ensures ranges only query ranges with the same `prefix`.\n\n#### `const values = idx.decode(buffer)`\n\nDecode the `buffer` into the original values. `values` will be in the same order as the defined `encodings`. Buffers encoded with a subset of keys will return the values encoded with remaining values being `0` filled if encoded with `UNIT` else `null`:\n\n```\nconst idx = new IndexEncoder([\n  IndexEncoder.STRING,\n  IndexEncoder.UINT,\n  IndexEncoder.STRING\n])\n\nconst buf = idx.encode(['foo'])\nconsole.log(idx.decode(buf)) // ['foo', 0, null]\n```\n\n## Encoding Types\n\nThe following are the types for `encodings` are supported provided as static properties on the `IndexEncoder` class:\n\n- `IndexEncoder.BUFFER` : Encodes a buffer.\n- `IndexEncoder.STRING` : Encodes a string.\n- `IndexEncoder.UINT` : Encodes an unsigned integer.\n- `IndexEncoder.INT` : Encodes an signed integer.\n- `IndexEncoder.DATE` : Encodes a date.\n- `IndexEncoder.BOOL` : Encodes a boolean.\n\n#### `const enc = IndexEncoder.lookup(c)`\n\nReturns the encoding type for a given compact encoding name (`c`). If `c` is not supported, it will throw an `Unknown type` error.\n\n## License\n\nApache 2.0\n","publish_time":1772400460316,"_cnpm_publish_time":1772400460316,"dist-tags":{"latest":"3.5.0"}}