MCPcopy Create free account
hub / github.com/denoland/std / numberToArray

Function numberToArray

cbor/_common.ts:5–10  ·  view source on GitHub ↗
(bytes: number, x: number | bigint)

Source from the content-addressed store, hash-verified

3export type ReleaseLock = (value?: unknown) => void;
4
5export function numberToArray(bytes: number, x: number | bigint): Uint8Array {
6 const view = new DataView(new ArrayBuffer(8));
7 if (typeof x === "bigint" || x % 1 === 0) view.setBigUint64(0, BigInt(x));
8 else view.setFloat64(0, x);
9 return new Uint8Array(view.buffer.slice(-bytes));
10}
11
12export function arrayToNumber(
13 buffer: ArrayBufferLike & { BYTES_PER_ELEMENT?: never },

Callers 4

#encodeArrayMethod · 0.90
#encodeObjectMethod · 0.90
constructorMethod · 0.90
constructorMethod · 0.90

Calls 1

sliceMethod · 0.45

Tested by

no test coverage detected