{"_id":"@borewit/text-codec@0.2.3","bugs":{"url":"https://github.com/Borewit/text-codec/issues"},"dist":{"shasum":"f5675fe4eae610670bbb635c6b75c6a4dd41ed73","tarball":"http://registry-npm.ywwl.com/@borewit/text-codec/download/@borewit/text-codec-0.2.3.tgz","fileCount":5,"integrity":"sha512-49CycTz1aAZmvFcwkeFyhud1HUmRIB5Tabf7ALV+VA4Iu85MTfz2cUwzPagMFAdVBvrWdkCxG67I30tUwwpKsw==","signatures":[{"sig":"MEQCIHGJOW1NlL2/TdwH5DXE2ccBEzLS81n5hBGFkHA5pgsXAiAspP8GQxIuFPLN9dRyqOGep2WsxkdhcCAh+o2DtjRcHA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIBfRBbqd+8rb5cpgoU4zwsXeLm9Gz/Ax07QiDta7aQFbAiAMZqXiNPv3iooCY8PBvR3gVpF/bP7j0f2gSdveF5QMNg=="}],"unpackedSize":16527,"size":5117,"noattachment":false,"key":"/@borewit/text-codec/-/@borewit/text-codec-0.2.3.tgz"},"name":"@borewit/text-codec","type":"module","types":"lib/index.d.ts","author":{"url":"https://github.com/Borewit","name":"Borewit"},"exports":"./lib/index.js","funding":{"url":"https://github.com/sponsors/Borewit","type":"github"},"gitHead":"caaa5d47ab7976b3742ecfd1dc8cb746404ef321","license":"MIT","scripts":{"lint":"biome check --error-on-warnings","test":"mocha","build":"npm run compile","clean":"del-cli lib/**/*.js lib/***.js.map test/**/*.d.ts test/**/*.js test/**/*.js.map","compile":"npm run compile:src && npm run compile:test","pretest":"npm run build","lint:fix":"biome check --write","compile:src":"tsc --p lib --sourceMap false","compile:test":"tsc --p test","update-biome":"npm install --save-dev --save-exact @biomejs/biome@latest && npx @biomejs/biome migrate --write","prepublishOnly":"npm run build"},"version":"0.2.3","_npmUser":{"name":"borewit","email":"borewit@xs4all.nl"},"homepage":"https://github.com/Borewit/text-codec#readme","keywords":["TextDecoder","TextEncoder","decoder","decoding","encod","encoding","decode","text","ascii","utf-8","utf8","utf-16le","latin1","iso-8859-1","windows-1252","charset","encoding","decoding","polyfill","character-set","latin","hermes","react"],"repository":{"url":"git+https://github.com/Borewit/text-codec.git","type":"git"},"_npmVersion":"10.9.9","description":"Text Decoder","directories":{},"maintainers":[{"name":"borewit","email":"borewit@xs4all.nl"}],"_nodeVersion":"22.23.3","_hasShrinkwrap":false,"devDependencies":{"chai":"^6.3.0","mocha":"^11.8.0","typescript":"7.0.2","@types/chai":"^5.2.3","@types/mocha":"^10.0.10","@biomejs/biome":"2.6.3"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/text-codec_0.2.3_1793218223607_0.6548117012760553"},"readme":"[![CI](https://github.com/Borewit/text-codec/actions/workflows/ci.yml/badge.svg)](https://github.com/Borewit/text-codec/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/%40borewit%2Ftext-codec.svg)](https://www.npmjs.com/package/@borewit/text-codec)\n[![npm downloads](http://img.shields.io/npm/dm/@borewit/text-codec.svg)](https://npmcharts.com/compare/@borewit/text-codec?interval=30)\n![bundlejs](https://deno.bundlejs.com/?q=@borewit/text-codec&badge)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?logo=open-source-initiative&logoColor=white)](LICENSE.txt)\n\n# `@borewit/text-codec`\n\nA **lightweight polyfill for text encoders and decoders** covering a small set of commonly used encodings.\n\nSome JavaScript runtimes provide limited or inconsistent encoding support through `TextEncoder` and `TextDecoder`.  \nExamples include environments like **Hermes (React Native)** or certain **Node.js builds with limited ICU support**.\n\nThis module provides **reliable encode/decode support for a small set of encodings that may be missing or unreliable in those environments**.\n\n- If a native UTF-8 `TextEncoder` / `TextDecoder` is available, it is used.\n- All other encodings are implemented by this library.\n\n## Supported encodings\n\n- `utf-8` / `utf8`\n- `utf-16le`\n- `ascii`\n- `latin1` / `iso-8859-1`\n- `windows-1252`\n\nThese encodings are commonly encountered in metadata formats and legacy text data.\n\n## ✨ Features\n\n- Encoding and decoding utilities\n- Lightweight\n- Typed API\n\n## 📦 Installation\n\n```sh\nnpm install @borewit/text-codec\n```\n\n# 📚 API Documentation\n\n## `textDecode(bytes, encoding): string`\n\nDecodes binary data into a JavaScript string.\n\n**Parameters**\n- `bytes` (`Uint8Array`) — The binary data to decode.\n- `encoding` (`SupportedEncoding`, optional) — Encoding type. Defaults to `\"utf-8\"`.  \n\n**Returns**\n- `string` — The decoded text.\n\n**Example**\n```js\nimport { textDecode } from \"@borewit/text-codec\";\n\nconst bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);\nconst text = textDecode(bytes, \"ascii\");\nconsole.log(text); // \"Hello\"\n```\n\n## `textEncode(input, encoding): Uint8Array`\n\nEncodes a JavaScript string into binary form using the specified encoding.\n\n**Parameters**\n\n- `input` (`string`) — The string to encode.\n- `encoding` (`SupportedEncoding`, optional) — Encoding type. Defaults to `\"utf-8\"`.\n\n**Returns**\n\n`Uint8Array` — The encoded binary data.\n\nExample:\n```js\nimport { textEncode } from \"@borewit/text-codec\";\n\nconst bytes = textEncode(\"Hello\", \"utf-16le\");\nconsole.log(bytes); // Uint8Array([...])\n```\n\n## 📜 Licence\n\nThis project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.\n ","publish_time":1793218223703,"_cnpm_publish_time":1793218223703,"dist-tags":{"latest":"0.2.3"}}