export type Equal = (() => T extends a ? 1 : 2) extends () => T extends b ? 1 : 2 ? true : false; /** * HACK: * Special function for never because `Equal` doesn't * work when called deep in the call stack (for a reason I don't understand * probably a TS bug). */ export type IsNever = [T] extends [never] ? true : false; export type Expect = a; export type Some = true extends bools[number] ? true : false; export type Every = bools[number] extends true ? true : false; export type Extends = [a] extends [b] ? true : false; export type Not = a extends true ? false : true; /** * trick to combine multiple unions of objects into a single object * only works with objects not primitives * @param union - Union of objects * @returns Intersection of objects */ export type UnionToIntersection = (union extends any ? (k: union) => void : never) extends (k: infer intersection) => void ? intersection : never; export type Prettify = { [K in keyof T]: T[K]; } | never; export type RecursivePrettify = IsArrayStrict extends true ? RecursivePrettify[number]>[] : { [K in keyof T]: RecursivePrettify; }; export type AnyTuple = readonly [any, ...any]; export declare namespace Iterator { type Get = it["length"]; type Iterator = it["length"] extends n ? it : Iterator; type Next = [any, ...it]; type Prev = it extends readonly [any, ...infer tail] ? tail : []; } 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"; type KebabToCamel = str extends `${infer first}-${infer rest}` ? `${first}${KebabToCamel>}` : str; type SnakeToCamel = str extends `${infer first}_${infer rest}` ? `${first}${SnakeToCamel>}` : str; /** * Converts string casing from snake_case or kebab-case to camelCase. */ export type CamelCase = KebabToCamel>; /** * Converts string casing from camelCase or kebab-case to snake_case. */ export type SnakeCase = str extends `${infer first}${infer rest}` ? first extends UppercaseLetter ? output extends "" ? SnakeCase> : SnakeCase}`> : first extends "-" ? SnakeCase : SnakeCase : output extends "" ? str : output; /** * Converts string casing from camelCase or snake_case to kebab-case. */ export type KebabCase = str extends `${infer first}${infer rest}` ? first extends UppercaseLetter ? output extends "" ? KebabCase> : KebabCase}`> : first extends "_" ? KebabCase : KebabCase : output extends "" ? str : output; export type IsTuple = a extends readonly [] | readonly [any, ...any] | readonly [...any, any] ? true : false; export type IsArrayStrict = a extends readonly any[] ? Not> : false; /** * get last element of union * @param Union - Union of any types * @returns Last element of union */ type GetUnionLast = UnionToIntersection Union : never> extends () => infer Last ? Last : never; /** * Convert union to tuple * @param Union - Union of any types, can be union of complex, composed or primitive types * @returns Tuple of each elements in the union */ export type UnionToTuple = [ Union ] extends [never] ? Tuple : UnionToTuple>, [ GetUnionLast, ...Tuple ]>; /** * Split string into a tuple, using a simple string literal separator * @description - This is a simple implementation of split, it does not support multiple separators * A more complete implementation is built on top of this one * @param Str - String to split * @param Sep - Separator, must be a string literal not a union of string literals * @returns Tuple of strings */ export type Split = Str extends "" ? Acc : Str extends `${infer T}${Sep}${infer U}` ? Split : [...Acc, Str]; export type Stringifiable = string | number | boolean | bigint | null | undefined; export type Primitive = string | number | boolean | bigint | null | undefined | symbol; export type Head = xs extends [infer first, ...any] ? first : never; export {};