UNPKG

uint8arrays

Version:

Utility functions to make dealing with Uint8Arrays easier

17 lines 533 B
import bases from "./util/bases.js"; /** * Turns a `Uint8Array` into a string. * * Supports `utf8`, `utf-8` and any encoding supported by the multibase module. * * Also `ascii` which is similar to node's 'binary' encoding. */ export function toString(array, encoding = 'utf8') { const base = bases[encoding]; if (base == null) { throw new Error(`Unsupported encoding "${encoding}"`); } // strip multibase prefix return base.encoder.encode(array).substring(1); } //# sourceMappingURL=to-string.js.map