react-native-encoding-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-native-encoding-api

npm version npm downloads License: MIT Platform - iOS Platform - Android Platform - macOS

A complete implementation of the Web API's TextEncoder and TextDecoder for React Native. This package provides both encoding and decoding functionality with the exact same API and behavior as the Web API.

Requirements

  • React Native >= 0.60.0
  • TypeScript >= 4.0.0 (for TypeScript projects)

Installation

npm install react-native-encoding-api
# or
yarn add react-native-encoding-api

Usage

import { TextEncoder, TextDecoder } from 'react-native-encoding-api';

// Encoding text to bytes
const encoder = new TextEncoder();
const bytes = encoder.encode('Hello World!');

// Decoding bytes back to text
const decoder = new TextDecoder();
const text = decoder.decode(bytes);
console.log(text); // Output: "Hello World!"

API

TextEncoder

new TextEncoder()
  • encode(text: string): Uint8Array: Encodes a string into UTF-8 bytes

TextDecoder

new TextDecoder(encoding?: string, options?: { fatal?: boolean; ignoreBOM?: boolean })
  • encoding (optional): Currently only 'utf-8' is supported
  • options (optional):
    • fatal: If true, throws an error for invalid UTF-8 sequences
    • ignoreBOM: If true, ignores the UTF-8 BOM (Byte Order Mark)
  • decode(input: Uint8Array): string: Decodes a Uint8Array into a string

License

MIT

Package Sidebar

Install

npm i react-native-encoding-api

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

14.5 kB

Total Files

6

Last publish

Collaborators

  • tanaytanay