UNPKG

byte-decoder

Version:

Decode data. Browser or NodeJS.

36 lines (25 loc) 973 B
import type LRUCache from '@neumatter/lru-cache' declare module 'byte-decoder' interface InternalDecode { utf8: (bytes: Uint8Array) => string base64: (bytes: Uint8Array) => string base64url: (bytes: Uint8Array) => string ascii: (bytes: Uint8Array) => string binary: (bytes: Uint8Array) => string utf16le: (bytes: Uint8Array) => string utf16be: (bytes: Uint8Array) => string hex: (bytes: Uint8Array) => string base32: (bytes: Uint8Array, usePadding: boolean) => string base32hex: (bytes: Uint8Array, usePadding: boolean) => string base32crockford: (bytes: Uint8Array, usePadding: boolean) => string } type Encoding = string & keyof InternalDecode export default class ByteDecoder<E extends Encoding> { #cache: LRUCache<string, string, undefined> #encoding: E #lookupTable: any #decodeInternal: InternalDecode[E] constructor (encoding: E) get encoding (): E decode (data: ArrayBufferLike | ArrayLike | ArrayBufferView): string }