{"name":"level-codec","repository":{"type":"git","url":"git+https://github.com/Level/codec.git"},"version":"7.0.1","description":"Levelup's encoding logic","license":"MIT","devDependencies":{"tape":"^4.3.0"},"scripts":{"test":"make test"},"dependencies":{},"gitHead":"4f4ebb7a5d05e20ed60bab103a12a2f91e93182a","bugs":{"url":"https://github.com/Level/codec/issues"},"homepage":"https://github.com/Level/codec#readme","_id":"level-codec@7.0.1","_npmVersion":"5.3.0","_nodeVersion":"8.2.0","_npmUser":{"name":"ralphtheninja","email":"ralphtheninja@riseup.net"},"dist":{"integrity":"sha512-Ua/R9B9r3RasXdRmOtd+t9TCOEIIlts+TN/7XTT2unhDaL6sJn83S3rUyljbr6lVtw49N3/yA0HHjpV6Kzb2aQ==","shasum":"341f22f907ce0f16763f24bddd681e395a0fb8a7","tarball":"http://registry-npm.ywwl.com/level-codec/download/level-codec-7.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBrJgvAptPl+aA3PChZ9/2HCGQtvHpFK73WDuVP+w7+8AiAC7Rvb3rz1KoA1YXxKPCI4OXENCwNxIM2M1Kx+yDvbGg=="}],"size":4177,"noattachment":false,"key":"/level-codec/-/level-codec-7.0.1.tgz"},"maintainers":[{"name":"juliangruber","email":"julian@juliangruber.com"},{"name":"ralphtheninja","email":"ralphtheninja@riseup.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/level-codec-7.0.1.tgz_1502724246178_0.46416788012720644"},"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":1502724247088,"deprecated":"Superseded by level-transcoder (https://github.com/Level/community#faq)","_cnpm_publish_time":1502724247088,"dist-tags":{"latest":"10.0.0"}}