/** * @file Shims for the ES2023 change-array-by-copy methods, both Node 20. * Only the two the tree consumes are here: `toSorted` and `toReversed`. * Both produce a DENSE result. Reading a hole yields undefined rather than * propagating the hole, and `toSorted` places every undefined at the end * regardless of the comparator, which is the part a `[...arr].sort(cmp)` * rewrite gets right only by accident and a `filter(Boolean)` rewrite gets * wrong outright. */ export type ToReversedFn = (arr: readonly T[]) => T[]; export type ToSortedFn = (arr: readonly T[], comparator?: ((a: T, b: T) => number) | undefined) => T[]; /** * The native `Array.prototype.toReversed`, or undefined below Node 20. */ export declare const arrayToReversedNative: ToReversedFn | undefined; /** * `Array.prototype.toReversed` shim. * * Walks the source backwards by index rather than reversing in place, so the * input is never mutated and the output is dense. */ export declare function arrayToReversedShim(arr: readonly T[]): T[]; export declare const arrayToReversed: ToReversedFn; /** * The native `Array.prototype.toSorted`, or undefined below Node 20. */ export declare const arrayToSortedNative: ToSortedFn | undefined; /** * `Array.prototype.toSorted` shim. * * The comparator is validated BEFORE any element is read, so a bad comparator * throws on an empty array too. `sort` then supplies the rest of the observable * contract: a stable order, and undefined last whatever the comparator says. */ export declare function arrayToSortedShim(arr: readonly T[], comparator?: ((a: T, b: T) => number) | undefined): T[]; export declare const arrayToSorted: ToSortedFn; /** * The spec's ToLength: a length is clamped to a non-negative integer under * 2^53-1. Without it a `length` of -1 or NaN reaches `new Array(length)` and * throws a RangeError where the spec produces an empty array. */ export declare function toLength(value: unknown): number;