/** * This module contains functions and types to change the cases of object keys * * @module */ import type { CaseName } from "./cases.js"; import { type ChangeStringCase } from "./string.js"; import { type DetectCaseNameFromArray } from "./array.js"; import { type DeepKeyOf, type UnionToTuple, type Writeable } from "./utils.js"; /** Attempts to identify the shared CaseName of the keys of an object type and return a CaseName. Returns 'undefined' if more than one CaseName is identified, except if one of them is a non-delimited case (upper or lower) and the only other one is not. * * @example * ```typescript * const case: DetectCaseNameFromKeys<{ fooBar: 0, baz: 0 }> = "camelCase"; * ``` */ export type DetectCaseNameFromKeys = DetectCaseNameFromArray>>; /** Attempts to identify the shared CaseName of the keys of a given object and return a CaseName. Returns 'undefined' if more than one CaseName is identified, except if one of them is a non-delimited case (upper or lower) and the only other one is not. * * @example * ```typescript * detectCaseNameFromKeys({ fooBar: 0, baz: 0 }) satisfies "camelCase"; * ``` */ export declare function detectCaseNameFromKeys(object: Object): DetectCaseNameFromKeys; /** Deeply changes the keys (property names) of records within an object type (including arrays and tuples) */ export type ChangeKeysCase = Object extends unknown[] ? BuildArray : Object extends Record ? BuildObject : Object; type BuildItem = Item extends object ? ChangeKeysCase : Item, ToCase, FromCase> : Item; type BuildObject, ToCase extends CaseName, FromCase extends CaseName, Keys extends unknown[] = UnionToTuple, Acc = unknown> = Keys extends [ infer Head extends PropertyKey, ...infer Tail extends unknown[] ] ? BuildObject : Head) | keyof Acc]: Key extends keyof Acc ? Acc[Key] : BuildItem; }> : Acc; type BuildArray = number extends SourceArray["length"] ? (BuildItem)[] : BuildTuple; type BuildTuple = SourceTuple extends [infer Head, ...infer Tail extends unknown[]] ? BuildTuple ]> : Acc; /** Returns a function translating the keys within an object. The current case will be auto-detected if possible. */ export declare function keysCaseChanger(toCase: ToCase): (object: Object) => DetectCaseNameFromKeys extends infer FromCase extends CaseName ? ChangeKeysCase : Object; /** Returns a function translating the keys within an object from one provided case to another */ export declare function keysCaseChanger(toCase: ToCase, fromCase: FromCase): (object: Object) => ChangeKeysCase; /** Translates the keys within an object. The current case will be auto-detected if possible. */ export declare function changeKeysCase(object: Object, toCase: ToCase): DetectCaseNameFromKeys extends infer FromCase extends CaseName ? ChangeKeysCase : Object; /** Translates the keys within an object from one provided case to another */ export declare function changeKeysCase(object: Object, toCase: ToCase, fromCase: FromCase): ChangeKeysCase; export {}; //# sourceMappingURL=object.d.ts.map