{"_id":"utf8-codec","_rev":"4579060","name":"utf8-codec","description":"utf8 to/from bytes codec (esm/cjs)","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"leichtgewicht","email":"martin.heidegger@gmail.com"}],"time":{"modified":"2026-04-10T15:52:54.000Z","created":"2022-05-30T06:24:02.669Z","1.0.0":"2022-05-30T06:24:02.669Z"},"users":{},"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/utf8-codec.git"},"versions":{"1.0.0":{"name":"utf8-codec","version":"1.0.0","description":"utf8 to/from bytes codec (esm/cjs)","main":"index.js","module":"index.mjs","types":"./types/index.d.ts","exports":{"require":"./index.js","import":"./index.mjs","types":"./types/index.d.ts"},"scripts":{"test":"npm run lint && npm run unit","lint":"standard &&  dtslint types --localTs node_modules/typescript/lib","unit":"node test.mjs","coverage":"c8 -r html -r text npm run unit","prepare":"esm2umd utf8Codec"},"keywords":["utf8","codec","bytes","encoding","buffer","uint8array"],"author":{"name":"Martin Heidegger","email":"martin.heidegger@gmail.com"},"license":"MIT","devDependencies":{"@definitelytyped/dtslint":"^0.0.112","@leichtgewicht/esm2umd":"^0.3.4","c8":"^7.11.3","fresh-tape":"^5.5.3","standard":"^17.0.0","typescript":"^4.7.2"},"repository":{"type":"git","url":"git+https://github.com/martinheidegger/utf8-codec.git"},"bugs":{"url":"https://github.com/martinheidegger/utf8-codec/issues"},"homepage":"https://github.com/martinheidegger/utf8-codec#readme","gitHead":"07cd4aa2771cebf55118fdc5feb46f4c64e6c013","_id":"utf8-codec@1.0.0","_nodeVersion":"18.2.0","_npmVersion":"8.9.0","dist":{"shasum":"b30252507271cd612dbf5b58f04620a5e1e7bb89","size":4672,"noattachment":false,"key":"/utf8-codec/-/utf8-codec-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/utf8-codec/download/utf8-codec-1.0.0.tgz"},"_npmUser":{"name":"leichtgewicht","email":"martin.heidegger@gmail.com"},"directories":{},"maintainers":[{"name":"leichtgewicht","email":"martin.heidegger@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/utf8-codec_1.0.0_1653891842526_0.9910669669389884"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2022-05-30T07:18:05.445Z","publish_time":1653891842669,"_cnpm_publish_time":1653891842669}},"readme":"# utf8-codec\n\nA javascript-only (esm/cjs) utf8 codec that is [abstract-encoding][] compatible,\nwell-tested and pretty efficient. Bonus: It doesn't use Nodejs' Buffer object\nand comes with typescript types.\n\n[abstract-encoding]: https://github.com/mafintosh/abstract-encoding\n\n## Usage\n\n```js\nimport { encode, encodingLength, decode } from 'utf8-codec' // require works too!\n\nconst str = 'Hello World / こんにちは世界'\nconst bytes = encode(\n  str,\n  new Uint8Array(endcodingLength(str)), // own buffer supplied, optional\n  0 // offset, at which to write the str, optional\n)\nstr === decode(bytes, 0, bytes.length)\n```\n\n## Why?\n\nThe [TextEncoder][] and [TextDecoder][] classes _exist_ to encode utf8 strings but\nthey are not optimized for bigger byte processing and don't offer APIs to figure\nout how preemptively how many bytes are supposed to be written/read. Surprisingly\nthis algorithm is even faster.\n\nThe other implementations found at the time do either not implement the edge cases\nproperly and/or both directions of the codec.\n\n[TextEncoder]: https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder\n[TextDecoder]: https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder\n\n## License\n\n[MIT](./LICENSE)\n","_attachments":{},"homepage":"https://github.com/martinheidegger/utf8-codec#readme","bugs":{"url":"https://github.com/martinheidegger/utf8-codec/issues"},"license":"MIT"}