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