js-utf8
v0.1.0
Published
js-utf8 is a UTF-8 encoder/decoder for Nodejs and Browser
Downloads
6
Maintainers
Readme
js-utf8
js-utf8 is a UTF-8 encoder/decoder for Nodejs and Browser
Install
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