{"name":"level-codec","repository":{"type":"git","url":"git+https://github.com/Level/codec.git"},"version":"9.0.0","description":"Levelup's encoding logic","license":"MIT","devDependencies":{"standard":"^11.0.1","tape":"^4.3.0"},"main":"index.js","typings":"index.d.ts","scripts":{"test":"tape test/*.js && standard"},"engines":{"node":">=6"},"dependencies":{},"gitHead":"20dee0fc97513850d79781747a0811667ab3d5cf","bugs":{"url":"https://github.com/Level/codec/issues"},"homepage":"https://github.com/Level/codec#readme","_id":"level-codec@9.0.0","_npmVersion":"6.0.0","_nodeVersion":"10.0.0","_npmUser":{"name":"ralphtheninja","email":"ralphtheninja@riseup.net"},"dist":{"integrity":"sha512-OIpVvjCcZNP5SdhcNupnsI1zo5Y9Vpm+k/F1gfG5kXrtctlrwanisakweJtE0uA0OpLukRfOQae+Fg0M5Debhg==","shasum":"2d3a0e835c4aa8339ec63de3f5a37480b74a5f87","tarball":"http://registry-npm.ywwl.com/level-codec/download/level-codec-9.0.0.tgz","fileCount":13,"unpackedSize":17718,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa9vYBCRA9TVsSAnZWagAA2pkP+QGU0RFEnmI6N5RHtuC1\nFjy5MmU66+xMZIxxhgw6x23b1wqmjYK5wMpPa3ByYgzZ/ZbBvEEOUD3BXFsC\nnGN5HAwG8HioVJlDWk4rZgiwybEzKCTZfapyCFPWa1SV6xZ53M3qK3IGKyzw\nJTtNFjL4b6rKlMcR5YryDkev8qgG99w13RL6a93rcfUZhN/uPAHw/mrmztrG\niq5cSupMxMmRGEJKPSL+17oxszOgTKpqXxlDTxya5deRCRn3nJFv4BtYaywq\njc96Mri/88Z8YKyQ0cYjOh3/ydZ4TxTPazlOiE1SEz3XT8fgVv6i62cDMp5e\njoyMOz3250DbIshvCXdkH7VSIvJvTIhgut5kaKmTs877EUPTYFmbk8nfomPl\nRZVbaXpXlHCSRvz1cz0+mgqvxoYI1JYCDiEAThvZkrHh5Z+MSWCFlWrpV/2d\nyO8SpWkassnK9dQjLgRRE0BVZvgorKQOIz3m0gI1gdVmtHR4f48G2fY6nRBF\nl6XEytq2mbbGvcFfrRKyfDwtcm3AaD/3IceDKNCbvXJczPffVUEMQY2zSHj8\nRd2QI3Z6FB0uHQxNaaVGkqO50Ab5auNEpLZ+KU2sVDypPNvRf9DsMnK4UmUP\nUY+w496Qk9nzfvi2FsFVfK6n/3321LJdOif6qsa2vYCEj8TwCCk6gBS2+Md9\nuHkd\r\n=6a8W\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCSPm1EsKwsBNoy/odjnijnX45vnShrdqvOhiS3uPZmUAIgO6JuRMCzISEgGBI8zewGbjwLbrPZsCXZKCtDZs805IA="}],"size":4955,"noattachment":false,"key":"/level-codec/-/level-codec-9.0.0.tgz"},"maintainers":[{"email":"julian@juliangruber.com","name":"juliangruber"},{"email":"ralphtheninja@riseup.net","name":"ralphtheninja"},{"email":"dev@vincentweevers.nl","name":"vweevers"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/level-codec_9.0.0_1526134271886_0.934087472479284"},"_hasShrinkwrap":false,"readme":"# level-codec\n\n> Encode keys, values and range options, with built-in or custom encodings.\n\n[![level badge][level-badge]](https://github.com/Level/awesome)\n[![npm](https://img.shields.io/npm/v/level-codec.svg?label=&logo=npm)](https://www.npmjs.com/package/level-codec)\n[![Node version](https://img.shields.io/node/v/level-codec.svg)](https://www.npmjs.com/package/level-codec)\n[![Travis](https://img.shields.io/travis/com/Level/codec.svg?logo=travis&label=)](https://travis-ci.com/Level/codec)\n[![npm](https://img.shields.io/npm/dm/level-codec.svg?label=dl)](https://www.npmjs.com/package/level-codec)\n[![Coverage Status](https://coveralls.io/repos/github/Level/codec/badge.svg)](https://coveralls.io/github/Level/codec)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![Backers on Open Collective](https://opencollective.com/level/backers/badge.svg?color=orange)](#backers)\n[![Sponsors on Open Collective](https://opencollective.com/level/sponsors/badge.svg?color=orange)](#sponsors)\n\n## Usage\n\n**If you are upgrading:** please see [`UPGRADING.md`](UPGRADING.md).\n\n```js\nconst Codec = require('level-codec')\nconst codec = Codec({ keyEncoding: 'json' })\nconst key = codec.encodeKey({ foo: 'bar' })\nconsole.log(key) // -> '{\"foo\":\"bar\"}'\nconsole.log(codec.decodeKey(key)) // -> { foo: 'bar' }\n```\n\n## API\n\n### `codec = Codec([opts])`\n\nCreate a new codec, with a global options object.\n\n### `codec.encodeKey(key[, opts])`\n\nEncode `key` with given `opts`.\n\n### `codec.encodeValue(value[, opts])`\n\nEncode `value` with given `opts`.\n\n### `codec.encodeBatch(batch[, opts])`\n\nEncode `batch` ops with given `opts`.\n\n### `codec.encodeLtgt(ltgt)`\n\nEncode the ltgt values of option object `ltgt`.\n\n### `codec.decodeKey(key[, opts])`\n\nDecode `key` with given `opts`.\n\n### `codec.decodeValue(value[, opts])`\n\nDecode `value` with given `opts`.\n\n### `codec.createStreamDecoder([opts])`\n\nCreate a function with signature `(key, value)`, that for each key-value pair returned from a levelup read stream returns the decoded value to be emitted.\n\n### `codec.keyAsBuffer([opts])`\n\nCheck whether `opts` and the global `opts` call for a binary key encoding.\n\n### `codec.valueAsBuffer([opts])`\n\nCheck whether `opts` and the global `opts` call for a binary value encoding.\n\n### `codec.encodings`\n\nThe builtin encodings as object of form\n\n```js\n{\n  [type]: encoding\n}\n```\n\nSee below for a list and the format of `encoding`.\n\n## Builtin Encodings\n\n| Type                                                              | Input                        | Stored as        | Output    |\n| :---------------------------------------------------------------- | :--------------------------- | :--------------- | :-------- |\n| `utf8`                                                            | String or Buffer             | String or Buffer | String    |\n| `json`                                                            | Any JSON type                | JSON string      | Input     |\n| `binary`                                                          | Buffer, string or byte array | Buffer           | As stored |\n| `hex`<br>`ascii`<br>`base64`<br>`ucs2`<br>`utf16le`<br>`utf-16le` | String or Buffer             | Buffer           | String    |\n| `none` a.k.a. `id`                                                | Any type (bypass encoding)   | Input\\*          | As stored |\n\n<sup>\\*</sup> Stores may have their own type coercion. Whether type information is preserved depends on the [`abstract-leveldown`] implementation as well as the underlying storage (`LevelDB`, `IndexedDB`, etc).\n\n## Encoding Format\n\nAn encoding is an object of the form:\n\n```js\n{\n  encode: function (data) {\n    return data\n  },\n  decode: function (data) {\n    return data\n  },\n  buffer: Boolean,\n  type: 'example'\n}\n```\n\nAll of these properties are required.\n\nThe `buffer` boolean tells consumers whether to fetch data as a Buffer, before calling your `decode()` function on that data. If `buffer` is true, it is assumed that `decode()` takes a Buffer. If false, it is assumed that `decode` takes any other type (usually a string).\n\nTo explain this in the grand scheme of things, consider a store like [`leveldown`] which has the ability to return either a Buffer or string, both sourced from the same byte array. Wrap this store with [`encoding-down`] and it'll select the most optimal data type based on the `buffer` property of the active encoding. If your `decode()` function needs a string (and the data can legitimately become a UTF8 string), you should set `buffer` to `false`. This avoids the cost of having to convert a Buffer to a string.\n\nThe `type` string should be a unique name.\n\n## Contributing\n\n[`Level/codec`](https://github.com/Level/codec) is an **OPEN Open Source Project**. This means that:\n\n> Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.\n\nSee the [Contribution Guide](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.\n\n## Donate\n\nTo sustain [`Level`](https://github.com/Level) and its activities, become a backer or sponsor on [Open Collective](https://opencollective.com/level). Your logo or avatar will be displayed on our 28+ [GitHub repositories](https://github.com/Level) and [npm](https://www.npmjs.com/) packages. 💖\n\n### Backers\n\n[![Open Collective backers](https://opencollective.com/level/backers.svg?width=890)](https://opencollective.com/level)\n\n### Sponsors\n\n[![Open Collective sponsors](https://opencollective.com/level/sponsors.svg?width=890)](https://opencollective.com/level)\n\n## License\n\n[MIT](LICENSE.md) © 2012-present [Contributors](CONTRIBUTORS.md).\n\n[level-badge]: https://leveljs.org/img/badge.svg\n\n[`encoding-down`]: https://github.com/Level/encoding-down\n\n[`abstract-leveldown`]: https://github.com/Level/abstract-leveldown\n\n[`leveldown`]: https://github.com/Level/leveldown\n","publish_time":1526134271976,"deprecated":"Superseded by level-transcoder (https://github.com/Level/community#faq)","_cnpm_publish_time":1526134271976,"dist-tags":{"latest":"10.0.0"}}