import type { CutFirst, EmptyTuple } from "./array"; import type { SubstractCount, ToCount } from "./number"; export type ExtractKey = K; export type EmptyString = ""; export type Underline = "_"; export type Hyphen = "-"; export type LowerCases = | "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"; export type UpperCases = | "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"; export type Chars = LowerCases | UpperCases; export type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"; export type Odds = "1" | "3" | "5" | "7" | "9"; export type Evens = "0" | "2" | "4" | "6" | "8"; export type Binary = "0" | "1"; export type SelectKey = K; export type TakeFirst = Str extends `${infer First}${string}` ? First : EmptyString; export type TakeRest = Str extends `${string}${infer Rest}` ? Rest : EmptyString; export type TakeLast = ListChar extends readonly [ ...string[], infer Last ] ? Last : EmptyString; export type ListChar = Str extends EmptyString ? [] : [TakeFirst, ...ListChar>]; export type Join< Arr extends readonly string[], Delimiter extends string = EmptyString > = Arr extends EmptyTuple ? EmptyString : Arr extends readonly [infer T] ? T extends string ? T : never : `${Arr[0]}${Delimiter}${Join, Delimiter>}`; export type Split< Str extends string, Splitter extends string > = Str extends `${infer Head}${Splitter}${infer Tail}` ? [Head, ...Split] : [Str]; type TitleMapFn< Result extends readonly string[], Arr extends readonly string[] > = Arr extends readonly [string, ...infer Rest] ? Rest extends readonly string[] ? TitleMapFn<[...Result, Capitalize], Rest> : never : [Result, []]; type TitleMap = TitleMapFn<[], Arr>[0]; export type PascalCase = Join< TitleMap> >; type _Expecting = Buffer extends EmptyTuple ? Chars | Digit : Buffer[0] extends Chars ? LowerCases : Buffer[0] extends Digit ? Digit : never; type SplitFn< Result extends readonly string[], Buffer extends readonly string[], Source extends string > = Source extends EmptyString ? Chars | Digit extends _Expecting // Buffer is Empty ? Result : [...Result, Join] : TakeFirst extends Chars | Digit ? TakeFirst extends _Expecting ? SplitFn], TakeRest> : SplitFn<[...Result, Join], [], Source> : Chars | Digit extends _Expecting // Buffer is Empty ? SplitFn> : SplitFn<[...Result, Join], [], TakeRest>; export type WordSplit = SplitFn<[], [], Str>; export type SnakeCase = Lowercase< Join, Underline> >; export type SmallCamelCase = `${Lowercase< TakeFirst >}${TakeRest>} >`; export type CamelCase = SmallCamelCase; export type KebabCase = Lowercase< Join, Hyphen> >; export type TemplateAllowedTypes = | bigint | boolean | number | string | null | undefined; export type StringLength = ListChar["length"]; export type Repeat = Join< Extract, Str>, readonly string[]>, "" >; export type MapTupleToStrings< T extends readonly unknown[], Str extends string > = { [K in keyof T]: Str; }; export type PadStart< Src extends string, Length extends number, Fill extends string = " " > = StringLength extends 1 ? `${Repeat< Fill, SubstractCount, ToCount<`${StringLength}`>> >}${Src}` : string; export type PadEnd< Src extends string, Length extends number, Fill extends string = " " > = StringLength extends 1 ? `${Src}${Repeat< Fill, SubstractCount, ToCount<`${StringLength}`>> >}` : string;