Text Decoder
npm install @borewit/text-codec


!bundlejs

@borewit/text-codecTextEncoder / TextDecoder supporting common encodings missing in some JavaScript engines and Node.js builds.
utf8 | ➕ | Native | Native | Native |
iso-8859-1 | ➕ | ➕ | ➕ | Native (sometimes) |
latin1 / iso-8859-1 or windows-1252 in these environments,
TextDecoder / TextEncoder may throw an error or return incorrect results.
utf-8 / utf8
utf-16le
ascii
latin1 / iso-8859-1
windows-1252
sh
npm install @borewit/text-codec
`
📚 API Documentation
textDecode(bytes, encoding): string
Decodes binary data into a JavaScript string using the specified encoding.
Parameters
- bytes (Uint8Array) — The binary data to decode.
- encoding (SupportedEncoding, optional) — Encoding type. Defaults to "utf-8".
Returns
- string — The decoded text.
Example
`js
import { textDecode } from "@borewit/text-encode";
const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
const text = textDecode(bytes, "ascii");
console.log(text); // "Hello"
`
Encodes a JavaScript string into binary form using the specified encoding.
textEncode(input, encoding): Uint8Array
Parameters
- input (string) — The string to encode.
- encoding (SupportedEncoding, optional) — Encoding type. Defaults to "utf-8".
Returns
Uint8Array — The encoded binary data.
Example:
`js
import { textEncode } from "@borewit/text-encode";
const bytes = textEncode("Hello", "utf-16le");
console.log(bytes); // Uint8Array([...])
``