You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@borewit/text-codec

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@borewit/text-codec

Text Decoder

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
3.8M
-56.92%
Maintainers
1
Weekly downloads
 
Created
Source

CI npm version npm downloads bundlejs License: MIT

@borewit/text-codec

A lightweight polyfill for text encoders and decoders covering a small set of commonly used encodings.

Some JavaScript runtimes provide limited or inconsistent encoding support through TextEncoder and TextDecoder.
Examples include environments like Hermes (React Native) or certain Node.js builds with limited ICU support.

This module provides reliable encode/decode support for a small set of encodings that may be missing or unreliable in those environments.

  • If a native UTF-8 TextEncoder / TextDecoder is available, it is used.
  • All other encodings are implemented by this library.

Supported encodings

  • utf-8 / utf8
  • utf-16le
  • ascii
  • latin1 / iso-8859-1
  • windows-1252

These encodings are commonly encountered in metadata formats and legacy text data.

✨ Features

  • Encoding and decoding utilities
  • Lightweight
  • Typed API

📦 Installation

npm install @borewit/text-codec

📚 API Documentation

textDecode(bytes, encoding): string

Decodes binary data into a JavaScript string.

Parameters

  • bytes (Uint8Array) — The binary data to decode.
  • encoding (SupportedEncoding, optional) — Encoding type. Defaults to "utf-8".

Returns

  • string — The decoded text.

Example

import { textDecode } from "@borewit/text-codec";

const bytes = new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f]);
const text = textDecode(bytes, "ascii");
console.log(text); // "Hello"

textEncode(input, encoding): Uint8Array

Encodes a JavaScript string into binary form using the specified encoding.

Parameters

  • input (string) — The string to encode.
  • encoding (SupportedEncoding, optional) — Encoding type. Defaults to "utf-8".

Returns

Uint8Array — The encoded binary data.

Example:

import { textEncode } from "@borewit/text-codec";

const bytes = textEncode("Hello", "utf-16le");
console.log(bytes); // Uint8Array([...])

📜 Licence

This project is licensed under the MIT License. Feel free to use, modify, and distribute as needed.

Keywords

TextDecoder

FAQs

Package last updated on 11 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts