UNPKG

cesr

Version:

[![NPM Version](https://img.shields.io/npm/v/cesr.svg?style=flat)](https://www.npmjs.com/package/cesr) [![NPM License](https://img.shields.io/npm/l/cesr.svg?style=flat)](https://github.com/lenkan/cesr-js/blob/main/LICENSE) [![CI](https://github.com/lenkan

29 lines (28 loc) 693 B
export function concat(a, b) { if (a.length === 0) { return b; } if (b.length === 0) { return a; } const merged = new Uint8Array(a.length + b.length); merged.set(a); merged.set(b, a.length); return merged; } export function prepad(raw, length) { if (raw.byteLength === length) { return raw; } const padded = new Uint8Array(length + raw.byteLength); padded.set(raw, length); return padded; } export function toArray(num, length) { const bytes = new Uint8Array(length); for (let i = 0; i < length; i++) { bytes[length - i - 1] = num % 256; num = Math.floor(num / 256); } return bytes; }