UNPKG

bananas-commerce

Version:

A client for bananas-commerce with support for TypeScript

41 lines (40 loc) 1.65 kB
import { CasedString, CaseType } from "./casedString.js"; /** * Converts the property keys of an object to a {@link CaseType}. * * @param object - The object to convert the casing of. * @param casing - The {@link CaseType}, e.g. `snake` or `camel`. */ export type ObjectGeneralCaserFunction = <O, T extends CaseType>(object: O, casing: T) => CasedObjectKeys<O, T>; /** * Converts an object to a {@link CaseType}. * * @param object - The object to convert the casing of. */ export type ObjectCaserFunction<T extends CaseType> = <O>(object: O) => CasedObjectKeys<O, T>; export type ObjectCaser = ObjectGeneralCaserFunction & { [T in CaseType]: ObjectCaserFunction<T>; }; /** * Converts the property keys of an object to a {@link CaseType}. * * @typeparam `O` - The string to convert the casing of. * @typeparam `T` - The {@link CaseType}, e.g. `snake` or `camel`. */ export type CasedObjectKeys<O, T extends CaseType> = O extends object ? O extends (infer E)[] ? CasedObjectKeys<E, T>[] : { [K in keyof O as CasedString<Extract<K, string>, T>]: CasedObjectKeys<O[K], T>; } : O; /** * Converts the property keys of an object to camelCase. * * @typeparam `O` - The string to convert the casing of. */ export type CamelCasedObjectKeys<O> = CasedObjectKeys<O, "camel">; /** * Converts the property keys of an object to snake_case. * * @typeparam `O` - The string to convert the casing of. */ export type SnakeCasedObjectKeys<O> = CasedObjectKeys<O, "snake">; /** Converts the keys (or deeply nested keys) of an {@link object} to the specified {@link casing}. */ export declare const casedObjectKeys: ObjectGeneralCaserFunction;