UNPKG

@ssttevee/u8-utils

Version:

Miscellaneous functions for working with Uint8Arrays

27 lines 701 B
export function stringToArray(s) { return Uint8Array.from(s, (c) => c.charCodeAt(0)); } export function arrayToString(a) { return String.fromCharCode.apply(null, a); } export function mergeArrays(...arrays) { const out = new Uint8Array(arrays.reduce((total, arr) => total + arr.length, 0)); let offset = 0; for (const arr of arrays) { out.set(arr, offset); offset += arr.length; } return out; } export function arraysEqual(a, b) { if (a.length !== b.length) { return false; } for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) { return false; } } return true; } //# sourceMappingURL=index.mjs.map