/** * Determines whether the types are strictly the same or not. * This was implemented with reference to: {@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650} * @example * Equals<123, 123> equals true * Equals<123, 456> equals false * Equals<123, number> equals false * Equals equals false * Equals equals false * Equals equals false * @example * Equals<'a' | 'b', 'b' | 'a'> equals true * Equals<1, 1 | never> equals true * Equals equals true * @example * Equals equals false * Equals equals false * @example * Equals<[a: string], [b: string]> equals true * Equals<[string?], [] | [string]> equals false */ type Equals = (() => R extends T ? 1 : 2) extends () => R extends U ? 1 : 2 ? Then : Else; /** * A function of the === operator with improved types. * Narrowing is possible on both the left-hand and right-hand sides. * @example * let value = Date.now() % 2 * if (equals(value, 0)) { * // Here, the value is of type 0. * } */ declare function equals(self: T, other: U): self is U; declare function equals(self: T, other: U): other is T; declare function equals(self: T, other: U): false; /** * Determines whether the given type is one of the types in the tuple. * @example * IsOneOf equals true * IsOneOf equals false * IsOneOf equals false * IsOneOf equals false * IsOneOf<1 | 2, [1, 2]> equals false * IsOneOf<'text', [string]> equals false * IsOneOf equals false */ type IsOneOf = U extends readonly [ infer H, ...infer L ] ? Equals extends true ? Then : IsOneOf : Else; /** * Determines whether the given value is one of the value in the tuple. * @example * isOneOf(2, 1, 2, 3) returns true * isOneOf(4, 1, 2, 3) returns false * isOneOf(1) returns false * @example Narrowing * let value = Date.now() % 5 * if (isOneOf(value, 0, 1)) { * // Here, the value is of type 0 | 1. * } */ declare function isOneOf(self: unknown, ...values: T): self is T[number]; declare function isNotOneOf(self: unknown, ...values: readonly unknown[]): boolean; declare const isNull: (value: unknown) => value is null; declare const isUndefined: (value: unknown) => value is undefined; declare const isNullish: (value: unknown) => value is nullish; declare const isBoolean: (value: unknown) => value is boolean; declare const isNumber: (value: unknown) => value is number; declare const isBigint: (value: unknown) => value is bigint; declare const isString: (value: unknown) => value is string; declare const isSymbol: (value: unknown) => value is symbol; declare const isFunction: (value: unknown) => value is Function; declare const isObject: (value: unknown) => value is object; declare const isNotNull: (value: T | null) => value is T; declare const isNotUndefined: (value: T | undefined) => value is T; declare const isNotNullish: (value: T | nullish) => value is T; declare const isNotBoolean: (value: T | boolean) => value is T; declare const isNotNumber: (value: T | number) => value is T; declare const isNotBigint: (value: T | bigint) => value is T; declare const isNotString: (value: T | string) => value is T; declare const isNotSymbol: (value: T | symbol) => value is T; declare const isNotFunction: (value: T | Function) => value is T; declare const isNotObject: (value: T | symbol) => value is T; /** * @example * isTruthy(false) returns false * isTruthy(undefined) returns false * isTruthy(null) returns false * isTruthy(0) returns false * isTruthy(0n) returns false * isTruthy('') returns false * isTruthy(NaN) returns false * @example * isTruthy(true) returns true * isTruthy(1) returns true * isTruthy(1n) returns true * isTruthy('a') returns true * isTruthy({}) returns true * isTruthy([]) returns true * isTruthy(() => {}) returns true */ declare function isTruthy(value: false | null | undefined | 0 | 0n | ''): false; declare function isTruthy(value: T | false | null | undefined | 0 | 0n | ''): value is T; /** * @example * isFalsy(false) returns true * isFalsy(undefined) returns true * isFalsy(null) returns true * isFalsy(0) returns true * isFalsy(0n) returns true * isFalsy('') returns true * isFalsy(NaN) returns true * @example * isFalsy(true) returns false * isFalsy(1) returns false * isFalsy(1n) returns false * isFalsy('a') returns false * isFalsy({}) returns false * isFalsy([]) returns false * isFalsy(() => {}) returns false */ declare function isFalsy(value: false | null | undefined | 0 | 0n | ''): true; declare function isFalsy(value: unknown): value is false | null | undefined | number | 0n | ''; declare function isInstanceOf any>(value: unknown, ctor: T): value is InstanceType; declare function isNotInstanceOf any, U>(value: U, ctor: T): value is Exclude>; /** * @example * assertTypeEquality() results in a type error * assertTypeEquality<123, 123>() does not result in a type error */ declare function assertTypeEquality(..._: Equals extends true ? [] : [error: [T, 'is not equal to', U]]): void; declare function assert(value: T, predicate: (value: T) => value is U): asserts value is U; declare function assert(value: T, predicate: (value: T) => boolean): void; declare function assertEqual(lhs: T, rhs: U): asserts lhs is U; declare function assertEqual(lhs: T, rhs: U): asserts rhs is T; declare function assertEqual(lhs: T, rhs: U): never; declare function assertInstanceOf any>(value: unknown, ctor: T): asserts value is InstanceType; /** * @example * let status: 'on' | 'off' = 'on' * switch (status) { * case 'on': * break * case 'off': * break * default: * assertNeverType(status) * } */ declare function assertNeverType(mustBeNever: never): never; /** Alias for null | undefined type */ type nullish = null | undefined; /** * Removes readonly modifier. * @example * Writable<{ readonly a: number }> equals { a: number } * Writable equals string[] * @example It does not apply to nested types. * Writable<{ nested: { readonly a: number } }> equals { nested: { readonly a: number } } * Writable<[readonly boolean[]]> equals [readonly boolean[]] */ type Writable = { -readonly [K in keyof T]: T[K]; }; declare const DEFAULT_BRAND: unique symbol; type Branded = T & Record; /** * Convert a literal type to its corresponding primitive type. * @example * ToBasePrimitiveType<'a'> equals string * ToBasePrimitiveType<1> equals number * ToBasePrimitiveType equals boolean * ToBasePrimitiveType equals undefined * ToBasePrimitiveType equals null * @example * ToBasePrimitiveType<1 | 'a'> equals number | string */ type ToBasePrimitiveType = T extends T ? IsOneOf extends true ? T : T extends string ? string : T extends number ? number : T extends bigint ? bigint : T extends boolean ? boolean : T extends symbol ? symbol : T : never; declare const lazyKey: unique symbol; /** One of the utilities to avoid the recursion limit */ interface Lazy { [lazyKey]: T; } /** One of the utilities to avoid the recursion limit */ type Unlazy = T extends { [lazyKey]: unknown; } ? Unlazy> : T; type ReduceLazy = T extends { [lazyKey]: never; } ? never : T extends { [lazyKey]: { [lazyKey]: { [lazyKey]: { [lazyKey]: infer U; }; }; }; } ? { [lazyKey]: ReduceLazy; } : T extends { [lazyKey]: { [lazyKey]: { [lazyKey]: infer U; }; }; } ? U : T extends { [lazyKey]: { [lazyKey]: infer U; }; } ? U : T extends { [lazyKey]: infer U; } ? U : T; /** A type that is neither a class nor an object or array containing a class. */ type NeitherClassNorContainsClass = null | undefined | boolean | number | bigint | string | symbol | ((..._: readonly unknown[]) => unknown) | readonly NeitherClassNorContainsClass[] | { readonly [key: keyof any]: NeitherClassNorContainsClass; }; declare const OMITTED: unique symbol; /** The default type of the type parameters */ type OMITTED = typeof OMITTED; /** * @example * MaxLengthArray<2> equals [] | [unknown] | [unknown, unknown] * MaxLengthArray<3, Date> equals [] | [Date] | [Date, Date] | [Date, Date, Date] * MaxLengthArray<0, string> equals [] * @example * MaxLengthArray equals string[] */ type MaxLengthArray = FixedLengthArray, T>; type ReadonlyMaxLengthArray = Readonly>; declare function isMaxLengthArray(self: T[], length: N): self is MaxLengthArray; declare function isMaxLengthArray(self: readonly T[], length: N): self is ReadonlyMaxLengthArray; declare function isMaxLengthArray(self: unknown, length: N): self is MaxLengthArray; declare function shuffle(self: T): FixedLengthArray; /** * @example * IsTuple<[]> equals true * IsTuple<[1, 2, 3]> equals true * IsTuple<[1, ...0[]]> equals true * IsTuple<[1, 2?, 3?]> equals true * IsTuple equals false * IsTuple equals false */ type IsTuple = T extends T ? IsOneOf : never; /** * @example * DestructTuple<[1, 2, ...3[], 4, 5]> equals { leading: [1, 2]; optional: []; rest: 3[]; trailing: [4, 5] } * DestructTuple<[1, 2?, ...3[]]> equals { leading: [1]; optional: [2]; rest: 3[]; trailing: [] } * DestructTuple equals { leading: []; optional: []; rest: Date[]; trailing: [] } * DestructTuple<[]> equals { leading: []; optional: []; rest: []; trailing: [] } */ type DestructTuple = Equals extends true ? { leading: []; optional: []; rest: any[]; trailing: []; } : T extends readonly [infer H, ...infer L] ? DestructTuple : T extends readonly [...infer L, infer H] ? DestructTuple : IsTuple extends false ? { leading: Leading; optional: Optional; rest: T; trailing: Trailing; } : T extends readonly [] ? { leading: Leading; optional: Optional; rest: T; trailing: Trailing; } : T extends readonly [(infer H)?, ...infer L] ? DestructTuple : never; declare function cartesianProductOf(lhs: T, rhs: U): [T[number], U[number]][]; declare function permutationOf(self: readonly T[], n?: number): (readonly T[])[]; /** * @example * createNGrams([1, 2, 3], 2) returns [[1, 2], [2, 3]] * createNGrams([1, 2, 3], 3) returns [[1, 2, 3]] * createNGrams([1, 2, 3], 1) returns [[1], [2], [3]] */ declare function createNGrams(self: T, n: N): T[number][][]; /** * @example * PrefixesOf<[1, 2, 3]> returns [[], [1], [1, 2], [1, 2, 3]] */ type PrefixesOf = IsTuple extends false ? T[] : PrefixesOfForTuple; type PrefixesOfForTuple = T extends readonly [ infer H, ...infer L ] ? [R, ...PrefixesOfForTuple] : IsTuple extends false ? [R, [...R, ...T]] : [R]; /** * @example * prefixesOf([1, 2, 3]) returns [[], [1], [1, 2], [1, 2, 3]] * prefixesOf([]) returns [[]] */ declare function prefixesOf(self: readonly T[]): NonEmptyArray; declare function filter(self: readonly [], f: (_: T) => boolean): []; declare function filter(self: readonly T[], f: (_: T) => _ is U): U[]; declare function filter(self: readonly T[], f: (_: T) => boolean): T[]; declare function partition(self: readonly [], f: (_: T) => boolean): [[], []]; declare function partition(self: readonly T[], f: (_: T) => _ is U): [U[], Exclude[]]; declare function partition(self: readonly T[], f: (_: T) => boolean): [T[], T[]]; /** * @example * Take<[0, 1, 2], 0> equals [] * Take<[0, 1, 2], 1> equals [0] * Take<[0, 1, 2], 2> equals [0, 1] * Take<[0, 1, 2], 3> equals [0, 1, 2] * Take<[0, 1, 2], 4> equals [0, 1, 2] * @example * Take equals [Date, Date] | [Date] | [] * Take<[number, ...string[]], 2> equals [number, string] | [number] * Take<[...Date[], bigint], 2> equals [Date, Date] | [Date, bigint] | [bigint] * @example * Take<[0, 1, 2], 1 | 2> equals [0] | [0, 1] * Take<[0, 1, 2], number> equals [] | [0] | [0, 1] | [0, 1, 2] */ type Take = Equals extends true ? MaxLengthArray : IsOneOf extends true ? PrefixesOf[number] : N extends N ? _Take : never; type _Take = R['length'] extends N ? R : T extends readonly [infer H, ...infer L] ? _Take : T extends readonly [] ? R : Subtract extends infer S extends number ? IsTuple extends false ? [...R, ...MaxLengthArray] : IntegerRangeThrough extends infer M extends number ? M extends M ? [ ...R, ...FixedLengthArray['rest'][0]>, ...Take['trailing'], Subtract> ] : never : never : never; declare function take(self: T, n: N): Take; declare function take(self: Iterable, n: N): MaxLengthArray; /** * @example * Drop<[0, 1, 2], 0> equals [0, 1, 2] * Drop<[0, 1, 2], 1> equals [1, 2] * Drop<[0, 1, 2], 2> equals [2] * Drop<[0, 1, 2], 3> equals [] * Drop<[0, 1, 2], 4> equals [] * @example * Drop<[0, 1, 2], 1 | 2> equals [1, 2] | [2] * Drop<[0, 1, 2], number> equals [0, 1, 2] | [1, 2] | [2] | [] * @example * Drop<[number, ...string[]], 2> equals string[] * Drop equals any */ type Drop = N extends N ? number extends N ? _Drop> : _Drop> : never; type _Drop = N extends readonly [any, ...infer NL] ? T extends readonly [any, ...infer TL] ? _Drop : T extends readonly [...infer TL, infer H] ? Equals extends true ? _Drop : T : T extends readonly [] ? [] : T : T; /** * Remove the first n elements from an array immutably. * If the second argument is omitted, it removes only one element. * * @example * drop([0, 1, 2]) returns [1, 2] * drop([0, 1, 2], 2) returns [2] * drop([0, 1, 2], 3) returns [] * @example * drop([0, 1, 2], 4) returns [] * drop([0, 1, 2], 0) returns [0, 1, 2] * drop([0, 1, 2], -1) returns [0, 1, 2] */ declare function drop(self: T): Drop; declare function drop(self: T, n: N): Drop; /** * @example * DropLast<[0, 1, 2], 0> equals [0, 1, 2] * DropLast<[0, 1, 2], 1> equals [0, 1] * DropLast<[0, 1, 2], 2> equals [0] * DropLast<[0, 1, 2], 3> equals [] * DropLast<[0, 1, 2], 4> equals [] * @example * DropLast<[0, 1, 2], 1 | 2> equals [0, 1] | [0] * DropLast<[0, 1, 2], number> equals [0, 1, 2] | [0, 1] | [0] | [] * @example * DropLast<[...number[], boolean], 2> equals number[] * DropLast equals any */ type DropLast = N extends N ? number extends N ? _DropLast> : _DropLast> : never; type _DropLast = N extends readonly [any, ...infer NL] ? T extends readonly [...infer TL, any] ? _DropLast : T extends readonly [] ? [] : T : T; /** * Remove the last n elements from an array immutably. * If the second argument is omitted, it removes only one element. * * @example * dropLast([0, 1, 2]) returns [0, 1] * dropLast([0, 1, 2], 2) returns [0] * dropLast([0, 1, 2], 3) returns [] * @example * dropLast([0, 1, 2], 4) returns [] * dropLast([0, 1, 2], 0) returns [0, 1, 2] * dropLast([0, 1, 2], -1) returns [0, 1, 2] */ declare function dropLast(self: T): Writable>; declare function dropLast(self: T, n: N): Writable>; declare function takeWhile(self: readonly T[], f: (_: T) => _ is U): U[]; declare function takeWhile(self: readonly T[], f: (_: T) => boolean): T[]; /** * @example * FirstOf<[bigint]> equals bigint * FirstOf<[number, bigint]> equals number * FirstOf<[]> equals undefined * FirstOf equals boolean | undefined * FirstOf<[...string[], number]> equals string | number * @example * FirstOf<[Date] | [Date, boolean]> equals Date * FirstOf<[Date?, boolean?]> equals Date | boolean | undefined */ type FirstOf = T extends readonly [infer First, ...any] ? First : T extends readonly [...infer U, infer Last] ? _FirstOf : T extends readonly [] ? undefined : T[number][] extends T ? T[number] | undefined : T extends readonly [(infer H)?, ...infer L] ? H | FirstOf : never; type _FirstOf = T extends readonly [] ? L : T extends readonly [...infer T2, infer L2] ? _FirstOf : T[0] | L; declare function firstOf(self: T): FirstOf; /** * @example * LastOf<[bigint]> equals bigint * LastOf<[bigint, number]> equals number * LastOf<[]> equals undefined * LastOf equals boolean | undefined * LastOf<[string, ...string[]]> equals string * LastOf<[boolean, ...string[]]> equals boolean | string * @example * LastOf<[Date] | [Date, boolean]> equals Date | boolean * LastOf<[Date?, boolean?]> equals Date | boolean | undefined */ type LastOf = T extends readonly [...any, infer Last] ? Last : T extends readonly [] ? undefined : T extends readonly [infer H, ...infer L] ? _LastOf : T[number][] extends T ? T[number] | undefined : T extends readonly [(infer H)?, ...infer L] ? H | LastOf : T[0] | undefined; type _LastOf = L extends readonly [] ? H : L extends readonly [infer H2, ...infer L2] ? _LastOf : L[number][] extends L ? H | L[0] : L extends readonly [(infer H2)?, ...infer L2] ? _LastOf : H | L[0]; declare function lastOf(self: T): LastOf; /** * Improved version of {@link Array.prototype.indexOf}. * Returns undefined instead of -1 if not found. */ declare function indexOf(self: readonly [], value: T, fromIndex?: number): undefined; declare function indexOf(self: readonly T[], value: T, fromIndex?: number): number | undefined; declare function lastIndexOf(self: readonly [], value: T, fromIndex?: number): undefined; declare function lastIndexOf(self: readonly T[], value: T, fromIndex?: number): number | undefined; declare function indexesOf(self: readonly [], value: T): []; declare function indexesOf(self: readonly T[], value: T): number[]; declare function maxOf(self: ReadonlyNonEmptyArray): T; declare function maxOf(self: readonly T[]): T | undefined; declare function maxBy(self: ReadonlyNonEmptyArray, by: (element: T) => U): T; declare function maxBy(self: readonly T[], by: (element: T) => U): T | undefined; declare function minOf(self: ReadonlyNonEmptyArray): T; declare function minOf(self: readonly T[]): T | undefined; declare function minBy(self: ReadonlyNonEmptyArray, by: (element: T) => U): T; declare function minBy(self: readonly T[], by: (element: T) => U): T | undefined; declare function elementAt(self: Iterable, n: number): T | undefined; declare function modeOf(self: ReadonlyNonEmptyArray): T; declare function modeOf(self: readonly T[]): T | undefined; declare function modeBy(self: ReadonlyNonEmptyArray, by: (_: T) => U): T; declare function modeBy(self: readonly T[], by: (_: T) => U): T | undefined; type NonEmptyArray = [T, ...T[]] | [...T[], T]; type ReadonlyNonEmptyArray = Readonly>; /** * @example * MinLengthArray<1> equals [unknown, ...unknown[]] | [...unknown[], unknown] * MinLengthArray<2, Date> equals [Date, Date, ...Date[]] | [Date, ...Date[], Date] | [...Date[], Date, Date] * MinLengthArray<0, string> equals string[] * MinLengthArray equals string[] */ type MinLengthArray = _MinLengthArray, T>; type _MinLengthArray = M extends M ? [...Drop, M>, ...T[], ...FixedLengthArray] : never; type ReadonlyMinLengthArray = _ReadonlyMinLengthArray, T>; type _ReadonlyMinLengthArray = M extends M ? readonly [...Drop, M>, ...T[], ...FixedLengthArray] : never; declare function isMinLengthArray(self: T[], length: N): self is MinLengthArray; declare function isMinLengthArray(self: readonly T[], length: N): self is ReadonlyMinLengthArray; declare function isMinLengthArray(self: unknown, length: N): self is MinLengthArray; declare const NON_EMPTY_MAP_TAG: unique symbol; type NonEmptyMap = Branded, typeof NON_EMPTY_MAP_TAG>; type ReadonlyNonEmptyMap = Branded, typeof NON_EMPTY_MAP_TAG>; /** * Create a Map object from a tuple of key-value pairs. * More precisely typed than Map constructor. * @example * mapOf([true, 1], [false, 0]) returns new Map([[true, 1], [false, 0]]) * mapOf([true, 1], [false, 0]) is typed as Map * @example * mapOf() returns new Map() * mapOf() is typed as Map */ declare function mapOf(...args: T): Map; declare const NON_EMPTY_SET_TAG: unique symbol; type NonEmptySet = Branded, typeof NON_EMPTY_SET_TAG>; type ReadonlyNonEmptySet = Branded, typeof NON_EMPTY_SET_TAG>; /** * setOf(...) is shorthand for new Set([...]). * Note that setOf() is Set type, unlike new Set() being Set type. * @example * setOf(121, 'abc') returns new Set([123, 'abc']) * setOf(121, 'abc') is typed as Set * @example * setOf() returns new Set() * setOf() is typed as Set */ declare function setOf(): Set; declare function setOf(...args: T): Set; /** * Add the given value to the set, but remove it if it is already included. * In other words, toggle the membership of the given value. * @example * toggleMembership(setOf(1, 2, 3), 2) returns setOf(1, 3) * toggleMembership(setOf(1, 2, 3), 4) returns setOf(1, 2, 3, 4) */ declare function toggleMembership(self: ReadonlySet, value: U): Set | Set; declare function setMembership(self: ReadonlySet, value: U, has: boolean): Set; declare function has(self: ReadonlySet, value: T): value is U; declare function has(self: ReadonlySet, value: T): boolean; /** * Create a union set. * @example * unionOf(setOf(1, 2, 3), setOf(2, 3, 4)) returns setOf(1, 2, 3, 4) * unionOf(setOf(1, 2, 3), setOf(2)) returns setOf(1, 2, 3) */ declare function unionOf(lhs: ReadonlyNonEmptySet, rhs: ReadonlySet): NonEmptySet; declare function unionOf(lhs: ReadonlySet, rhs: ReadonlyNonEmptySet): NonEmptySet; declare function unionOf(lhs: ReadonlySet, rhs: ReadonlySet): Set; /** * Create an intersection set. * @example * intersectionOf(setOf(1, 2, 3), setOf(2, 3, 4)) returns setOf(2, 3) * intersectionOf(setOf(1, 2, 3), setOf(4, 5)) returns setOf() */ declare function intersectionOf(lhs: ReadonlySet, rhs: ReadonlySet): Set; declare function intersectionOf(lhs: ReadonlySet, rhs: ReadonlySet): Set; declare function intersectionOf(lhs: ReadonlySet, rhs: ReadonlySet): Set; declare function intersectionOf(lhs: ReadonlySet, rhs: ReadonlySet): Set; /** * Create the set difference(lhs - rhs) that elements are contained lhs but not contained rhs. * @example * differenceOf(setOf(1, 2, 3), setOf(2, 3, 4)) returns setOf(1) */ declare function differenceOf(lhs: ReadonlySet, rhs: ReadonlySet): Set; declare function isDisjoint(lhs: ReadonlySet, rhs: ReadonlySet): boolean; /** isSubsetOf(a, b) means a ⊆ b. */ declare function isSubsetOf(lhs: ReadonlySet, rhs: ReadonlySet): boolean; /** * @example * ToNumber<'00'> equals 0 * ToNumber<'001'> equals 1 * ToNumber<'-0'> equals 0 * ToNumber<'-00'> equals 0 * ToNumber<'-001'> equals -1 * ToNumber<'Infinity'> equals Infinity * ToNumber<'-Infinity'> equals -Infinity * @example * ToNumber<'1' | '2'> equals 1 | 2 * ToNumber equals number * ToNumber equals number * ToNumber equals never * @example NaN is typed as number * ToNumber<'0xFF'> equals number * ToNumber<'1px'> equals number * ToNumber<''> equals number * ToNumber<' 12'> equals number * ToNumber<'1_234'> equals number * ToNumber<'1,234'> equals number */ type ToNumber = S extends 'Infinity' ? Infinity : S extends '-Infinity' ? NegativeInfinity : S extends `-${infer U}` ? RemoveLeadingExtraZeros extends `${infer N extends number}` ? Negate : number : RemoveLeadingExtraZeros extends `${infer N extends number}` ? N : number; type RemoveLeadingExtraZeros = T extends `0${infer U extends Digit}${infer L}` ? RemoveLeadingExtraZeros<`${U}${L}`> : T; /** * @example * toNumber('123') returns 123 * toNumber('123') is typed as 123 * @example * toNumber('-1') returns -1 * toNumber('-1') is typed as -1 * @example * toNumber('01') returns 1 * toNumber('01') is typed as 1 * @example * toNumber('1.0') returns 1 * toNumber('1.0') is typed as number * @example * toNumber('1.05') returns 1.05 * toNumber('1.05') is typed as 1.05 */ declare function toNumber(text: T): ToNumber; type ToString = T extends Interpolable ? `${T}` : string; declare function toString(value: T): ToString; /** * A type for enabling automatic completion of specific literals in an editor. * Unlike a literal union type, it also accepts values other than the specified literals. * https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts */ type LiteralAutoComplete = Literals | (ToBasePrimitiveType & {}); /** The types that can be interpolated within a template literal. */ type Interpolable = string | number | bigint | boolean | null | undefined; type CharactersSubjectToRemoveByTrim = ' ' | '\t' | '\n' | '\r' | '\f' | '\v' | '\uFEFF' | '\xA0'; /** * @example * TrimStart<' abc '> equals 'abc ' * TrimStart<'\n\t\r\uFEFF\xA0'> equals '' */ type TrimStart = Equals extends true ? string : T extends `${CharactersSubjectToRemoveByTrim}${infer L}` ? TrimStart : T; /** * @example * trimStart(' abc ') returns 'abc ' * trimStart('\n\t\r\uFEFF\xA0') returns '' */ declare function trimStart(self: T): TrimStart; /** * @example * TrimEnd<' abc '> equals ' abc' * TrimEnd<'\n\t\r\uFEFF\xA0'> equals '' */ type TrimEnd = Equals extends true ? string : T extends `${infer L}${CharactersSubjectToRemoveByTrim}` ? TrimEnd : T; /** * @example * trimEnd(' abc ') returns ' abc' * trimEnd('\n\t\r\uFEFF\xA0') returns '' */ declare function trimEnd(self: T): TrimEnd; /** * @example * TrimStart<' abc '> equals 'abc' * TrimStart<'\n\t\r\uFEFF\xA0'> equals '' */ type Trim = TrimStart>; /** * @example * trim(' abc ') returns 'abc' * trim('\n\t\r\uFEFF\xA0') returns '' */ declare function trim(self: T): Trim; declare function map(self: ReadonlyNonEmptyArray, f: (_: T) => U): NonEmptyArray; declare function map(self: readonly T[], f: (_: T) => U): U[]; /** * @example * flatMap([0, 1, 2], (x) => [x, x + 0.5]) returns [0, 0.5, 1, 1.5, 2, 2.5] */ declare function flatMap(self: readonly T[], f: (_: T) => readonly []): []; declare function flatMap(self: readonly [], f: (_: T) => readonly U[]): []; declare function flatMap(self: readonly T[], f: (_: T) => readonly U[]): U[]; declare function flatten(self: readonly (readonly T[])[]): T[]; /** * @example * Join<['a', 'b', 'c']> equals 'a,b,c' * Join<['a', 'b', 'c'], ''> equals 'abc' * Join<['a', 'b', 'c'], '-' | '.'> equals 'a-b-c' | 'a.b.c' * Join<[], '.'> equals '' * @example * Join<[1, 2, 3], ' + '> equals '1 + 2 + 3' * Join<[Date, RegExp]> equals string */ type Join = Equals extends true ? string : T extends readonly Interpolable[] ? _Join : string; type _Join = T extends readonly [ infer U extends Interpolable ] ? `${U}` : T extends readonly [infer H extends Interpolable, ...infer L extends readonly Interpolable[]] ? `${H}${Separator}${_Join}` : T extends readonly [] ? '' : string; /** * @example * join(['a', 'b', 'c']) returns 'a,b,c' * join(['a', 'b', 'c'], '') returns 'abc' * join([1, 2, 3], ' + ') returns '1 + 2 + 3' */ declare function join(self: T, separator?: Separator): Join; /** * @example * Split<'12:34', ':'> equals ['12', '34'] * Split<'12:34:56', ':'> equals ['12', '34', '56'] * Split<'12:34', '@'> equals ['12:34'] * Split<'//', '/'> equals ['', '', ''] * Split<'12:34', ''> equals ['1', '2', ':', '3', '4'] * Split<`${number}:${number}`, ':'> equals [`${number}`, `${number}`] */ type Split = string extends Separator ? string[] : Separator extends Separator ? T extends `${infer H}${Separator}${infer L}` ? `${Separator}${L}` extends '' ? [H] : [H, ...Split] : [T] : never; /** * Note that when both arguments are empty strings, the return value differs from the standard split method. * @example * split('12:34', ':') returns ['12', '34'] * split('12:34', '') returns ['1', '2', ':', '3', '4'] * split('12:34', '@') returns ['12:34'] * split('', '') returns [''] */ declare function split(self: T, separator: Separator): Split; /** * @example * chunk([1, 2, 3, 4, 5, 6], 2) returns [[1, 2], [3, 4], [5, 6]] * chunk([1, 2, 3, 4, 5, 6], 2) is typed as [number, number][] * @example * chunk([3, 1, 4, 1, 5, 9, 2], 3) returns [[3, 1, 4], [1, 5, 9]] * chunk([3, 1, 4, 1, 5, 9, 2], 3) is typed as [number, number, number][] */ declare function chunk(array: readonly T[], size: N): number extends N ? T[][] : FixedLengthArray[]; declare function padStart(self: T, length: number, value: string): string; declare function padEnd(self: T, length: number, value: string): string; declare function sort(self: T): FixedLengthArray; declare function sortBy(self: T, by: (_: T[number]) => U): FixedLengthArray; /** * @example * Reverse<[0, 1, 2]> equals [2, 1, 0] * Reverse<[]> equals [] * Reverse equals string[] * @example * Reverse<[0, 1] | [0, 1, 2]> equals [1, 0] | [2, 1, 0] * Reverse<[0, 1, ...number[], 9]> equals [9, ...number[], 1, 0] */ type Reverse = [ ..._Reverse['trailing']>, ...DestructTuple['rest'], ..._Reverse['optional'], IntegerRangeThrough['optional']['length']>>>, ..._Reverse['leading']> ]; type _Reverse = T extends readonly [infer First, ...infer R, infer Last] ? [Last, ..._Reverse, First] : T extends readonly [infer First, ...infer R] ? [..._Reverse, First] : T extends readonly [...infer R, infer Last] ? [Last, ..._Reverse] : T extends readonly [] ? [] : T; declare function reverse(self: T): Reverse; /** * @example * removeDuplicates(['a', 'b', 'a', 'c']) returns ['a', 'b', 'c'] * removeDuplicates([]) returns [] * removeDuplicates([undefined, null, null, null, undefined]) returns [undefined, null] */ declare function removeDuplicates(self: readonly T[]): T[]; declare function removeDuplicatesBy(self: readonly T[], by: (_: T) => U): T[]; /** * Generate the next sequential number starting from 0. * @example * [getNextSequentialNumber(), getNextSequentialNumber()] equals [0, 1] */ declare function getNextSequentialNumber(): number; /** * @example * SequentialNumbersUntil<3> equals [0, 1, 2] * SequentialNumbersUntil<2, 5> equals [2, 3, 4] * SequentialNumbersUntil<5, 2> equals [5, 4, 3] * SequentialNumbersUntil<7, 7> equals [] * @example * SequentialNumbersUntil<-3, 2> equals [-3, -2, -1, 0, 1] * SequentialNumbersUntil<3, -2> equals [3, 2, 1, 0, -1] * SequentialNumbersUntil<-1, -3> equals [-1, -2] * SequentialNumbersUntil<-3, -1> equals [-3, -2] * @example * SequentialNumbersUntil<2 | -2> equals [0, 1] | [0, -1] * SequentialNumbersUntil<1, 3 | 5> equals [1, 2] | [1, 2, 3, 4] * SequentialNumbersUntil<0 | 2, 4> equals [0, 1, 2, 3] | [2, 3] * SequentialNumbersUntil equals number[] */ type SequentialNumbersUntil = To extends number ? number extends From ? number[] : number extends To ? number[] : From extends From ? To extends To ? `${From}` extends `-${infer PN extends number}` ? `${To}` extends `-${infer PM extends number}` ? [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? ToNegativeNumbers, PN>> : ToNegativeNumbers, NaturalNumbersThrough['length']>>> : [...ToNegativeNumbers>>, ...NaturalNumbersUntil] : `${To}` extends `-${infer PM extends number}` ? [...Reverse>, ...ToNegativeNumbers>] : [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? Drop, From> : Reverse, NaturalNumbersThrough['length']>> : never : never : SequentialNumbersUntil<0, From>; /** * @example * SequentialNumbersThrough<3> equals [0, 1, 2, 3] * SequentialNumbersThrough<2, 5> equals [2, 3, 4, 5] * SequentialNumbersThrough<5, 2> equals [5, 4, 3, 2] * SequentialNumbersThrough<7, 7> equals [7] * @example * SequentialNumbersThrough<-3, 2> equals [-3, -2, -1, 0, 1, 2] * SequentialNumbersThrough<3, -2> equals [3, 2, 1, 0, -1, -2] * SequentialNumbersThrough<-1, -3> equals [-1, -2, -3] * SequentialNumbersThrough<-3, -1> equals [-3, -2, -1] * @example * SequentialNumbersThrough<2 | -2> equals [0, 1, 2] | [0, -1, -2] * SequentialNumbersThrough<1, 3 | 5> equals [1, 2, 3] | [1, 2, 3, 4, 5] * SequentialNumbersThrough<0 | 2, 4> equals [0, 1, 2, 3, 4] | [2, 3, 4] * SequentialNumbersThrough equals [number, ...number[]] | [...number[], number] */ type SequentialNumbersThrough = To extends number ? number extends From ? NonEmptyArray : number extends To ? NonEmptyArray : From extends From ? To extends To ? `${From}` extends `-${infer PN extends number}` ? `${To}` extends `-${infer PM extends number}` ? [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? ToNegativeNumbers, PN>> : ToNegativeNumbers, PM>>> : [...ToNegativeNumbers>>, ...NaturalNumbersThrough] : `${To}` extends `-${infer PM extends number}` ? [...Reverse>, ...ToNegativeNumbers>] : [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? Drop, From> : Reverse, To>> : never : never : SequentialNumbersThrough<0, From>; /** * @example * NaturalNumbersUntil<3> equals [0, 1, 2] * NaturalNumbersUntil<0> equals [] * NaturalNumbersUntil<1 | 2> equals [0] | [0, 1] * NaturalNumbersUntil equals number[] */ type NaturalNumbersUntil = number extends N ? number[] : N extends N ? Unlazy<_NaturalNumbersUntil> : never; type _NaturalNumbersUntil = Acc['length'] extends N ? Acc : Lazy<_NaturalNumbersUntil>; /** * @example * NaturalNumbersThrough<3> equals [0, 1, 2, 3] * NaturalNumbersThrough<0> equals [0] * NaturalNumbersThrough<1 | 2> equals [0, 1] | [0, 1, 2] * NaturalNumbersThrough equals number[] */ type NaturalNumbersThrough = number extends N ? number[] : N extends N ? Unlazy<_NaturalNumbersThrough>> : never; type _NaturalNumbersThrough = Size extends readonly [any, ...infer L extends readonly unknown[]] ? Lazy<_NaturalNumbersThrough> : [0, ...R]; /** * @example * PositiveIntegersThrough<3> equals [1, 2, 3] * PositiveIntegersThrough<1 | 2> equals [1] | [1, 2] * PositiveIntegersThrough<0> equals [] * PositiveIntegersThrough equals number[] */ type PositiveIntegersThrough = number extends N ? number[] : N extends 0 ? [] : N extends N ? _PositiveIntegersThrough> : never; type _PositiveIntegersThrough = Size extends readonly [any, ...infer L] ? _PositiveIntegersThrough : R; /** * @example * ToNegativeNumbers<[1, 2, -3]> equals [-1, -2, -3] * ToNegativeNumbers<[0]> equals [0] * ToNegativeNumbers<[]> equals [] */ type ToNegativeNumbers = T extends readonly [ infer H extends number, ...infer L extends readonly number[] ] ? H extends 0 ? [0, ...ToNegativeNumbers] : `-${H}` extends `${infer N extends number}` ? [N, ...ToNegativeNumbers] : [H, ...ToNegativeNumbers] : []; /** * @example * sequentialNumbersUntil(3) returns [0, 1, 2] * sequentialNumbersUntil(3) is typed as [0, 1, 2] * @example * sequentialNumbersUntil(0) returns [] * sequentialNumbersUntil(0) is typed as [] * @example * sequentialNumbersUntil(4 as number) returns [0, 1, 2, 3] * sequentialNumbersUntil(4 as number) is typed as number[] */ declare function sequentialNumbersUntil(to: To): SequentialNumbersUntil; declare function sequentialNumbersUntil(from: From, to: To): SequentialNumbersUntil; /** * @example * sequentialNumbersThrough(3) returns [0, 1, 2, 3] * sequentialNumbersThrough(3) is typed as [0, 1, 2, 3] * @example * sequentialNumbersThrough(0) returns [0] * sequentialNumbersThrough(0) is typed as [0] * @example * sequentialNumbersThrough(4 as number) returns [0, 1, 2, 3, 4] * sequentialNumbersThrough(4 as number) is typed as number[] */ declare function sequentialNumbersThrough(to: To): SequentialNumbersThrough; declare function sequentialNumbersThrough(from: From, to: To): SequentialNumbersThrough; /** * Generate an array of unique random natural numbers. * @example * uniqueRandomIntegersUntil(2, 2) returns [0, 1] or [1, 0] * uniqueRandomIntegersUntil(2, 1) returns [0] or [1] * uniqueRandomIntegersUntil(3, 1) returns [0] or [1] or [2] * uniqueRandomIntegersUntil(3, 2) returns [0, 1] or [0, 2] or [1, 0] or [1, 2] or [2, 0] or [2, 1] * @example * uniqueRandomIntegersUntil(2, 2) is typed as [0 | 1, 0 | 1] */ declare function uniqueRandomIntegersUntil(upperBound: N, length: M): FixedLengthArray>; /** * @example * Repeat<3, ['a', 'b']> is typed as ['a', 'b', 'a', 'b', 'a', 'b'] * Repeat<0, ['a', 'b']> is typed as [] * @example * Repeat<0 | 1, ['a', 'b']> is typed as [] | ['a', 'b'] * Repeat is typed as ('a' | 'b')[] */ type Repeat = number extends N ? A[number][] : N extends N ? _Repeat : never; type _Repeat = Size['length'] extends N ? R : _Repeat; /** * @example * RepeatString<'Abc', 2> equals 'AbcAbc' * RepeatString<'A', 0> equals '' * @example * RepeatString<'A' | 'B', 2> equals 'AA' | 'AB' | 'BA' | 'BB' * RepeatString<'A', 1 | 3> equals 'A' | 'AAA' * @example * RepeatString equals string * RepeatString<'A', number> equals string */ type RepeatString = string extends S ? string : number extends N ? string : _RepeatString>; type _RepeatString = Size extends [any, ...infer L] ? `${S}${_RepeatString}` : ''; /** * @example * repeat(3, 'a') returns ['a', 'a', 'a'] * repeat(2, true, false) returns [true, false, true, false] */ declare function repeat(count: N, ...values: T): Repeat; declare function repeatApply(length: N, first: T, f: (_: T) => T): FixedLengthArray; /** * Function that improves the type of Object.fromEntries. * * @example * fromEntries([['a', 1], ['b', 2]]) returns { a: 1, b: 2 } * fromEntries([['a', 1], ['b', 2]]) is typed as Record<'a' | 'b', 1 | 2> * @example * fromEntries([]) returns {} * fromEntries([]) is typed as Record */ declare function fromEntries(entries: Iterable): Record; /** * @example * IntegerRangeUntil<3> equals 0 | 1 | 2 * IntegerRangeUntil<4, 8> equals 4 | 5 | 6 | 7 * IntegerRangeUntil<5, 3> equals 5 | 4 * @example * IntegerRangeUntil<2, -2> equals 2 | 1 | 0 | -1 * IntegerRangeUntil<-2, 2> equals -2 | -1 | 0 | 1 * @example * IntegerRangeUntil<1, 1> equals never * IntegerRangeUntil<0> equals never * @example * IntegerRangeUntil<2 | 4> equals 0 | 1 | 2 | 3 * IntegerRangeUntil equals number * IntegerRangeUntil<9, number> equals number */ type IntegerRangeUntil = N extends N ? M extends M ? IsOneOf extends true ? number : M extends number ? `${N}` extends `-${infer PN extends number}` ? `${M}` extends `-${infer PM extends number}` ? [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? Negate, NaturalNumbersFrom0Through>> : Negate, NaturalNumbersFrom0Until>> : Negate> | NaturalNumbersFrom0Until : `${M}` extends `-${infer PM extends number}` ? NaturalNumbersFrom0Through | Negate> : [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? Exclude, NaturalNumbersFrom0Through> : Exclude, NaturalNumbersFrom0Until> : IntegerRangeUntil<0, N> : never : never; /** * @example * IntegerRangeThrough<3> equals 0 | 1 | 2 | 3 * IntegerRangeThrough<4, 8> equals 4 | 5 | 6 | 7 | 8 * IntegerRangeThrough<5, 3> equals 5 | 4 | 3 * @example * IntegerRangeThrough<2, -2> equals 2 | 1 | 0 | -1 | -2 * IntegerRangeThrough<-2, 2> equals -2 | -1 | 0 | 1 | 2 * @example * IntegerRangeThrough<1, 1> equals 1 * IntegerRangeThrough<0> equals 0 * @example * IntegerRangeThrough<2 | 4> equals 0 | 1 | 2 | 3 | 4 * IntegerRangeThrough equals number * IntegerRangeThrough<9, number> equals number */ type IntegerRangeThrough = N extends N ? M extends M ? IsOneOf extends true ? number : M extends number ? `${N}` extends `-${infer PN extends number}` ? `${M}` extends `-${infer PM extends number}` ? [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? Negate, NaturalNumbersFrom0Until>> : Negate, NaturalNumbersFrom0Until>> : Negate> | NaturalNumbersFrom0Through : `${M}` extends `-${infer PM extends number}` ? NaturalNumbersFrom0Through | Negate> : [...FixedLengthArray, ...any] extends [...FixedLengthArray, ...any] ? Exclude, NaturalNumbersFrom0Until> : Exclude, NaturalNumbersFrom0Until> : IntegerRangeThrough<0, N> : never : never; type DigitToRangeUntil = { '0': never; '1': '0'; '2': '0' | '1'; '3': '0' | '1' | '2'; '4': '0' | '1' | '2' | '3'; '5': '0' | '1' | '2' | '3' | '4'; '6': '0' | '1' | '2' | '3' | '4' | '5'; '7': '0' | '1' | '2' | '3' | '4' | '5' | '6'; '8': '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7'; '9': '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8'; }; /** * Generate a union type from 0 to the given number minus 1. It's orders of magnitude faster compared to a naive implementation. * @example * NaturalNumbersFrom0Until<0> equals never * NaturalNumbersFrom0Until<1> equals 0 * NaturalNumbersFrom0Until<2> equals 0 | 1 * NaturalNumbersFrom0Until<10000> equals 0 | 1 | 2 | ... | 9999 */ type NaturalNumbersFrom0Until = ToNumber<_NaturalNumbersFrom0Until>>; type _NaturalNumbersFrom0Until = DigitArray extends readonly [ infer D extends Digit ] ? `${DigitToRangeUntil[D]}` : DigitArray extends readonly [infer H extends Digit, ...infer L extends readonly Digit[]] ? `${DigitToRangeUntil[H]}${RepeatString extends infer S extends string ? S : never}` | `${H}${_NaturalNumbersFrom0Until}` : ''; /** * Generate a union type from 0 to the given number. It's orders of magnitude faster compared to a naive implementation. * @example * NaturalNumbersFrom0Through<0> equals 0 * NaturalNumbersFrom0Through<1> equals 1 * NaturalNumbersFrom0Through<2> equals 0 | 1 | 2 * NaturalNumbersFrom0Through<10000> equals 0 | 1 | 2 | ... | 10000 */ type NaturalNumbersFrom0Through = NaturalNumbersFrom0Until | N; /** * Determine if the given value is in the given range. * @example * isInIntegerRangeUntil(50, 0, 100) returns true * isInIntegerRangeUntil(101, 0, 100) returns false * @example */ declare function isInIntegerRangeUntil(value: number, n: N, m: M): value is IntegerRangeUntil; declare function isInIntegerRangeThrough(value: number, n: N, m: M): value is IntegerRangeThrough; /** * @example * randomIntegerUntil(3) returns 0, 1 or 2 * randomIntegerUntil(3) is typed as 0 | 1 | 2 * randomIntegerUntil(1, 4) returns 1, 2 or 3 * randomIntegerUntil(1, 4) is typed as 1 | 2 | 3 * @example * randomIntegerUntil(-2) returns 0 or -1 * randomIntegerUntil(-2) is typed as 0 | -1 * @example * randomIntegerUntil(0) throws RangeError * randomIntegerUntil(0) is typed as never * randomIntegerUntil(5, 5) throws RangeError * randomIntegerUntil(5, 5) is typed as never */ declare function randomIntegerUntil(to: To): IntegerRangeUntil; declare function randomIntegerUntil(from: From, to: To): IntegerRangeUntil; declare function randomIntegerThrough(end: N): IntegerRangeThrough; declare function randomIntegerThrough(start: N, end: M): IntegerRangeThrough; type Infinity = 1e999; declare const Infinity: Infinity; type NegativeInfinity = -1e999; declare const NegativeInfinity: NegativeInfinity; /** * @example * IsInteger<12.34> equals false * IsInteger<-12> equals true * IsInteger<1.2e-15> equals false * IsInteger<1.2e+15> equals true * @example * IsInteger<1.8e+308> equals false (Note that 1.8e+308 is Infinity) * @example Customizing result values * IsInteger<12, []> equals [] * IsInteger<0.5, number, never> equals never */ type IsInteger = N extends N ? IsOneOf extends true ? boolean : `${N}` extends `${string}e+${string}` ? Then : `${N}` extends `${string}.${string}` | `${string}e-${string}` | 'Infinity' | '-Infinity' ? Else : Then : never; /** * @example * Negate<1> equals -1 * Negate<-0.5> equals 0.5 * Negate<0> equals 0 * Negate<-0> equals 0 * Negate<1e+100> equals -1e+100 * Negate<-1.2e-45> equals 1.2e-45 * Negate<2 | -4> equals -2 | 4 * Negate equals number */ type Negate = N extends 0 ? 0 : number extends N ? number : N extends N ? `${N}` extends `-${infer P extends number}` ? P : `-${N}` extends `${infer M extends number}` ? M : never : never; /** * Convert a natural number type into an array type of its digits. * @example * ToDigitArray<123> equals ['1', '2', '3'] * ToDigitArray<0> equals ['0'] */ type ToDigitArray = _ToDigitArray<`${N}`>; type _ToDigitArray = S extends `${infer H extends Digit}${infer L}` ? [H, ..._ToDigitArray] : []; type Subtract = _SubtractNaturalNumber, FixedLengthArray>; type _SubtractNaturalNumber = N extends readonly [ any, ...infer NL ] ? M extends readonly [any, ...infer ML] ? _SubtractNaturalNumber : N['length'] : Negate; type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'; /** * Function to calculate modulo instead of reminder. * Unlike the % operator, the modOf function handles negative numbers differently, such that the result has the same sign as the divisor. * * @example * modOf(4, 3) returns 1 * modOf(3, 3) returns 0 * modOf(2, 3) returns 2 * modOf(1, 3) returns 1 * modOf(0, 3) returns 0 * modOf(-1, 3) returns 2 * modOf(-2, 3) returns 1 * modOf(-3, 3) returns 0 * modOf(-4, 3) returns 2 * @example * modOf(4, -3) returns -2 * modOf(3, -3) returns -0 * modOf(2, -3) returns -1 * modOf(1, -3) returns -2 * modOf(0, -3) returns -0 * modOf(-1, -3) returns -1 * modOf(-2, -3) returns -2 * modOf(-3, -3) returns -0 * modOf(-4, -3) returns -1 * @example * modOf(3.5, 2) returns 1.5 * modOf(0.5, 0.2) returns 0.09999999999999998 * @example * modOf(Infinity, 2) returns NaN * modOf(9, Infinity) returns NaN */ declare function modOf(a: N, b: M): IsInteger extends false ? number : IsInteger extends false ? number : IntegerRangeUntil; declare function factorialOf(n: number): number; /** * @example * FixedLengthArray<3> equals [unknown, unknown, unknown] * FixedLengthArray<3, boolean> equals [boolean, boolean, boolean] * FixedLengthArray<0, Set> equals [] * @example * FixedLengthArray<2 | 3, any> equals [any, any] | [any, any, any] * FixedLengthArray equals bigint[] */ type FixedLengthArray = number extends N ? T[] : DigitArrayToFixedLengthArray, T>; type ReadonlyFixedLengthArray = Readonly>; declare function isFixedLengthArray(self: T[], length: N): self is FixedLengthArray; declare function isFixedLengthArray(self: readonly T[], length: N): self is ReadonlyFixedLengthArray; declare function isFixedLengthArray(self: unknown, length: N): self is FixedLengthArray; /** Create a tuple by repeating the given tuple 10 times. */ type TenTimes = [...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T, ...T]; type DigitToFixedLengthArray = { '0': []; '1': [T]; '2': [T, T]; '3': [T, T, T]; '4': [T, T, T, T]; '5': [T, T, T, T, T]; '6': [T, T, T, T, T, T]; '7': [T, T, T, T, T, T, T]; '8': [T, T, T, T, T, T, T, T]; '9': [T, T, T, T, T, T, T, T, T]; }[N]; /** * @example * DigitArrayToFixedLengthArray<['2']> equals [unknown, unknown] * DigitArrayToFixedLengthArray<['0', '3']> ie equivalent to [unknown, unknown, unknown] * DigitArrayToFixedLengthArray<['1', '0']> ie equivalent to [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown */ type DigitArrayToFixedLengthArray = DigitArray extends [ ...infer R extends readonly Digit[], infer Last extends Digit ] ? [...DigitToFixedLengthArray, ...TenTimes>] : []; declare function isEmpty(self: readonly []): true; declare function isEmpty(self: readonly never[]): true; declare function isEmpty(self: ReadonlyNonEmptyArray): false; declare function isEmpty(self: T[]): self is []; declare function isEmpty(self: readonly T[]): self is readonly []; declare function isEmpty(self: ReadonlySet): true; declare function isEmpty(self: ReadonlyNonEmptySet): false; declare function isEmpty(self: ReadonlyMap): true; declare function isEmpty(self: ReadonlyNonEmptyMap): false; declare function isEmpty(self: ''): true; declare function isEmpty(self: string): self is ''; declare function isEmpty(self: Iterable): boolean; declare function isNotEmpty(self: readonly []): false; declare function isNotEmpty(self: readonly never[]): false; declare function isNotEmpty(self: ReadonlyNonEmptyArray): true; declare function isNotEmpty(self: T[]): self is NonEmptyArray; declare function isNotEmpty(self: readonly T[]): self is ReadonlyNonEmptyArray; declare function isNotEmpty(self: ReadonlySet): false; declare function isNotEmpty(self: ReadonlyNonEmptySet): true; declare function isNotEmpty(self: Set): self is NonEmptySet; declare function isNotEmpty(self: ReadonlySet): self is ReadonlyNonEmptySet; declare function isNotEmpty(self: ReadonlyMap): true; declare function isNotEmpty(self: ReadonlyNonEmptyMap): false; declare function isNotEmpty(self: Map): self is NonEmptyMap; declare function isNotEmpty(self: ReadonlyMap): self is ReadonlyNonEmptyMap; declare function isNotEmpty(self: ''): false; declare function isNotEmpty(self: Iterable): boolean; declare function every(self: readonly [], f: (value: T) => boolean): true; declare function every(self: T[], f: (value: T) => value is U): self is U[]; declare function every(self: readonly T[], f: (value: T) => value is U): self is readonly U[]; declare function every(self: readonly T[], f: (value: T) => boolean): boolean; declare function some(self: readonly [], f: (value: T) => boolean): false; declare function some(self: readonly T[], f: (value: T) => boolean): self is ReadonlyNonEmptyArray; declare function everyIterable(self: Set, f: (value: T) => value is U): self is Set; declare function everyIterable(self: ReadonlySet, f: (value: T) => value is U): self is ReadonlySet; declare function everyIterable(self: Iterable, f: (value: T) => value is U): self is Iterable; declare function everyIterable(self: Iterable, f: (value: T) => boolean): boolean; declare function someIterable(self: Iterable, f: (value: T) => boolean): boolean; declare function includes(self: readonly [], value: unknown, fromIndex?: number | undefined): false; declare function includes(self: T, value: unknown, fromIndex?: number | undefined): value is T[number]; declare function isUnique(self: readonly [] | ''): true; declare function isUnique(self: Iterable): boolean; declare function push(self: T, ...args: U): [...T, ...U]; declare function unshift(self: T, ...args: U): [...U, ...T]; /** * @example * insertAt([0, 1, 2], 0, 9) returns [9, 0, 1, 2] * insertAt([0, 1, 2], 1, 9) returns [0, 9, 1, 2] * insertAt([0, 1, 2], 3, 9) returns [0, 1, 2, 9] * insertAt([0, 1, 2], 4, 9) returns [0, 1, 2] * insertAt([0, 1, 2], -1, 9) returns [0, 1, 2] * insertAt([0, 1, 2], 1, false, null) returns [0, false, null, 1, 2] */ declare function insertAt(self: readonly T[], at: number, ...values: U): NonEmptyArray; type RemoveAt = Equals extends true ? any[] : _RemoveAt>; type _RemoveAt = T extends readonly [infer H, ...infer L] ? N extends readonly [any, ...infer M] ? _RemoveAt : [...Acc, ...L] : [...Acc, ...T]; /** * @example * removeAt([0, 1, 2], 0) returns [1, 2] * removeAt([0, 1, 2], 1) returns [0, 2] * removeAt([0, 1, 2], 2) returns [0, 1] * removeAt([0, 1, 2], 3) returns [0, 1, 2] * removeAt([0, 1, 2], -1) returns [0, 1, 2] */ declare function removeAt(self: T, i: N): RemoveAt; declare function removeAll(self: readonly T[], value: T): T[]; declare function remove(self: readonly T[], value: T): T[]; /** * @example * removePrefix('ABCDE', 'AB') returns 'CDE' * removePrefix('ABCDE', 'ABCDE') returns '' * removePrefix('ABCDE', '123') returns 'ABCDE' * removePrefix('ABCDE', '') returns 'ABCDE' */ declare function removePrefix(self: string, prefix: string): string; /** * @example * removeSuffix('ABCDE', 'DE') returns 'ABC' * removeSuffix('ABCDE', 'ABCDE') returns '' * removeSuffix('ABCDE', '123') returns 'ABCDE' * removeSuffix('ABCDE', '') returns 'ABCDE' */ declare function removeSuffix(self: string, suffix: string): string; declare function moveTo(self: readonly T[], from: number, to: number): T[]; /** Convert Less-Than function (< symbol) to comparator. */ declare function createComparatorFromIsLessThan(isLessThan: (lhs: T, rhs: T) => boolean): (lhs: T, rhs: T) => number; /** Convert Less-Than or Equal to function (<= symbol) to comparator. */ declare function createComparatorFromIsAtMost(isAtMost: (lhs: T, rhs: T) => boolean): (lhs: T, rhs: T) => number; /** * Compare two iterables lexicographically. * @returns true if lhs is lexicographically less than rhs. * @example * isLexicographicLessThan([1, 2, 3], [1, 2, 4]) returns true * isLexicographicLessThan([1, 2, 3], [1, 2, 3]) returns false * isLexicographicLessThan([10], [3]) returns false * isLexicographicLessThan(['alice'], ['bob']) returns true * isLexicographicLessThan([], []) returns false * @example Different length * isLexicographicLessThan([1, 2, 3], [1, 2]) returns false */ declare function isLexicographicLessThan(lhs: Iterable, rhs: Iterable): boolean; declare function isLexicographicAtMost(lhs: Iterable, rhs: Iterable): boolean; declare function curry(f: (h: H, ...l: L) => R): (a: H) => (...bs: L) => R; /** * Shorthand for IIFEs (Immediately Invoked Function Expressions). * It improves readability and can avoid issues with semicolons. * @example * const resultCode = call(() => { * switch (type) { * case 'success': * return 1 * case 'failure': * return 2 * default: * return 3 * } * }) */ declare function call(f: () => T): T; /** * Returns the given value as is. * It is known as the identity function in mathematics. * @example Primitive values * identity(9) returns 9 * identity('text') returns 'text' * @example Mutable object * const now = new Date() * identity(now) returns now */ declare function identity(value: T): T; /** * Passes a value through a pipeline (a sequence of functions). * For example, pipe(x, f, g) is equivalent to g(f(x)). */ declare function pipe(a: A): A; declare function pipe(a: A, b: (a: A) => B): B; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C): C; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D): D; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E): E; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F): F; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G): G; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G, h: (g: G) => H): H; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G, h: (g: G) => H, i: (h: H) => I): I; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G, h: (g: G) => H, i: (h: H) => I, j: (i: I) => J): J; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G, h: (g: G) => H, i: (h: H) => I, j: (i: I) => J, k: (j: J) => K): K; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G, h: (g: G) => H, i: (h: H) => I, j: (i: I) => J, k: (j: J) => K, l: (k: K) => L): L; declare function pipe(a: A, b: (a: A) => B, c: (b: B) => C, d: (c: C) => D, e: (d: D) => E, f: (e: E) => F, g: (f: F) => G, h: (g: G) => H, i: (h: H) => I, j: (i: I) => J, k: (j: J) => K, l: (k: K) => L, m: (l: L) => M): M; declare function pipe(a: A, ...fs: readonly ((a: A) => A)[]): A; type UnwrapArrayAll = T extends readonly [infer H, ...infer L] ? [H extends readonly (infer U)[] ? U : H, ...UnwrapArrayAll] : []; type UnwrapIterableAll = T extends readonly [infer H, ...infer L] ? [H extends Iterable ? U : H, ...UnwrapIterableAll] : []; type ZipArray = UnwrapArrayAll[]; /** * @example * zip([1, 2, 3], ['a', 'b', 'c']) returns [[1, 'a'], [2, 'b'], [3, 'c']] * zip([1, 2, 3], ['a', 'b']) returns [[1, 'a'], [2, 'b']] * @example * zip([1, 2, 3], ['a', 'b', 'c'], [true, false, true]) returns [[1, 'a', true], [2, 'b', false], [3, 'c', true]] */ declare function zip(...source: T): ZipArray; declare function zipWith(f: (...tuple: UnwrapArrayAll) => U, ...source: T): U[]; type AtLeastOneIsNonUndefined> = N extends N ? SetUndefinedableAllBut : never; type SetUndefinedableAllBut = T extends readonly [infer H, ...infer L] ? N extends L['length'] ? [H, ...SetUndefinedableAllBut] : [H | undefined, ...SetUndefinedableAllBut] : []; type ZipAllArray = AtLeastOneIsNonUndefined>[]; declare function zipAll(...source: T): ZipAllArray; /** * @example * merge([1, 2, 3], ['a', 'b', 'c']) returns [1, 'a', 2, 'b', 3, 'c'] * merge([1, 2, 3, 4], ['a', 'b']) returns [1, 'a', 2, 'b', 3, 4] * merge([], []) returns [] */ declare function merge(lhs: readonly T[], rhs: readonly U[]): (T | U)[]; /** * The clamp function restricts a given input value to a specified range or interval, by constraining it to a minimum and maximum value. * If the input value is within the specified range, the function returns the input value itself. * However, if the input value is outside of the specified range, the function returns the nearest boundary value that it is constrained to. * * @example * clamp(0, 50, 100) returns 50 * clamp(0, 110, 100) returns 100 * clamp(0, -20, 100) returns 0 * @example * clamp(0, Infinity, 100) returns 100 * clamp(0, -Infinity, 100) returns 0 * @example * clamp(0, 50, Infinity) returns 50 * clamp(-Infinity, 50, 100) returns 50 */ declare function clamp(min: number, value: number, max: number): number; type NestedProperty = Ks extends readonly [] ? T : Ks extends readonly [infer H extends keyof T, ...infer R extends readonly (keyof any)[]] ? NestedProperty : undefined; /** * The value level function of Omit. * @example * omit({ a: 1 }, 'a') equals {} * omit({ a: 1, b: 2 }, 'a', 'b') equals {} * omit({ a: 1 }, 'b') equals { a: 1 } */ declare function omit[]>(self: T, ...keys: Keys): Omit; /** * @example * getNestedProperty({ a: 123 }, 'a') returns 123 * getNestedProperty({ a: 123, b: { c: 'nested' } }, 'b', 'c') returns 'nested' * @example * getNestedProperty({ a: 123 }, 'z', 'x') returns undefined * @example Empty path * getNestedProperty({ a: 123 }) returns { a: 123 } */ declare function getNestedProperty(self: T, ...keys: Ks): NestedProperty; declare function groupBy(self: readonly T[], by: (_: T) => U): Map>; /** * @example * toMultiset(['a', 'a', 'b', 'c']) returns new Map([['a', 2], ['b', 1], ['c', 1]]) * toMultiset('aabc') returns new Map([['a', 2], ['b', 1], ['c', 1]]) */ declare function toMultiset(self: readonly []): Map; declare function toMultiset(self: ''): Map; declare function toMultiset(self: Iterable): Map; declare function sumOf(self: readonly []): 0; declare function sumOf(self: readonly number[]): number; declare const forever: Promise; type AllKeysOf = IsOneOf extends true ? [] : Equals extends true ? (string | symbol)[] : T extends Record ? ToStringKey[] : (string | symbol)[]; type ToStringKey = K extends number ? `${K}` : K; /** * Get all keys of an object including inherited keys. * It behaves similarly to the keyof operator. * @example * allKeysOf({ name: 'Bob', age: 60 }) returns ['name', 'age'] * allKeysOf({}) returns [] * allKeysOf({ 0: false, 1: true }) returns ['0', '1'] * allKeysOf({ [Symbol.iterator]: false }) returns [Symbol.iterator] */ declare function allKeysOf(objectLike: T): AllKeysOf; type UppercaseLetter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'; declare function isUppercaseLetter(self: string): self is UppercaseLetter; type LowercaseLetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'; declare function isLowercaseLetter(self: string): self is LowercaseLetter; /** * Convert the first character to uppercase. * @example * capitalize('hello') returns 'Hello' * capitalize('HTML') returns 'HTML' * capitalize('') returns '' * capitalize('123') returns '123' */ declare function capitalize(self: T): Capitalize; /** * Splits a string in formats like snake_case or PascalCase into words. * Words such as 'iPhone' are not correctly recognized. * @example * SplitIntoWords<''> equals [] * SplitIntoWords<'kebab-case'> equals ['kebab', 'case'] * SplitIntoWords<'snake_case'> equals ['snake', 'case'] * SplitIntoWords<'PascalCase'> equals ['Pascal', 'Case'] * SplitIntoWords<'camelCase'> equals ['camel', 'Case'] * SplitIntoWords<'SCREAMING_SNAKE_CASE'> equals ['SCREAMING', 'SNAKE', 'CASE'] * SplitIntoWords<'Title Case'> equals ['Title', 'Case'] * @example * SplitIntoWords<'block__element--modifier'> equals ['block', 'element', 'modifier'] * SplitIntoWords<`abc_${string}_xyz`> equals ['abc', string, 'xyz'] * @example * SplitIntoWords<'iPhone'> equals ['i', 'Phone'] */ type SplitIntoWords = IsOneOf extends true ? string[] : _SplitIntoWords; type _SplitIntoWords = T extends `${infer H1 extends LowercaseLetter}${infer H2 extends UppercaseLetter}${infer L}` ? _SplitIntoWords<`${H2}${L}`, D, '', [...Result, `${Acc}${H1}`]> : T extends `${infer H1 extends UppercaseLetter}${infer H2 extends LowercaseLetter}${infer L}` ? _SplitIntoWords<`${H2}${L}`, D, H1, Acc extends '' ? Result : [...Result, Acc]> : T extends `${D}${infer L}` ? _SplitIntoWords : T extends `${infer H1}${infer L}` ? _SplitIntoWords : Acc extends '' ? Result : [...Result, Acc]; /** * @example * splitIntoWords('camelCase') returns ['camel', 'Case'] * splitIntoWords('PascalCase') returns ['Pascal', 'Case'] * splitIntoWords('snake_case') returns ['snake', 'case'] * splitIntoWords('SCREAMING_SNAKE_CASE') returns ['SCREAMING', 'SNAKE', 'CASE'] * splitIntoWords('Title Case') returns ['Title', 'Case'] * @example * splitIntoWords('block__element--modifier') returns ['block', 'element', 'modifier'] * splitIntoWords('XMLHttpRequest') returns ['XML', 'Http', 'Request'] * splitIntoWords('innerHTML') returns ['inner', 'HTML'] * splitIntoWords('getXCoordinate') returns ['get', 'X', 'Coordinate'] * splitIntoWords('') returns [] */ declare function splitIntoWords(self: T, separators?: D): SplitIntoWords; /** * @example * ToSnakeCase<'camelCase'> equals 'camel_case' * ToSnakeCase<'PascalCase'> equals 'pascal_case' * ToSnakeCase<'kebab-case'> equals 'kebab_case' * ToSnakeCase<'SCREAMING_SNAKE_CASE'> equals 'screaming_snake_case' * ToSnakeCase<'Title Case'> equals 'title_case' * @example * ToSnakeCase<'block__element--modifier'> equals 'block_element_modifier' * ToSnakeCase<'XMLHttpRequest'> equals 'xml_http_request' * ToSnakeCase<'innerHTML'> equals 'inner_html' * ToSnakeCase<'getXCoordinate'> equals 'get_x_coordinate' * ToSnakeCase<'camelCase' | 'PascalCase'> equals 'camel_case' | 'pascal_case' */ type ToSnakeCase = IsOneOf extends true ? string : Lowercase, '_'>>; /** * @example * toSnakeCase('camelCase') returns 'camel_case' * toSnakeCase('PascalCase') returns 'pascal_case' * toSnakeCase('kebab-case') returns 'kebab_case' * toSnakeCase('SCREAMING_SNAKE_CASE') returns 'screaming_snake_case' * toSnakeCase('Title Case') returns 'title_case' * @example * toSnakeCase('block__element--modifier') returns 'block_element_modifier' * toSnakeCase('XMLHttpRequest') returns 'xml_http_request' * toSnakeCase('innerHTML') returns 'inner_html' * toSnakeCase('getXCoordinate') returns 'get_x_coordinate' */ declare function toSnakeCase(self: T): ToSnakeCase; /** * @example * ToKebabCase<'camelCase'> equals 'camel-case' * ToKebabCase<'PascalCase'> equals 'pascal-case' * ToKebabCase<'snake_case'> equals 'snake-case' * ToKebabCase<'SCREAMING_SNAKE_CASE'> equals 'screaming-snake-case' * ToKebabCase<'Title Case'> equals 'title-case' * @example * ToKebabCase<'block__element--modifier'> equals 'block-element-modifier' * ToKebabCase<'XMLHttpRequest'> equals 'xml-http-request' * ToKebabCase<'innerHTML'> equals 'inner-html' * ToKebabCase<'getXCoordinate'> equals 'get-x-coordinate' * ToKebabCase<'camelCase' | 'PascalCase'> equals 'camel-case' | 'pascal-case' */ type ToKebabCase = IsOneOf extends true ? string : Lowercase, '-'>>; /** * @example * toKebabCase('camelCase') returns 'camel-case' * toKebabCase('PascalCase') returns 'pascal-case' * toKebabCase('snake_case') returns 'snake-case' * toKebabCase('SCREAMING_SNAKE_CASE') returns 'screaming-snake-case' * toKebabCase('Title Case') returns 'title-case' * @example * toKebabCase('block__element--modifier') returns 'block-element-modifier' * toKebabCase('XMLHttpRequest') returns 'xml-http-request' * toKebabCase('innerHTML') returns 'inner-html' * toKebabCase('getXCoordinate') returns 'get-x-coordinate' */ declare function toKebabCase(self: T): ToKebabCase; /** * @example * ToCamelCase<'PascalCase'> equals 'pascalCase' * ToCamelCase<'snake_case'> equals 'snakeCase' * ToCamelCase<'kebab-case'> equals 'kebabCase' * ToCamelCase<'SCREAMING_SNAKE_CASE'> equals 'screamingSnakeCase' * ToCamelCase<'Title Case'> equals 'titleCase' * @example * ToCamelCase<'block__element--modifier'> equals 'blockElementModifier' * ToCamelCase<'XMLHttpRequest'> equals 'xmlHttpRequest' * ToCamelCase<'innerHTML'> equals 'innerHtml' * ToCamelCase<'getXCoordinate'> equals 'getXCoordinate' */ type ToCamelCase = IsOneOf extends true ? string : SplitIntoWords extends readonly [infer H extends string, ...infer L extends readonly string[]] ? Join<[Lowercase, ...PascalizeAll], ''> : ''; type PascalizeAll = T extends readonly [ infer H extends string, ...infer L extends readonly string[] ] ? [Capitalize>, ...PascalizeAll] : []; /** * @example * toCamelCase('PascalCase') returns 'pascalCase' * toCamelCase('snake_case') returns 'snakeCase' * toCamelCase('kebab-case') returns 'kebabCase' * toCamelCase('SCREAMING_SNAKE_CASE') returns 'screamingSnakeCase' * toCamelCase('Title Case') returns 'titleCase' * @example * toCamelCase('block__element--modifier') returns 'blockElementModifier' * toCamelCase('XMLHttpRequest') returns 'xmlHttpRequest' * toCamelCase('innerHTML') returns 'innerHtml' * toCamelCase('getXCoordinate') returns 'getXCoordinate' */ declare function toCamelCase(self: T): ToCamelCase; /** * Converts all property names in a given object type to snake case. * This function is recursively applied to objects nested within objects and arrays. * * @example * ToSnakeCasedPropertiesDeeply<{ firstName: string, lastName: string }> equals { first_name: string, last_name: string } * ToSnakeCasedPropertiesDeeply<{ nested: { firstName: string } }> equals { nested: { first_name: string } } * ToSnakeCasedPropertiesDeeply<{ tags: { createdAt: number }[] }> equals { tags: { created_at: number }[] } * ToSnakeCasedPropertiesDeeply<{ firstName: string }[]> equals { first_name: string }[] * @example keep modifiers * ToSnakeCasedPropertiesDeeply<{ readonly firstName?: string }> equals { readonly first_name?: string } * ToSnakeCasedPropertiesDeeply equals readonly string[] */ type ToSnakeCasedPropertiesDeeply = Equals extends true ? T : T extends Function ? T : T extends readonly unknown[] ? ToSnakeCasedPropertiesDeeplyTuple : { [K in keyof T as K extends string ? ToSnakeCase : K]: ToSnakeCasedPropertiesDeeply; }; type ToSnakeCasedPropertiesDeeplyTuple = T extends any[] ? _ToSnakeCasedPropertiesDeeplyTuple : Readonly<_ToSnakeCasedPropertiesDeeplyTuple>; type _ToSnakeCasedPropertiesDeeplyTuple = T extends readonly [infer H, ...infer L] ? [ToSnakeCasedPropertiesDeeply, ..._ToSnakeCasedPropertiesDeeplyTuple] : T extends readonly [...infer L, infer H] ? [..._ToSnakeCasedPropertiesDeeplyTuple, ToSnakeCasedPropertiesDeeply] : T extends readonly [] ? [] : T[number][] extends T ? ToSnakeCasedPropertiesDeeply[] : T extends readonly [(infer H)?, ...infer L] ? [ToSnakeCasedPropertiesDeeply?, ..._ToSnakeCasedPropertiesDeeplyTuple] : never; /** * Converts all property names in a given object to snake case. * This function is recursively applied to objects nested within objects and arrays. * * @example * toSnakeCasedPropertiesDeeply({ firstName: 'John', lastName: 'Smith' }) returns { first_name: 'John', last_name: 'Smith' } * toSnakeCasedPropertiesDeeply({ nested: { firstName: 'John' } }) returns { nested: { first_name: 'John' } } * toSnakeCasedPropertiesDeeply({ tags: [{ createdAt: 1 }] }) returns { tags: [{ created_at: 1 }] } * toSnakeCasedPropertiesDeeply([{ firstName: 'John' }]) returns [{ first_name: 'John' }] * toSnakeCasedPropertiesDeeply(undefined) returns undefined * toSnakeCasedPropertiesDeeply('kebab-case-text') returns 'kebab-case-text' */ declare function toSnakeCasedPropertiesDeeply(self: T): ToSnakeCasedPropertiesDeeply; /** * Converts all property names in a given object type to camel case. * This function is recursively applied to objects nested within objects and arrays. * * @example * ToCamelCasedPropertiesDeeply<{ first_name: string, last_name: string }> equals { firstName: string, lastName: string } * ToCamelCasedPropertiesDeeply<{ nested: { first_name: string } }> equals { nested: { firstName: string } } * ToCamelCasedPropertiesDeeply<{ tags: { created_at: number }[] }> equals { tags: { createdAt: number }[] } * ToCamelCasedPropertiesDeeply<{ first_name: string }[]> equals { firstName: string }[] * @example keep modifiers * ToCamelCasedPropertiesDeeply<{ readonly first_name?: string }> equals { readonly firstName?: string } * ToCamelCasedPropertiesDeeply equals readonly string[] */ type ToCamelCasedPropertiesDeeply = Equals extends true ? T : T extends Function ? T : T extends readonly unknown[] ? ToCamelCasedPropertiesDeeplyTuple : { [K in keyof T as K extends string ? ToCamelCase : K]: ToCamelCasedPropertiesDeeply; }; type ToCamelCasedPropertiesDeeplyTuple = T extends any[] ? _ToCamelCasedPropertiesDeeplyTuple : Readonly<_ToCamelCasedPropertiesDeeplyTuple>; type _ToCamelCasedPropertiesDeeplyTuple = T extends readonly [infer H, ...infer L] ? [ToCamelCasedPropertiesDeeply, ..._ToCamelCasedPropertiesDeeplyTuple] : T extends readonly [...infer L, infer H] ? [..._ToCamelCasedPropertiesDeeplyTuple, ToCamelCasedPropertiesDeeply] : T extends readonly [] ? [] : T[number][] extends T ? ToCamelCasedPropertiesDeeply[] : T extends readonly [(infer H)?, ...infer L] ? [ToCamelCasedPropertiesDeeply?, ..._ToCamelCasedPropertiesDeeplyTuple] : never; /** * Converts all property names in a given object to camel case. * This function is recursively applied to objects nested within objects and arrays. * * @example * toCamelCasedPropertiesDeeply({ first_name: 'John', last_name: 'Smith' }) returns { firstName: 'John', lastName: 'Smith' } * toCamelCasedPropertiesDeeply({ nested: { first_name: 'John' } }) returns { nested: { firstName: 'John' } } * toCamelCasedPropertiesDeeply({ tags: [{ created_at: 1 }] }) returns { tags: [{ createdAt: 1 }] } * toCamelCasedPropertiesDeeply([{ first_name: 'John' }]) returns [{ firstName: 'John' }] * toCamelCasedPropertiesDeeply(undefined) returns undefined * toCamelCasedPropertiesDeeply('kebab-case-text') returns 'kebab-case-text' */ declare function toCamelCasedPropertiesDeeply(self: T): ToCamelCasedPropertiesDeeply; declare const all_allKeysOf: typeof allKeysOf; declare const all_assert: typeof assert; declare const all_assertEqual: typeof assertEqual; declare const all_assertInstanceOf: typeof assertInstanceOf; declare const all_assertNeverType: typeof assertNeverType; declare const all_assertTypeEquality: typeof assertTypeEquality; declare const all_call: typeof call; declare const all_capitalize: typeof capitalize; declare const all_cartesianProductOf: typeof cartesianProductOf; declare const all_chunk: typeof chunk; declare const all_clamp: typeof clamp; declare const all_createComparatorFromIsAtMost: typeof createComparatorFromIsAtMost; declare const all_createComparatorFromIsLessThan: typeof createComparatorFromIsLessThan; declare const all_createNGrams: typeof createNGrams; declare const all_curry: typeof curry; declare const all_differenceOf: typeof differenceOf; declare const all_drop: typeof drop; declare const all_dropLast: typeof dropLast; declare const all_elementAt: typeof elementAt; declare const all_equals: typeof equals; declare const all_every: typeof every; declare const all_everyIterable: typeof everyIterable; declare const all_factorialOf: typeof factorialOf; declare const all_filter: typeof filter; declare const all_firstOf: typeof firstOf; declare const all_flatMap: typeof flatMap; declare const all_flatten: typeof flatten; declare const all_forever: typeof forever; declare const all_fromEntries: typeof fromEntries; declare const all_getNestedProperty: typeof getNestedProperty; declare const all_getNextSequentialNumber: typeof getNextSequentialNumber; declare const all_groupBy: typeof groupBy; declare const all_has: typeof has; declare const all_identity: typeof identity; declare const all_includes: typeof includes; declare const all_indexOf: typeof indexOf; declare const all_indexesOf: typeof indexesOf; declare const all_insertAt: typeof insertAt; declare const all_intersectionOf: typeof intersectionOf; declare const all_isBigint: typeof isBigint; declare const all_isBoolean: typeof isBoolean; declare const all_isDisjoint: typeof isDisjoint; declare const all_isEmpty: typeof isEmpty; declare const all_isFalsy: typeof isFalsy; declare const all_isFixedLengthArray: typeof isFixedLengthArray; declare const all_isFunction: typeof isFunction; declare const all_isInIntegerRangeThrough: typeof isInIntegerRangeThrough; declare const all_isInIntegerRangeUntil: typeof isInIntegerRangeUntil; declare const all_isInstanceOf: typeof isInstanceOf; declare const all_isLexicographicAtMost: typeof isLexicographicAtMost; declare const all_isLexicographicLessThan: typeof isLexicographicLessThan; declare const all_isLowercaseLetter: typeof isLowercaseLetter; declare const all_isMaxLengthArray: typeof isMaxLengthArray; declare const all_isMinLengthArray: typeof isMinLengthArray; declare const all_isNotBigint: typeof isNotBigint; declare const all_isNotBoolean: typeof isNotBoolean; declare const all_isNotEmpty: typeof isNotEmpty; declare const all_isNotFunction: typeof isNotFunction; declare const all_isNotInstanceOf: typeof isNotInstanceOf; declare const all_isNotNull: typeof isNotNull; declare const all_isNotNullish: typeof isNotNullish; declare const all_isNotNumber: typeof isNotNumber; declare const all_isNotObject: typeof isNotObject; declare const all_isNotOneOf: typeof isNotOneOf; declare const all_isNotString: typeof isNotString; declare const all_isNotSymbol: typeof isNotSymbol; declare const all_isNotUndefined: typeof isNotUndefined; declare const all_isNull: typeof isNull; declare const all_isNullish: typeof isNullish; declare const all_isNumber: typeof isNumber; declare const all_isObject: typeof isObject; declare const all_isOneOf: typeof isOneOf; declare const all_isString: typeof isString; declare const all_isSubsetOf: typeof isSubsetOf; declare const all_isSymbol: typeof isSymbol; declare const all_isTruthy: typeof isTruthy; declare const all_isUndefined: typeof isUndefined; declare const all_isUnique: typeof isUnique; declare const all_isUppercaseLetter: typeof isUppercaseLetter; declare const all_join: typeof join; declare const all_lastIndexOf: typeof lastIndexOf; declare const all_lastOf: typeof lastOf; declare const all_map: typeof map; declare const all_mapOf: typeof mapOf; declare const all_maxBy: typeof maxBy; declare const all_maxOf: typeof maxOf; declare const all_merge: typeof merge; declare const all_minBy: typeof minBy; declare const all_minOf: typeof minOf; declare const all_modOf: typeof modOf; declare const all_modeBy: typeof modeBy; declare const all_modeOf: typeof modeOf; declare const all_moveTo: typeof moveTo; declare const all_omit: typeof omit; declare const all_padEnd: typeof padEnd; declare const all_padStart: typeof padStart; declare const all_partition: typeof partition; declare const all_permutationOf: typeof permutationOf; declare const all_pipe: typeof pipe; declare const all_prefixesOf: typeof prefixesOf; declare const all_push: typeof push; declare const all_randomIntegerThrough: typeof randomIntegerThrough; declare const all_randomIntegerUntil: typeof randomIntegerUntil; declare const all_remove: typeof remove; declare const all_removeAll: typeof removeAll; declare const all_removeAt: typeof removeAt; declare const all_removeDuplicates: typeof removeDuplicates; declare const all_removeDuplicatesBy: typeof removeDuplicatesBy; declare const all_removePrefix: typeof removePrefix; declare const all_removeSuffix: typeof removeSuffix; declare const all_repeat: typeof repeat; declare const all_repeatApply: typeof repeatApply; declare const all_reverse: typeof reverse; declare const all_sequentialNumbersThrough: typeof sequentialNumbersThrough; declare const all_sequentialNumbersUntil: typeof sequentialNumbersUntil; declare const all_setMembership: typeof setMembership; declare const all_setOf: typeof setOf; declare const all_shuffle: typeof shuffle; declare const all_some: typeof some; declare const all_someIterable: typeof someIterable; declare const all_sort: typeof sort; declare const all_sortBy: typeof sortBy; declare const all_split: typeof split; declare const all_splitIntoWords: typeof splitIntoWords; declare const all_sumOf: typeof sumOf; declare const all_take: typeof take; declare const all_takeWhile: typeof takeWhile; declare const all_toCamelCase: typeof toCamelCase; declare const all_toCamelCasedPropertiesDeeply: typeof toCamelCasedPropertiesDeeply; declare const all_toKebabCase: typeof toKebabCase; declare const all_toMultiset: typeof toMultiset; declare const all_toNumber: typeof toNumber; declare const all_toSnakeCase: typeof toSnakeCase; declare const all_toSnakeCasedPropertiesDeeply: typeof toSnakeCasedPropertiesDeeply; declare const all_toString: typeof toString; declare const all_toggleMembership: typeof toggleMembership; declare const all_trim: typeof trim; declare const all_trimEnd: typeof trimEnd; declare const all_trimStart: typeof trimStart; declare const all_unionOf: typeof unionOf; declare const all_uniqueRandomIntegersUntil: typeof uniqueRandomIntegersUntil; declare const all_unshift: typeof unshift; declare const all_zip: typeof zip; declare const all_zipAll: typeof zipAll; declare const all_zipWith: typeof zipWith; declare namespace all { export { all_allKeysOf as allKeysOf, all_assert as assert, all_assertEqual as assertEqual, all_assertInstanceOf as assertInstanceOf, all_assertNeverType as assertNeverType, all_assertTypeEquality as assertTypeEquality, all_call as call, all_capitalize as capitalize, all_cartesianProductOf as cartesianProductOf, all_chunk as chunk, all_clamp as clamp, all_createComparatorFromIsAtMost as createComparatorFromIsAtMost, all_createComparatorFromIsLessThan as createComparatorFromIsLessThan, all_createNGrams as createNGrams, all_curry as curry, all_differenceOf as differenceOf, all_drop as drop, all_dropLast as dropLast, all_elementAt as elementAt, all_equals as equals, all_every as every, all_everyIterable as everyIterable, all_factorialOf as factorialOf, all_filter as filter, all_firstOf as firstOf, all_flatMap as flatMap, all_flatten as flatten, all_forever as forever, all_fromEntries as fromEntries, all_getNestedProperty as getNestedProperty, all_getNextSequentialNumber as getNextSequentialNumber, all_groupBy as groupBy, all_has as has, all_identity as identity, all_includes as includes, all_indexOf as indexOf, all_indexesOf as indexesOf, all_insertAt as insertAt, all_intersectionOf as intersectionOf, all_isBigint as isBigint, all_isBoolean as isBoolean, all_isDisjoint as isDisjoint, all_isEmpty as isEmpty, all_isFalsy as isFalsy, all_isFixedLengthArray as isFixedLengthArray, all_isFunction as isFunction, all_isInIntegerRangeThrough as isInIntegerRangeThrough, all_isInIntegerRangeUntil as isInIntegerRangeUntil, all_isInstanceOf as isInstanceOf, all_isLexicographicAtMost as isLexicographicAtMost, all_isLexicographicLessThan as isLexicographicLessThan, all_isLowercaseLetter as isLowercaseLetter, all_isMaxLengthArray as isMaxLengthArray, all_isMinLengthArray as isMinLengthArray, all_isNotBigint as isNotBigint, all_isNotBoolean as isNotBoolean, all_isNotEmpty as isNotEmpty, all_isNotFunction as isNotFunction, all_isNotInstanceOf as isNotInstanceOf, all_isNotNull as isNotNull, all_isNotNullish as isNotNullish, all_isNotNumber as isNotNumber, all_isNotObject as isNotObject, all_isNotOneOf as isNotOneOf, all_isNotString as isNotString, all_isNotSymbol as isNotSymbol, all_isNotUndefined as isNotUndefined, all_isNull as isNull, all_isNullish as isNullish, all_isNumber as isNumber, all_isObject as isObject, all_isOneOf as isOneOf, all_isString as isString, all_isSubsetOf as isSubsetOf, all_isSymbol as isSymbol, all_isTruthy as isTruthy, all_isUndefined as isUndefined, all_isUnique as isUnique, all_isUppercaseLetter as isUppercaseLetter, all_join as join, all_lastIndexOf as lastIndexOf, all_lastOf as lastOf, all_map as map, all_mapOf as mapOf, all_maxBy as maxBy, all_maxOf as maxOf, all_merge as merge, all_minBy as minBy, all_minOf as minOf, all_modOf as modOf, all_modeBy as modeBy, all_modeOf as modeOf, all_moveTo as moveTo, all_omit as omit, all_padEnd as padEnd, all_padStart as padStart, all_partition as partition, all_permutationOf as permutationOf, all_pipe as pipe, all_prefixesOf as prefixesOf, all_push as push, all_randomIntegerThrough as randomIntegerThrough, all_randomIntegerUntil as randomIntegerUntil, all_remove as remove, all_removeAll as removeAll, all_removeAt as removeAt, all_removeDuplicates as removeDuplicates, all_removeDuplicatesBy as removeDuplicatesBy, all_removePrefix as removePrefix, all_removeSuffix as removeSuffix, all_repeat as repeat, all_repeatApply as repeatApply, all_reverse as reverse, all_sequentialNumbersThrough as sequentialNumbersThrough, all_sequentialNumbersUntil as sequentialNumbersUntil, all_setMembership as setMembership, all_setOf as setOf, all_shuffle as shuffle, all_some as some, all_someIterable as someIterable, all_sort as sort, all_sortBy as sortBy, all_split as split, all_splitIntoWords as splitIntoWords, all_sumOf as sumOf, all_take as take, all_takeWhile as takeWhile, all_toCamelCase as toCamelCase, all_toCamelCasedPropertiesDeeply as toCamelCasedPropertiesDeeply, all_toKebabCase as toKebabCase, all_toMultiset as toMultiset, all_toNumber as toNumber, all_toSnakeCase as toSnakeCase, all_toSnakeCasedPropertiesDeeply as toSnakeCasedPropertiesDeeply, all_toString as toString, all_toggleMembership as toggleMembership, all_trim as trim, all_trimEnd as trimEnd, all_trimStart as trimStart, all_unionOf as unionOf, all_uniqueRandomIntegersUntil as uniqueRandomIntegersUntil, all_unshift as unshift, all_zip as zip, all_zipAll as zipAll, all_zipWith as zipWith }; } export { all as _, allKeysOf, assert, assertEqual, assertInstanceOf, assertNeverType, assertTypeEquality, call, capitalize, cartesianProductOf, chunk, clamp, createComparatorFromIsAtMost, createComparatorFromIsLessThan, createNGrams, curry, differenceOf, drop, dropLast, elementAt, equals, every, everyIterable, factorialOf, filter, firstOf, flatMap, flatten, forever, fromEntries, getNestedProperty, getNextSequentialNumber, groupBy, has, identity, includes, indexOf, indexesOf, insertAt, intersectionOf, isBigint, isBoolean, isDisjoint, isEmpty, isFalsy, isFixedLengthArray, isFunction, isInIntegerRangeThrough, isInIntegerRangeUntil, isInstanceOf, isLexicographicAtMost, isLexicographicLessThan, isLowercaseLetter, isMaxLengthArray, isMinLengthArray, isNotBigint, isNotBoolean, isNotEmpty, isNotFunction, isNotInstanceOf, isNotNull, isNotNullish, isNotNumber, isNotObject, isNotOneOf, isNotString, isNotSymbol, isNotUndefined, isNull, isNullish, isNumber, isObject, isOneOf, isString, isSubsetOf, isSymbol, isTruthy, isUndefined, isUnique, isUppercaseLetter, join, lastIndexOf, lastOf, map, mapOf, maxBy, maxOf, merge, minBy, minOf, modOf, modeBy, modeOf, moveTo, omit, padEnd, padStart, partition, permutationOf, pipe, prefixesOf, push, randomIntegerThrough, randomIntegerUntil, remove, removeAll, removeAt, removeDuplicates, removeDuplicatesBy, removePrefix, removeSuffix, repeat, repeatApply, reverse, sequentialNumbersThrough, sequentialNumbersUntil, setMembership, setOf, shuffle, some, someIterable, sort, sortBy, split, splitIntoWords, sumOf, take, takeWhile, toCamelCase, toCamelCasedPropertiesDeeply, toKebabCase, toMultiset, toNumber, toSnakeCase, toSnakeCasedPropertiesDeeply, toString, toggleMembership, trim, trimEnd, trimStart, unionOf, uniqueRandomIntegersUntil, unshift, zip, zipAll, zipWith };