declare global { interface SymbolConstructor { readonly observable: symbol; } } type UpperCaseCharacters = '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 WordSeparators = '-' | '_' | ' '; /** Represents an array of strings split using a given character or character set. Use-case: Defining the return type of a method like `String.prototype.split`. @example ``` import {Split} from 'type-fest'; declare function split(string: S, separator: D): Split; type Item = 'foo' | 'bar' | 'baz' | 'waldo'; const items = 'foo,bar,baz,waldo'; let array: Item[]; array = split(items, ','); ``` @category Template Literals */ type Split< S extends string, Delimiter extends string, > = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split] : S extends Delimiter ? [] : [S]; /** Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder. Only to be used by `CamelCaseStringArray<>`. @see CamelCaseStringArray */ type InnerCamelCaseStringArray = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] ? FirstPart extends undefined ? '' : FirstPart extends '' ? InnerCamelCaseStringArray : `${PreviousPart extends '' ? FirstPart : Capitalize}${InnerCamelCaseStringArray}` : ''; /** Starts fusing the output of `Split<>`, an array literal of strings, into a camel-cased string literal. It's separate from `InnerCamelCaseStringArray<>` to keep a clean API outwards to the rest of the code. @see Split */ type CamelCaseStringArray = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] ? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray}`> : never; /** Convert a string literal to camel-case. This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result. @example ``` import {CamelCase} from 'type-fest'; // Simple const someVariable: CamelCase<'foo-bar'> = 'fooBar'; // Advanced type CamelCasedProperties = { [K in keyof T as CamelCase]: T[K] }; interface RawOptions { 'dry-run': boolean; 'full_family_name': string; foo: number; BAR: string; QUZ_QUX: number; 'OTHER-FIELD': boolean; } const dbResult: CamelCasedProperties = { dryRun: true, fullFamilyName: 'bar.js', foo: 123, bar: 'foo', quzQux: 6, otherField: false }; ``` @category Template Literals */ type CamelCase = K extends string ? CamelCaseStringArray ? Lowercase : K, WordSeparators>> : K; /** Convert object properties to camel case recursively. This can be useful when, for example, converting some API types from a different style. @see CamelCasedProperties @see CamelCase @example ``` interface User { UserId: number; UserName: string; } interface UserWithFriends { UserInfo: User; UserFriends: User[]; } const result: CamelCasedPropertiesDeep = { userInfo: { userId: 1, userName: 'Tom', }, userFriends: [ { userId: 2, userName: 'Jerry', }, { userId: 3, userName: 'Spike', }, ], }; ``` @category Template Literals */ type CamelCasedPropertiesDeep = Value extends Function ? Value : Value extends Array ? Array> : Value extends Set ? Set> : { [K in keyof Value as CamelCase]: CamelCasedPropertiesDeep; }; /** Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters. @category Template Literals */ type SplitIncludingDelimiters = Source extends '' ? [] : Source extends `${infer FirstPart}${Delimiter}${infer SecondPart}` ? ( Source extends `${FirstPart}${infer UsedDelimiter}${SecondPart}` ? UsedDelimiter extends Delimiter ? Source extends `${infer FirstPart}${UsedDelimiter}${infer SecondPart}` ? [...SplitIncludingDelimiters, UsedDelimiter, ...SplitIncludingDelimiters] : never : never : never ) : [Source]; /** Format a specific part of the splitted string literal that `StringArrayToDelimiterCase<>` fuses together, ensuring desired casing. @see StringArrayToDelimiterCase */ type StringPartToDelimiterCase = StringPart extends UsedWordSeparators ? Delimiter : Start extends true ? Lowercase : StringPart extends UsedUpperCaseCharacters ? `${Delimiter}${Lowercase}` : StringPart; /** Takes the result of a splitted string literal and recursively concatenates it together into the desired casing. It receives `UsedWordSeparators` and `UsedUpperCaseCharacters` as input to ensure it's fully encapsulated. @see SplitIncludingDelimiters */ type StringArrayToDelimiterCase = Parts extends [`${infer FirstPart}`, ...infer RemainingParts] ? `${StringPartToDelimiterCase}${StringArrayToDelimiterCase}` : ''; /** Convert a string literal to a custom string delimiter casing. This can be useful when, for example, converting a camel-cased object property to an oddly cased one. @see KebabCase @see SnakeCase @example ``` import {DelimiterCase} from 'type-fest'; // Simple const someVariable: DelimiterCase<'fooBar', '#'> = 'foo#bar'; // Advanced type OddlyCasedProperties = { [K in keyof T as DelimiterCase]: T[K] }; interface SomeOptions { dryRun: boolean; includeFile: string; foo: number; } const rawCliOptions: OddlyCasedProperties = { 'dry#run': true, 'include#file': 'bar.js', foo: 123 }; ``` @category Template Literals */ type DelimiterCase = Value extends string ? StringArrayToDelimiterCase< SplitIncludingDelimiters, true, WordSeparators, UpperCaseCharacters, Delimiter > : Value; /** Convert object properties to delimiter case recursively. This can be useful when, for example, converting some API types from a different style. @see DelimiterCase @see DelimiterCasedProperties @example ``` interface User { userId: number; userName: string; } interface UserWithFriends { userInfo: User; userFriends: User[]; } const result: DelimiterCasedPropertiesDeep = { 'user-info': { 'user-id': 1, 'user-name': 'Tom', }, 'user-friends': [ { 'user-id': 2, 'user-name': 'Jerry', }, { 'user-id': 3, 'user-name': 'Spike', }, ], }; ``` @category Template Literals */ type DelimiterCasedPropertiesDeep< Value, Delimiter extends string, > = Value extends Function ? Value : Value extends Array ? Array> : Value extends Set ? Set> : { [K in keyof Value as DelimiterCase< K, Delimiter >]: DelimiterCasedPropertiesDeep; }; /** Convert a string literal to snake-case. This can be useful when, for example, converting a camel-cased object property to a snake-cased SQL column name. @example ``` import {SnakeCase} from 'type-fest'; // Simple const someVariable: SnakeCase<'fooBar'> = 'foo_bar'; // Advanced type SnakeCasedProperties = { [K in keyof T as SnakeCase]: T[K] }; interface ModelProps { isHappy: boolean; fullFamilyName: string; foo: number; } const dbResult: SnakeCasedProperties = { 'is_happy': true, 'full_family_name': 'Carla Smith', foo: 123 }; ``` @category Template Literals */ type SnakeCase = DelimiterCase; /** Convert object properties to snake case recursively. This can be useful when, for example, converting some API types from a different style. @see SnakeCase @see SnakeCasedProperties @example ``` interface User { userId: number; userName: string; } interface UserWithFriends { userInfo: User; userFriends: User[]; } const result: SnakeCasedPropertiesDeep = { user_info: { user_id: 1, user_name: 'Tom', }, user_friends: [ { user_id: 2, user_name: 'Jerry', }, { user_id: 3, user_name: 'Spike', }, ], }; ``` @category Template Literals */ type SnakeCasedPropertiesDeep = DelimiterCasedPropertiesDeep; /** Return a default type if input type is nil. @template T - Input type. @template U - Default type. */ declare type WithDefault = T extends undefined | null ? U : T; declare type EmptyTuple = []; /** Append a segment to dot-notation path. */ declare type AppendPath = S extends '' ? Last : `${S}.${Last}`; /** Check if an element is included in a tuple. @template List - List of values. @template Target - Target to search. */ declare type Includes = List extends undefined ? false : List extends Readonly ? false : List extends readonly [infer First, ...infer Rest] ? First extends Target ? true : Includes : boolean; /** Convert keys of an object to camelcase strings. */ interface CamelCaseOptions { /** Recurse nested objects and objects in arrays. @default false */ readonly deep?: boolean; /** Exclude keys from being camel-cased. If this option can be statically determined, it's recommended to add `as const` to it. @default [] */ readonly exclude?: ReadonlyArray; } declare type CamelCaseKeys | readonly any[], Deep extends boolean, Exclude extends readonly unknown[], Path extends string = ''> = T extends readonly any[] ? { [P in keyof T]: CamelCaseKeys; } : T extends Record ? { [P in keyof T & string as [Includes] extends [true] ? P : CamelCase

]: [Deep] extends [true] ? T[P] extends Record ? CamelCaseKeys> : T[P] : T[P]; } : T; declare type CamelCaseKeysWithOptions | readonly any[], Options extends CamelCaseOptions = CamelCaseOptions> = CamelCaseKeys, WithDefault>; declare type SnakeCaseKeys | readonly any[], Deep extends boolean, Exclude extends readonly unknown[], Path extends string = ''> = T extends readonly any[] ? { [P in keyof T]: SnakeCaseKeys; } : T extends Record ? { [P in keyof T & string as [Includes] extends [true] ? P : SnakeCase

]: [Deep] extends [true] ? T[P] extends Record ? SnakeCaseKeys> : T[P] : T[P]; } : T; interface SnakeCaseOptions { /** Recurse nested objects and objects in arrays. @default true */ readonly deep?: boolean; /** Exclude keys from being snakeCased. @default [] */ readonly exclude?: ReadonlyArray; } declare type SnakeCaseWithOptions | readonly any[], Options extends SnakeCaseOptions> = SnakeCaseKeys, WithDefault>; declare type SnakeCasedDeep = SnakeCasedPropertiesDeep; declare type CamelCasedDeep = CamelCasedPropertiesDeep; declare function camelcaseKeys | readonly any[], Options extends CamelCaseOptions = CamelCaseOptions>(input: T, options?: Options): CamelCaseKeysWithOptions; declare function snakecaseKeys | readonly any[], Options extends SnakeCaseOptions = SnakeCaseOptions>(input: T, options?: Options): SnakeCaseWithOptions; export { AppendPath, CamelCaseKeysWithOptions, CamelCaseOptions, CamelCasedDeep, EmptyTuple, SnakeCaseOptions, SnakeCaseWithOptions, SnakeCasedDeep, WithDefault, camelcaseKeys, snakecaseKeys };