byte-decoder
v1.0.0
Published
Decode data. Browser or NodeJS.
Downloads
8
Maintainers
Readme
ByteDecoder
Decode data. Browser or NodeJS.
Table of Contents
Install
npm i byte-decoder
Usage
(constructor) ByteDecoder
:
Args [encoding: 'utf8' | 'base64' | 'base64url' | 'ascii' | 'binary' | 'utf16le' | 'utf16be' | 'hex' | 'base32' | 'base32hex' | 'base32crockford'
]
import ByteDecoder from 'byte-decoder'
const base64ByteDecoder = new ByteDecoder('base64')
//...use base64ByteDecoder
(method) ByteDecoder.decode
:
Args [data: ArrayBufferLike | ArrayLike | ArrayBufferView
]
import ByteDecoder from 'byte-decoder'
const utf8ByteDecoder = new ByteDecoder('utf8')
const result = utf8ByteDecoder.decode([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]) // returns 'Hello World!'
TextDecoder
Polyfill:
// TextDecoder-polyfill.js
import ByteDecoder from 'byte-decoder'
if (!globalThis.TextDecoder) {
globalThis.TextDecoder = ByteDecoder
}
// index.js
import './TextDecoder-polyfill.js'