js-utf8
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

js-utf8

js-utf8 is a UTF-8 encoder/decoder for Nodejs and Browser

Install

NPM

Usage

import { toArray, toString } from 'js-utf8'
 
const raw = '56\u0020你好 🚀'
 
const arr = toArray(raw)
const str = toString(arr)
 
console.log('raw:', raw)
console.log('arr:', arr)
console.log('str: ', str)
console.log('raw === str: ', raw === str)
// raw: 56 你好 🚀
// arr: [
//   [ 53 ],
//   [ 54 ],
//   [ 32 ],
//   [ 228, 189, 160 ],
//   [ 229, 165, 189 ],
//   [ 32 ],
//   [ 240, 159, 154, 128 ]
// ]
// str:  56 你好 🚀
// raw === str:  true

API

  • toArray: convert string to utf8 encoded byte array
function toArray (str: string): Array<number[]>
  • toString: convert utf8 encoded byte array to string
function toString (arr: Array<number[]>): string

/js-utf8/

    Package Sidebar

    Install

    npm i js-utf8

    Weekly Downloads

    4

    Version

    0.1.0

    License

    MIT

    Unpacked Size

    6.33 kB

    Total Files

    5

    Last publish

    Collaborators

    • nashaofu