mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-04 09:28:24 +08:00
Represent ordinary JavaScript arrays with hole, value, and explicit-undefined states; add sparse side storage and carry missing values through the frontend, native backends, runtime, and Node-facing consumers.
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { format, inspect } from "node:util";
|
|
|
|
const numbers: number[] = [];
|
|
numbers[2] = 7;
|
|
numbers.length = 5;
|
|
console.log("number-json", JSON.stringify(numbers));
|
|
console.log("number-inspect", inspect(numbers));
|
|
console.log("number-join", numbers.join("|"));
|
|
const strings: string[] = [];
|
|
strings[1] = "value";
|
|
strings.length = 3;
|
|
console.log("string-json", JSON.stringify(strings));
|
|
console.log("string-inspect", inspect(strings));
|
|
const records: { value: number }[] = [];
|
|
records[1] = { value: 3 };
|
|
records.length = 4;
|
|
console.log("record-json", JSON.stringify(records));
|
|
console.log("record-inspect", inspect(records));
|
|
const optional: (number | undefined)[] = [undefined];
|
|
optional[3] = 8;
|
|
console.log("optional-json", JSON.stringify(optional));
|
|
console.log("optional-inspect", inspect(optional));
|
|
console.log("optional-format", format("%j", optional));
|
|
const tuple: [number | undefined, number] = [undefined, 2];
|
|
console.log("tuple-json", JSON.stringify(tuple));
|
|
console.log("materialized-json", JSON.stringify(numbers.toReversed()));
|
|
console.log("materialized-inspect", inspect(numbers.toReversed()));
|
|
const huge: number[] = [];
|
|
huge[4_000_000_000] = 11;
|
|
console.log("huge-inspect", inspect(huge));
|
|
const alternating: number[] = [];
|
|
for (let i = 0; i < 220; i += 2) alternating[i] = i;
|
|
console.log("truncated-inspect", inspect(alternating));
|