diff --git a/index.d.ts b/index.d.ts index f4ee3c3..e1d7199 100644 --- a/index.d.ts +++ b/index.d.ts @@ -43,23 +43,25 @@ export type CamelCaseKeys< StopPaths extends readonly string[] = EmptyTuple, Path extends string = '', > = T extends readonly any[] - // Handle arrays or tuples. +// Handle arrays or tuples. ? { + [P in keyof T]: T[P] extends Record | readonly any[] // eslint-disable-next-line @typescript-eslint/ban-types - [P in keyof T]: {} extends CamelCaseKeys - ? T[P] - : CamelCaseKeys< - T[P], - Deep, - IsPascalCase, - Exclude, - StopPaths - >; + ? {} extends CamelCaseKeys + ? T[P] + : CamelCaseKeys< + T[P], + Deep, + IsPascalCase, + Exclude, + StopPaths + > + : T[P]; } : T extends Record - // Handle objects. + // Handle objects. ? { - [P in keyof T as [IsInclude] extends [true] + [P in keyof T as[IsInclude] extends [true] ? P : [IsPascalCase] extends [true] ? PascalCase

@@ -67,7 +69,7 @@ export type CamelCaseKeys< true, ] ? T[P] - // eslint-disable-next-line @typescript-eslint/ban-types + // eslint-disable-next-line @typescript-eslint/ban-types : {} extends CamelCaseKeys ? T[P] : [Deep] extends [true] @@ -81,69 +83,69 @@ export type CamelCaseKeys< > : T[P]; } - // Return anything else as-is. + // Return anything else as-is. : T; type Options = { /** - Recurse nested objects and objects in arrays. + Recurse nested objects and objects in arrays. - @default false - */ + @default false + */ readonly deep?: boolean; /** - Exclude keys from being camel-cased. + Exclude keys from being camel-cased. - If this option can be statically determined, it's recommended to add `as const` to it. + If this option can be statically determined, it's recommended to add `as const` to it. - @default [] - */ + @default [] + */ readonly exclude?: ReadonlyArray; /** - Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`. - - If this option can be statically determined, it's recommended to add `as const` to it. - - @default [] - - @example - ``` - import camelcaseKeys from 'camelcase-keys'; - - camelcaseKeys({ - a_b: 1, - a_c: { - c_d: 1, - c_e: { - e_f: 1 - } - } - }, { - deep: true, - stopPaths: [ - 'a_c.c_e' - ] - }), - // { - // aB: 1, - // aC: { - // cD: 1, - // cE: { - // e_f: 1 - // } - // } - // } - ``` - */ + Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`. + + If this option can be statically determined, it's recommended to add `as const` to it. + + @default [] + + @example + ``` + import camelcaseKeys from 'camelcase-keys'; + + camelcaseKeys({ + a_b: 1, + a_c: { + c_d: 1, + c_e: { + e_f: 1 + } + } + }, { + deep: true, + stopPaths: [ + 'a_c.c_e' + ] + }), + // { + // aB: 1, + // aC: { + // cD: 1, + // cE: { + // e_f: 1 + // } + // } + // } + ``` + */ readonly stopPaths?: readonly string[]; /** - Uppercase the first character as in `bye-bye` → `ByeBye`. + Uppercase the first character as in `bye-bye` → `ByeBye`. - @default false - */ + @default false + */ readonly pascalCase?: boolean; };