//#region src/cache.d.ts /** * A fixed-capacity `Map` that evicts the least recently used entry once it is full. * * Recency is tracked by `Map` insertion order: a read re-inserts its key so the oldest key is * always the map's first. Iteration (`keys`, `values`, `entries`, `forEach`, spread) therefore * yields entries least recently used first, and neither iterating nor {@link LRUCache.has} affects * recency — only {@link LRUCache.get} and {@link LRUCache.set} do. * * @typeParam TKey - Type of the cache key. * @typeParam TValue - Type of the cached value. */ declare class LRUCache extends Map { private _maxSize; /** Maximum number of entries retained before a write evicts the least recently used entry. */ get maxSize(): number; constructor(limit: number); /** Reads an entry, marking it as the most recently used, or `undefined` when absent. */ get(key: TKey): TValue | undefined; /** Writes an entry as the most recently used, evicting the least recently used entry when at capacity. */ set(key: TKey, value: TValue): this; /** Reads an entry as the most recently used, inserting `defaultValue` first when absent. */ getOrInsert(key: TKey, defaultValue: TValue): TValue; /** Reads an entry as the most recently used, inserting the result of `callback` first when absent. */ getOrInsertComputed(key: TKey, callback: (key: TKey) => TValue): TValue; } /** * Creates a bounded {@link LRUCache}, evicting the single least recently used entry when a write * exceeds the limit. * * Preferred over an unbounded memo wherever the key space is open-ended (paint strings, resolved * geometry), since evicting one entry keeps every other caller's entry warm — wiping the whole * cache at a threshold makes the steady state a permanent miss. * * @param limit - Maximum number of entries to retain. Values below `1` are clamped to `1`. * @typeParam TKey - Type of the cache key. * @typeParam TValue - Type of the cached value. * @returns The cache instance. * @example * const cache = createLRUCache(2); * * cache.set('a', 1); * cache.set('b', 2); * cache.get('a'); * cache.set('c', 3); // evicts 'b', the least recently used */ declare function createLRUCache(limit: number): LRUCache; //#endregion //#region src/types.d.ts /** A loosely-typed object with string, number, or symbol keys. */ type AnyObject = { [key: PropertyKey]: unknown; }; /** A loosely-typed function signature that accepts and returns anything. */ type AnyFunction = (...args: any[]) => any; /** A loosely-typed async function signature. */ type AnyAsyncFunction = (...args: any[]) => any; /** Represents a single value or an array of values. */ type OneOrMore = TValue | TValue[]; /** A comparison function that tests whether two values match. */ type Predicate = (left: TLeft, right: TRight) => boolean; /** Derives a grouping key from a value. */ type Indexer = (value: TValue) => PropertyKey; /** Merges two types, with properties in `TB` overriding those in `TA`. */ type Merge = Omit & TB; /** Converts a union type to an intersection type. */ type UnionToIntersection = (U extends any ? (arg: U) => any : never) extends ((arg: infer I) => void) ? I : never; /** Conditional type that resolves to `A` if `X` and `Y` are identical, otherwise `B`. */ type IfEquals = (() => TValue extends X ? 1 : 2) extends (() => TValue extends Y ? 1 : 2) ? A : B; /** Extracts the readonly property keys from an object type. */ type GetReadonlyKeys = { [TKey in keyof TValue]-?: IfEquals<{ [Q in TKey]: TValue[TKey]; }, { -readonly [Q in TKey]: TValue[TKey]; }, never, TKey>; }[keyof TValue]; /** Extracts the mutable (non-readonly) property keys from an object type. */ type GetMutableKeys = { [TKey in keyof TValue]-?: IfEquals<{ [Q in TKey]: TValue[TKey]; }, { -readonly [Q in TKey]: TValue[TKey]; }, TKey>; }[keyof TValue]; /** A resource that can be disposed to release underlying subscriptions or handles. */ interface Disposable { /** Releases any resources or subscriptions held by this object. */ dispose: () => void; } //#endregion //#region src/collection.d.ts /** An object whose values are unknown, suitable for generic iteration. */ type IterableObject = Record; /** Callback invoked for each item in a collection, receiving the value and its index. */ type CollectionIteratee = (value: TValue, index: number) => TResult; /** Callback invoked for each entry in an object, receiving the key and value. */ type ObjectIteratee = (key: TKey, value: TValue) => TResult; /** Reducer callback for folding over object entries into an accumulated result. */ type ObjectReducer = (accumulator: TResult, key: TKey, value: TValue) => TResult; /** A property key or indexer function used to derive group identity from array items. */ type ArrayGroupIdentity = keyof TValue | Indexer; /** A shared key or predicate function used to match items between two arrays in a join. */ type ArrayJoinPredicate = keyof (TLeft & TRight) | Predicate; /** Result of an array join containing unmatched left items, matched pairs, and unmatched right items. */ interface ArrayJoin { /** Left items with no matching right item (entries). */ left: TLeft[]; /** Matched pairs of left and right items (updates). */ inner: [left: TLeft, right: TRight][]; /** Right items with no matching left item (exits). */ right: TRight[]; } /** Creates an array of the given length by mapping each index through the iteratee. */ declare function arrayMapRange(length: number, iteratee: (index: number) => TResult): TResult[]; /** Performs a full join between two arrays, returning entries (left-only), updates (matched), and exits (right-only). */ declare function arrayJoin(leftInput: TLeft[], rightInput: TRight[], predicate: ArrayJoinPredicate): ArrayJoin; /** Groups array items by a property key or indexer function into a keyed record. */ declare function arrayGroup(input: TValue[], identity: ArrayGroupIdentity): Record; /** Returns items from the left array that have a matching counterpart in the right array. */ declare function arrayIntersection(leftInput: TLeft[], rightInput: TRight[], predicate?: ArrayJoinPredicate): TLeft[]; /** Returns items from the left array that have no matching counterpart in the right array. */ declare function arrayDifference(leftInput: TLeft[], rightInput: TRight[], predicate?: ArrayJoinPredicate): TLeft[]; /** Returns a new array with duplicate values removed, preserving insertion order. */ declare function arrayDedupe(input: TValue[]): TValue[]; /** Iterates over the enumerable properties of an object, invoking the iteratee for each key-value pair. */ declare function objectForEach(input: TSource, iteratee: ObjectIteratee): void; /** Maps over the enumerable properties of an object, producing a new object with transformed values. */ declare function objectMap = Record>(input: TSource, iteratee: ObjectIteratee, TSource[keyof TSource], unknown>): TResult; /** Reduces the enumerable properties of an object into a single accumulated value. */ declare function objectReduce(input: TSource, reducer: ObjectReducer, initial: TResult): TResult; /** Iterates over each value in a `Set`, invoking the iteratee with the value and a running index. */ declare function setForEach(input: Set, iteratee: CollectionIteratee): void; /** Maps over a `Set`, producing a new `Set` with each value transformed by the iteratee. */ declare function setMap(input: Set, iteratee: CollectionIteratee): Set; /** Filters a `Set`, returning a new `Set` containing only values that satisfy the predicate. */ declare function setFilter(input: Set, predicate: CollectionIteratee): Set; /** Searches a `Set` for the first value that satisfies the predicate. */ declare function setFind(input: Set, predicate: CollectionIteratee): TValue | undefined; /** Flat-maps over a `Set`, concatenating the arrays returned by the iteratee into a new `Set`. */ declare function setFlatMap(input: Set, iteratee: CollectionIteratee): Set; //#endregion //#region src/comparitors.d.ts /** Numeric comparator suitable for sorting numbers in ascending order. */ declare function comparitorNumeric(valueA: number, valueB: number): number; /** Date comparator suitable for sorting dates in ascending chronological order. */ declare function comparitorDate(valueA: Date, valueB: Date): number; /** Locale-aware string comparator suitable for alphabetical sorting. */ declare function comparitorString(valueA: string, valueB: string): number; //#endregion //#region src/function.d.ts /** A function wrapper that caches its result after the first invocation until explicitly invalidated. */ type CachedFunction = { (...args: Parameters): ReturnType; /** Clears the cached result so the next call recomputes it. */ invalidate(): void; }; /** A function wrapper that caches results per unique key, exposing the underlying cache `Map`. */ type MemoizedFunction = { (...args: Parameters): ReturnType; /** The underlying cache mapping each unique key to its memoized result. */ cache: Map>; }; /** Derives a cache key from the arguments of a memoized function. */ type MemoizeResolver = (...args: Parameters) => TKey; /** A do-nothing function, useful as a default callback or placeholder. */ declare function functionNoop(): void; /** Returns the value it receives unchanged, useful as a default transform or placeholder. */ declare function functionIdentity(value: TValue): TValue; /** Wraps a value or factory function into a consistent factory that always returns the value. */ declare function functionProduce(value: TValue | (() => TValue)): () => TValue; /** Wraps a function so its result is computed once and then returned from cache on subsequent calls until `invalidate()` is called. */ declare function functionCache(value: TValue): CachedFunction; /** Memoizes a function by caching results keyed by the resolver (defaults to the first argument). */ declare function functionMemoize[0]>(value: TValue, resolver?: MemoizeResolver): MemoizedFunction; //#endregion //#region src/number.d.ts /** Options for {@link numberFormat}: any `Intl.NumberFormat` option plus a locale and a precision shorthand. */ interface NumberFormatOptions extends Intl.NumberFormatOptions { /** BCP 47 locale tag (defaults to the runtime locale). */ locale?: string; /** Shorthand for `maximumFractionDigits`. */ precision?: number; } /** Constrains a value to the inclusive range between lower and upper bounds. */ declare function numberClamp(value: number, lower: number, upper: number): number; /** Returns the minimum numeric value extracted from an array via the accessor (`Infinity` when empty). */ declare function numberMinOf(values: TValue[], accessor: (value: TValue) => number): number; /** Returns the maximum numeric value extracted from an array via the accessor (`-Infinity` when empty). */ declare function numberMaxOf(values: TValue[], accessor: (value: TValue) => number): number; /** Returns the fractional part of a number (e.g. `numberFractional(3.7)` → `0.7`). */ declare function numberFractional(value: number): number; /** Computes the `[min, max]` extent of an array using the given numeric accessor. */ declare function numberExtent(values: TValue[], accessor: (value: TValue) => number): [min: number, max: number]; /** * Computes the sum of an array of numbers, or of values mapped through an optional iteratee. * * The iteratee wins wherever one is given, so a numeric array is summed through it rather than * raw. Anything that does not resolve to a number — a value with no iteratee to map it, or an * iteratee returning `undefined` — contributes `0`. * * @typeParam TValue - The element type of the array. * @param values - The values to sum. * @param iteratee - Maps each value to the number it contributes. * @returns The sum, or `0` for an empty array. */ declare function numberSum(values: TValue[], iteratee?: (value: TValue) => number): number; /** * Rounds a number to at most `precision` decimal places, stripping any trailing zeros. * * Unlike `Number.prototype.toFixed` (which returns a fixed-width string), this returns a `number` * so integers stay integers (`numberRoundTo(5, 2) === 5`) and fractional values are capped * (`numberRoundTo(1.005, 2) === 1.01`, `numberRoundTo(3.14159, 2) === 3.14`). Non-finite values pass * through unchanged. Used as the default precision cap for chart labels, axes, and tooltips. */ declare function numberRoundTo(value: number, precision?: number): number; /** Rounds a value to a "nice" human-readable number (1, 2, 5, or 10 scaled by the appropriate power of ten). */ declare function numberNice(value: number, round?: boolean): number; /** * Returns the smallest power of `base` that is greater than or equal to `minimum`, starting from `1`. * * A `minimum` of `1` or less (including `0` and negatives) returns `1`. Useful for growing pooled * buffers or capacities in exponential steps. */ declare function numberNextPowerOfN(minimum: number, base?: number): number; /** * Formats a number as a locale-aware string. Supports decimal, `percent`, and `currency` styles; * `compact`/`scientific`/`engineering` notation; grouping; and fraction-digit control (with * `precision` as a shorthand for `maximumFractionDigits`). Non-numeric values fall back to `String`. * * This is a standalone utility; it is passed values explicitly by axes, legends, and tooltips, and * is intentionally never bound to a scale. */ declare function numberFormat(value: unknown, options?: NumberFormatOptions): string; //#endregion //#region src/object.d.ts /** Creates a shallow frozen copy of the given object. */ declare function objectFreeze(value: TValue): Readonly; //#endregion //#region src/predicate.d.ts /** Tests strict reference equality between two values. */ declare function predicateIdentity(valueA: unknown, valueB: unknown): boolean; /** Tests whether two objects share the same value at a given key. */ declare function predicateKey>(valueA: TValue, valueB: TValue, key: PropertyKey): boolean; //#endregion //#region src/string.d.ts /** Generates a cryptographically random hexadecimal string of the specified length (default 8 characters / 32 bits). */ declare function stringUniqueId(length?: number): string; /** Case-insensitive string equality check. */ declare function stringEquals(valueA: string, valueB: string): boolean; //#endregion //#region src/time.d.ts /** Options for {@link timeFormat}: any `Intl.DateTimeFormat` option plus a locale. */ interface TimeFormatOptions extends Intl.DateTimeFormatOptions { /** BCP 47 locale tag (defaults to the runtime locale). */ locale?: string; } /** * Formats a `Date` (or epoch millisecond value) as a locale-aware string via `Intl.DateTimeFormat`. * With no field options a short year/month/day format is used. Passed values explicitly by axes and * tooltips; never bound to a scale. */ declare function timeFormat(value: Date | number, options?: TimeFormatOptions): string; //#endregion //#region src/type.d.ts /** Checks whether a value is an array. */ declare function typeIsArray(value: unknown): value is unknown[]; /** Checks whether a value is a `Date` instance. */ declare function typeIsDate(value: unknown): value is Date; /** Checks whether a value is a non-null object. */ declare function typeIsObject(value: unknown): value is object; /** Checks whether a value is a boolean. */ declare function typeIsBoolean(value: unknown): value is boolean; /** Checks whether a value is a function. */ declare function typeIsFunction(value: unknown): value is AnyFunction; /** Checks whether a value is a number. */ declare function typeIsNumber(value: unknown): value is number; /** Checks whether a value is a string. */ declare function typeIsString(value: unknown): value is string; /** Checks whether a value is `null` or `undefined`. */ declare function typeIsNil(value: unknown): value is null | undefined; //#endregion //#region src/value.d.ts /** Normalizes a single value or array into a guaranteed array. */ declare function valueOneOrMore(value: OneOrMore): TValue[]; //#endregion export { AnyAsyncFunction, AnyFunction, AnyObject, ArrayGroupIdentity, ArrayJoin, ArrayJoinPredicate, CachedFunction, CollectionIteratee, Disposable, GetMutableKeys, GetReadonlyKeys, IfEquals, Indexer, IterableObject, LRUCache, MemoizeResolver, MemoizedFunction, Merge, NumberFormatOptions, ObjectIteratee, ObjectReducer, OneOrMore, Predicate, TimeFormatOptions, UnionToIntersection, arrayDedupe, arrayDifference, arrayGroup, arrayIntersection, arrayJoin, arrayMapRange, comparitorDate, comparitorNumeric, comparitorString, createLRUCache, functionCache, functionIdentity, functionMemoize, functionNoop, functionProduce, numberClamp, numberExtent, numberFormat, numberFractional, numberMaxOf, numberMinOf, numberNextPowerOfN, numberNice, numberRoundTo, numberSum, objectForEach, objectFreeze, objectMap, objectReduce, predicateIdentity, predicateKey, setFilter, setFind, setFlatMap, setForEach, setMap, stringEquals, stringUniqueId, timeFormat, typeIsArray, typeIsBoolean, typeIsDate, typeIsFunction, typeIsNil, typeIsNumber, typeIsObject, typeIsString, valueOneOrMore };