{"name":"level-codec","repository":{"type":"git","url":"https://github.com/Level/codec"},"version":"5.4.0","description":"Levelup's encoding logic","license":"MIT","devDependencies":{"tape":"^3.5.0"},"scripts":{"test":"make test"},"gitHead":"8b26135d79215676813f9c47553716a5b2f8c809","bugs":{"url":"https://github.com/Level/codec/issues"},"homepage":"https://github.com/Level/codec","_id":"level-codec@5.4.0","_shasum":"6bfd13fba18c4304da4e4fe07f56c88a033f6990","_from":".","_npmVersion":"2.6.1","_nodeVersion":"0.10.36","_npmUser":{"name":"juliangruber","email":"julian@juliangruber.com"},"maintainers":[{"name":"juliangruber","email":"julian@juliangruber.com"},{"name":"ralphtheninja","email":"ralphtheninja@riseup.net"}],"dist":{"shasum":"6bfd13fba18c4304da4e4fe07f56c88a033f6990","tarball":"http://registry-npm.ywwl.com/level-codec/download/level-codec-5.4.0.tgz","integrity":"sha512-Q8mjpQS6EvAzLodN9R1VKYeSmMOvMd/vPJdv6tinKH4bTFpLj7OmNG3xzAzj/KqzZ4ed6aCW7mXH8QnT63nI+w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCTZw9/Fkhssmy2rIrrKGsO2o+AkPWZb+VChTDZQBZC5gIgH6VQPx/oFBikQEQu7raKsqpcQi09PmUYAijJ0t4vnEw="}],"size":3967,"noattachment":false,"key":"/level-codec/-/level-codec-5.4.0.tgz"},"directories":{},"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":1429254364686,"deprecated":"Superseded by level-transcoder (https://github.com/Level/community#faq)","_cnpm_publish_time":1429254364686,"dist-tags":{"latest":"10.0.0"}}