import type { GuardablePredicate } from "./functions.ts"; import type { anyOrNever, conform } from "./generics.ts"; import type { isDisjoint } from "./intersections.ts"; import type { parseNonNegativeInteger } from "./numbers.ts"; type DuplicateData = { element: val; indices: number[]; }; /** * Extracts duplicated elements and their indices from an array, returning them. * * Note that given `a === b && b === c`, then `c === a` must be `true` for this to give accurate results. * * @param arr The array to extract duplicate elements from. */ export declare const getDuplicatesOf: (arr: arr, opts?: ComparisonOptions) => DuplicateData[]; export type pathToString = segments extends [] ? "/" : join; export declare const join: , delimiter extends string>(segments: segments, delimiter: delimiter) => join; export type join, delimiter extends string, result extends string = ""> = segments extends (readonly [infer head extends string, ...infer tail extends string[]]) ? join : result; export declare const getPath: (root: unknown, path: string[]) => unknown; export declare const intersectUniqueLists: (l: readonly item[], r: readonly item[]) => item[]; export type filter = t extends readonly [infer head, ...infer tail] ? filter : result; export type array = readonly t[]; export declare namespace array { type multiply = _multiply; type _multiply = i["length"] extends count ? result : _multiply; type repeat = buildFromSegments, count>; type buildFromSegments = next["length"] extends count ? { [i in keyof next]: element; } : `${count}` extends keyof next ? buildFromSegments, count> : buildFromSegments, count>; type nextSegments = segments extends [unknown, ...infer nextSegments extends 1[][]] ? nextSegments : never; type minLength = readonly [ ...multiply<[element], minLength>, ...element[] ]; } export type listable = t | readonly t[]; export type flattenListable = t extends array ? element : t; export type longerThan = `${n}` extends keyof t ? true : false; export type CollapsingList = readonly [] | t | readonly [t, t, ...t[]]; export type headOf = t[0]; export type tailOf = t extends readonly [unknown, ...infer tail] ? tail : never; export type lastIndexOf = tailOf["length"]; export type lastOf = t[lastIndexOf]; export type initOf = t extends readonly [...infer init, unknown] ? init : never; export type numericStringKeyOf = Extract; export type arrayIndexOf = keyof a extends infer k ? parseNonNegativeInteger : never; export type liftArray = t extends array ? [ t ] extends [anyOrNever] ? t[] : t : t[]; export declare const liftArray: (data: t) => liftArray; /** * Splits an array into two arrays based on the result of a predicate * * @param predicate - The guard function used to determine which items to include. * @returns A tuple containing two arrays: * - the first includes items for which `predicate` returns true * - the second includes items for which `predicate` returns false * * @example * const list = [1, "2", "3", 4, 5]; * const [numbers, strings] = spliterate(list, (x) => typeof x === "number"); * // Type: number[] * // Output: [1, 4, 5] * console.log(evens); * // Type: string[] * // Output: ["2", "3"] * console.log(odds); */ export declare const spliterate: (arr: readonly item[], predicate: GuardablePredicate) => [included: included[], excluded: [item] extends [included] ? item[] : Exclude[]]; export declare const ReadonlyArray: new (...args: ConstructorParameters>) => ReadonlyArray; export declare const includes: (array: a, element: unknown) => element is a[number]; export declare const range: (length: number, offset?: number) => number[]; export type AppendOptions = { /** If true, adds the element to the beginning of the array instead of the end */ prepend?: boolean; }; /** * Adds a value or array to an array, returning the concatenated result */ export declare const append: >(to: to, value: value, opts?: AppendOptions) => to & {}; export type appendableValue = to extends array ? element extends array ? array : listable : never; /** * Concatenates an element or list with a readonly list */ export declare const conflatenate: (to: readonly element[] | undefined | null, elementOrList: appendableValue | undefined | null) => readonly element[]; /** * Concatenates a variadic list of elements or lists with a readonly list */ export declare const conflatenateAll: (...elementsOrLists: (listable | undefined | null)[]) => readonly element[]; export interface ComparisonOptions { isEqual?: (l: t, r: t) => boolean; } /** * Appends a value or concatenates an array to an array if it is not already included, returning the array */ export declare const appendUnique: (to: to | undefined, value: NoInfer | to[number]>, opts?: ComparisonOptions) => to; export type groupableKeyOf = keyof o extends infer k ? k extends keyof o ? o[k] extends PropertyKey ? k : never : never : never; export type groupBy> = { [k in element[discriminant] & PropertyKey]?: (element extends unknown ? isDisjoint extends true ? never : element : never)[]; } & unknown; export declare const groupBy: >(array: readonly element[], discriminant: discriminant) => groupBy; export declare const arrayEquals: (l: array, r: array, opts?: ComparisonOptions) => boolean; export type validateExhaustiveKeys = keys extends readonly [infer head, ...infer tail extends PropertyKey[]] ? readonly [ conform, ...validateExhaustiveKeys> ] : [expectedKey] extends [never] ? [] : [expectedKey]; export type applyElementLabels = labels extends [unknown, ...infer labelsTail] ? t extends readonly [infer head, ...infer tail] ? readonly [ ...labelElement, ...applyElementLabels ] : applyOptionalElementLabels, labels> : t; type applyOptionalElementLabels = labels extends readonly [unknown, ...infer labelsTail] ? t extends readonly [infer head, ...infer tail] ? [ ...labelOptionalElement, ...applyOptionalElementLabels ] : applyRestElementLabels : t; type applyRestElementLabels = t extends readonly [] ? [] : labels extends readonly [unknown, ...infer tail] ? [ ...labelOptionalElement, ...applyRestElementLabels ] : t; type labelElement = labels extends readonly [unknown] ? { [K in keyof labels]: element; } : labels extends readonly [...infer head, unknown] ? labelElement : [_: element]; type labelOptionalElement = label extends readonly [unknown] ? { [K in keyof label]?: element; } : label extends readonly [...infer head, unknown] ? labelOptionalElement : [_?: element]; export type setIndex = arr extends arr[number][] ? _setIndex : Readonly<_setIndex>; type _setIndex = arr extends readonly [infer head, ...infer tail] ? _setIndex : result; type zero = []; type one = [1]; type two = [1, 1]; type three = [...two, ...two]; type four = [...three, ...three]; type five = [...four, ...four]; type six = [...five, ...five]; type seven = [...six, ...six]; type eight = [...seven, ...seven]; type nine = [...eight, ...eight]; type ten = [...nine, ...nine]; type eleven = [...ten, ...ten]; type twelve = [...eleven, ...eleven]; type thirteen = [...twelve, ...twelve]; type fourteen = [...thirteen, ...thirteen]; type exponentials = [ fourteen, thirteen, twelve, eleven, ten, nine, eight, seven, six, five, four, three, two, one, zero ]; declare namespace exponentials { type max = _max; type _max = `${n}` extends keyof filtered[0] ? _max> : filtered; } export {};