es-toolkit 1.50.0-dev.2053 → 1.50.0-dev.2055
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internal/NonPlainObject.d.mts +8 -0
- package/dist/_internal/NonPlainObject.d.ts +8 -0
- package/dist/object/toCamelCaseKeys.d.mts +2 -6
- package/dist/object/toCamelCaseKeys.d.ts +2 -6
- package/dist/object/toConstantCaseKeys.d.mts +2 -3
- package/dist/object/toConstantCaseKeys.d.ts +2 -3
- package/dist/object/toKebabCaseKeys.d.mts +2 -5
- package/dist/object/toKebabCaseKeys.d.ts +2 -5
- package/dist/object/toPascalCaseKeys.d.mts +2 -6
- package/dist/object/toPascalCaseKeys.d.ts +2 -6
- package/dist/object/toSnakeCaseKeys.d.mts +2 -3
- package/dist/object/toSnakeCaseKeys.d.ts +2 -3
- package/dist/types/ToCamelCaseKeys.d.mts +24 -0
- package/dist/types/ToCamelCaseKeys.d.ts +24 -0
- package/dist/types/ToConstantCaseKeys.d.mts +21 -0
- package/dist/types/ToConstantCaseKeys.d.ts +21 -0
- package/dist/types/ToKebabCaseKeys.d.mts +23 -0
- package/dist/types/ToKebabCaseKeys.d.ts +23 -0
- package/dist/types/ToPascalCaseKeys.d.mts +24 -0
- package/dist/types/ToPascalCaseKeys.d.ts +24 -0
- package/dist/types/ToSnakeCaseKeys.d.mts +21 -0
- package/dist/types/ToSnakeCaseKeys.d.ts +21 -0
- package/dist/types/index.d.mts +6 -1
- package/dist/types/index.d.ts +6 -1
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/_internal/NonPlainObject.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Built-in object types that key-conversion types like `ToCamelCaseKeys`
|
|
4
|
+
* leave unchanged instead of mapping over their properties.
|
|
5
|
+
*/
|
|
6
|
+
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { NonPlainObject };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/_internal/NonPlainObject.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Built-in object types that key-conversion types like `ToCamelCaseKeys`
|
|
4
|
+
* leave unchanged instead of mapping over their properties.
|
|
5
|
+
*/
|
|
6
|
+
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { NonPlainObject };
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import { ToCamelCaseKeys } from "../types/ToCamelCaseKeys.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toCamelCaseKeys.d.ts
|
|
2
|
-
type SnakeToCamel<S extends string> = S extends `${infer H}_${infer T}` ? `${Lowercase<H>}${Capitalize<SnakeToCamel<T>>}` : Lowercase<S>;
|
|
3
|
-
type PascalToCamel<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
4
|
-
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase the entire string; otherwise, just lowercase the first letter (including PascalCase → camelCase). */
|
|
5
|
-
type AnyToCamel<S extends string> = S extends `${string}_${string}` ? SnakeToCamel<S> : S extends Uppercase<S> ? Lowercase<S> : PascalToCamel<S>;
|
|
6
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
7
|
-
type ToCamelCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToCamelCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToCamel<Extract<K, string>>]: ToCamelCaseKeys<T[K]> } : T;
|
|
8
4
|
/**
|
|
9
5
|
* Creates a new object composed of the properties with keys converted to camelCase.
|
|
10
6
|
*
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import { ToCamelCaseKeys } from "../types/ToCamelCaseKeys.js";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toCamelCaseKeys.d.ts
|
|
2
|
-
type SnakeToCamel<S extends string> = S extends `${infer H}_${infer T}` ? `${Lowercase<H>}${Capitalize<SnakeToCamel<T>>}` : Lowercase<S>;
|
|
3
|
-
type PascalToCamel<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
4
|
-
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase the entire string; otherwise, just lowercase the first letter (including PascalCase → camelCase). */
|
|
5
|
-
type AnyToCamel<S extends string> = S extends `${string}_${string}` ? SnakeToCamel<S> : S extends Uppercase<S> ? Lowercase<S> : PascalToCamel<S>;
|
|
6
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
7
|
-
type ToCamelCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToCamelCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToCamel<Extract<K, string>>]: ToCamelCaseKeys<T[K]> } : T;
|
|
8
4
|
/**
|
|
9
5
|
* Creates a new object composed of the properties with keys converted to camelCase.
|
|
10
6
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { ToConstantCaseKeys } from "../types/ToConstantCaseKeys.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toConstantCaseKeys.d.ts
|
|
2
|
-
type ConstantCase<S extends string> = S extends Lowercase<S> ? Uppercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Uppercase<P1>}${ConstantCase<P2>}` : `${Uppercase<P1>}_${ConstantCase<Uncapitalize<P2>>}` : Uppercase<S>;
|
|
3
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
4
|
-
type ToConstantCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToConstantCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as ConstantCase<string & K>]: ToConstantCaseKeys<T[K]> } : T;
|
|
5
4
|
/**
|
|
6
5
|
* Creates a new object composed of the properties with keys converted to CONSTANT_CASE.
|
|
7
6
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { ToConstantCaseKeys } from "../types/ToConstantCaseKeys.js";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toConstantCaseKeys.d.ts
|
|
2
|
-
type ConstantCase<S extends string> = S extends Lowercase<S> ? Uppercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Uppercase<P1>}${ConstantCase<P2>}` : `${Uppercase<P1>}_${ConstantCase<Uncapitalize<P2>>}` : Uppercase<S>;
|
|
3
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
4
|
-
type ToConstantCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToConstantCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as ConstantCase<string & K>]: ToConstantCaseKeys<T[K]> } : T;
|
|
5
4
|
/**
|
|
6
5
|
* Creates a new object composed of the properties with keys converted to CONSTANT_CASE.
|
|
7
6
|
*
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { ToKebabCaseKeys } from "../types/ToKebabCaseKeys.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toKebabCaseKeys.d.ts
|
|
2
|
-
type SnakeToKebab<S extends string> = S extends `${infer P1}_${infer P2}` ? Lowercase<`${P1}-${SnakeToKebab<P2>}`> : Lowercase<S>;
|
|
3
|
-
type CamelToKebab<S extends string> = S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${CamelToKebab<P2>}` : `${Lowercase<P1>}-${CamelToKebab<Uncapitalize<P2>>}` : S;
|
|
4
|
-
type KebabCase<S extends string> = S extends `${string}_${string}` ? SnakeToKebab<S> : S extends Uppercase<S> ? Lowercase<S> : CamelToKebab<S>;
|
|
5
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
6
|
-
type ToKebabCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToKebabCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as KebabCase<string & K>]: ToKebabCaseKeys<T[K]> } : T;
|
|
7
4
|
/**
|
|
8
5
|
* Creates a new object composed of the properties with keys converted to kebab-case.
|
|
9
6
|
*
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { ToKebabCaseKeys } from "../types/ToKebabCaseKeys.js";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toKebabCaseKeys.d.ts
|
|
2
|
-
type SnakeToKebab<S extends string> = S extends `${infer P1}_${infer P2}` ? Lowercase<`${P1}-${SnakeToKebab<P2>}`> : Lowercase<S>;
|
|
3
|
-
type CamelToKebab<S extends string> = S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${CamelToKebab<P2>}` : `${Lowercase<P1>}-${CamelToKebab<Uncapitalize<P2>>}` : S;
|
|
4
|
-
type KebabCase<S extends string> = S extends `${string}_${string}` ? SnakeToKebab<S> : S extends Uppercase<S> ? Lowercase<S> : CamelToKebab<S>;
|
|
5
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
6
|
-
type ToKebabCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToKebabCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as KebabCase<string & K>]: ToKebabCaseKeys<T[K]> } : T;
|
|
7
4
|
/**
|
|
8
5
|
* Creates a new object composed of the properties with keys converted to kebab-case.
|
|
9
6
|
*
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import { ToPascalCaseKeys } from "../types/ToPascalCaseKeys.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toPascalCaseKeys.d.ts
|
|
2
|
-
type SnakeToPascal<S extends string> = S extends `${infer H}_${infer T}` ? `${Capitalize<Lowercase<H>>}${Capitalize<SnakeToPascal<T>>}` : Capitalize<Lowercase<S>>;
|
|
3
|
-
type CamelToPascal<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
4
|
-
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase and capitalize the entire string; otherwise, just uppercase the first letter (including camelCase → PascalCase). */
|
|
5
|
-
type AnyToPascal<S extends string> = S extends `${string}_${string}` ? SnakeToPascal<S> : S extends Uppercase<S> ? Capitalize<Lowercase<S>> : CamelToPascal<S>;
|
|
6
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
7
|
-
type ToPascalCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToPascalCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToPascal<Extract<K, string>>]: ToPascalCaseKeys<T[K]> } : T;
|
|
8
4
|
/**
|
|
9
5
|
* Creates a new object composed of the properties with keys converted to PascalCase.
|
|
10
6
|
*
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
+
import { ToPascalCaseKeys } from "../types/ToPascalCaseKeys.js";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toPascalCaseKeys.d.ts
|
|
2
|
-
type SnakeToPascal<S extends string> = S extends `${infer H}_${infer T}` ? `${Capitalize<Lowercase<H>>}${Capitalize<SnakeToPascal<T>>}` : Capitalize<Lowercase<S>>;
|
|
3
|
-
type CamelToPascal<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
4
|
-
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase and capitalize the entire string; otherwise, just uppercase the first letter (including camelCase → PascalCase). */
|
|
5
|
-
type AnyToPascal<S extends string> = S extends `${string}_${string}` ? SnakeToPascal<S> : S extends Uppercase<S> ? Capitalize<Lowercase<S>> : CamelToPascal<S>;
|
|
6
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
7
|
-
type ToPascalCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToPascalCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToPascal<Extract<K, string>>]: ToPascalCaseKeys<T[K]> } : T;
|
|
8
4
|
/**
|
|
9
5
|
* Creates a new object composed of the properties with keys converted to PascalCase.
|
|
10
6
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { ToSnakeCaseKeys } from "../types/ToSnakeCaseKeys.mjs";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toSnakeCaseKeys.d.ts
|
|
2
|
-
type SnakeCase<S extends string> = S extends Uppercase<S> ? Lowercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${SnakeCase<P2>}` : `${Lowercase<P1>}_${SnakeCase<Uncapitalize<P2>>}` : Lowercase<S>;
|
|
3
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
4
|
-
type ToSnakeCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToSnakeCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as SnakeCase<string & K>]: ToSnakeCaseKeys<T[K]> } : T;
|
|
5
4
|
/**
|
|
6
5
|
* Creates a new object composed of the properties with keys converted to snake_case.
|
|
7
6
|
*
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { ToSnakeCaseKeys } from "../types/ToSnakeCaseKeys.js";
|
|
2
|
+
|
|
1
3
|
//#region src/object/toSnakeCaseKeys.d.ts
|
|
2
|
-
type SnakeCase<S extends string> = S extends Uppercase<S> ? Lowercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${SnakeCase<P2>}` : `${Lowercase<P1>}_${SnakeCase<Uncapitalize<P2>>}` : Lowercase<S>;
|
|
3
|
-
type NonPlainObject = Date | RegExp | Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any> | Promise<any> | Error | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array | ((...args: any[]) => any) | typeof globalThis;
|
|
4
|
-
type ToSnakeCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToSnakeCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as SnakeCase<string & K>]: ToSnakeCaseKeys<T[K]> } : T;
|
|
5
4
|
/**
|
|
6
5
|
* Creates a new object composed of the properties with keys converted to snake_case.
|
|
7
6
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToCamelCaseKeys.d.ts
|
|
4
|
+
type SnakeToCamel<S extends string> = S extends `${infer H}_${infer T}` ? `${Lowercase<H>}${Capitalize<SnakeToCamel<T>>}` : Lowercase<S>;
|
|
5
|
+
type PascalToCamel<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
6
|
+
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase the entire string; otherwise, just lowercase the first letter (including PascalCase → camelCase). */
|
|
7
|
+
type AnyToCamel<S extends string> = S extends `${string}_${string}` ? SnakeToCamel<S> : S extends Uppercase<S> ? Lowercase<S> : PascalToCamel<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the keys of `T` to camelCase recursively.
|
|
10
|
+
*
|
|
11
|
+
* This is the return type of the `toCamelCaseKeys` function. Recurses into
|
|
12
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
13
|
+
* pass through unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type whose keys are converted.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* type Response = { user_id: number; first_name: string };
|
|
19
|
+
* type Converted = ToCamelCaseKeys<Response>;
|
|
20
|
+
* // => { userId: number; firstName: string }
|
|
21
|
+
*/
|
|
22
|
+
type ToCamelCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToCamelCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToCamel<Extract<K, string>>]: ToCamelCaseKeys<T[K]> } : T;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ToCamelCaseKeys };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToCamelCaseKeys.d.ts
|
|
4
|
+
type SnakeToCamel<S extends string> = S extends `${infer H}_${infer T}` ? `${Lowercase<H>}${Capitalize<SnakeToCamel<T>>}` : Lowercase<S>;
|
|
5
|
+
type PascalToCamel<S extends string> = S extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : S;
|
|
6
|
+
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase the entire string; otherwise, just lowercase the first letter (including PascalCase → camelCase). */
|
|
7
|
+
type AnyToCamel<S extends string> = S extends `${string}_${string}` ? SnakeToCamel<S> : S extends Uppercase<S> ? Lowercase<S> : PascalToCamel<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the keys of `T` to camelCase recursively.
|
|
10
|
+
*
|
|
11
|
+
* This is the return type of the `toCamelCaseKeys` function. Recurses into
|
|
12
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
13
|
+
* pass through unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type whose keys are converted.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* type Response = { user_id: number; first_name: string };
|
|
19
|
+
* type Converted = ToCamelCaseKeys<Response>;
|
|
20
|
+
* // => { userId: number; firstName: string }
|
|
21
|
+
*/
|
|
22
|
+
type ToCamelCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToCamelCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToCamel<Extract<K, string>>]: ToCamelCaseKeys<T[K]> } : T;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ToCamelCaseKeys };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToConstantCaseKeys.d.ts
|
|
4
|
+
type ConstantCase<S extends string> = S extends Lowercase<S> ? Uppercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Uppercase<P1>}${ConstantCase<P2>}` : `${Uppercase<P1>}_${ConstantCase<Uncapitalize<P2>>}` : Uppercase<S>;
|
|
5
|
+
/**
|
|
6
|
+
* Converts the keys of `T` to CONSTANT_CASE recursively.
|
|
7
|
+
*
|
|
8
|
+
* This is the return type of the `toConstantCaseKeys` function. Recurses into
|
|
9
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
10
|
+
* pass through unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type whose keys are converted.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* type Response = { userId: number; firstName: string };
|
|
16
|
+
* type Converted = ToConstantCaseKeys<Response>;
|
|
17
|
+
* // => { USER_ID: number; FIRST_NAME: string }
|
|
18
|
+
*/
|
|
19
|
+
type ToConstantCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToConstantCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as ConstantCase<string & K>]: ToConstantCaseKeys<T[K]> } : T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ToConstantCaseKeys };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToConstantCaseKeys.d.ts
|
|
4
|
+
type ConstantCase<S extends string> = S extends Lowercase<S> ? Uppercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Uppercase<P1>}${ConstantCase<P2>}` : `${Uppercase<P1>}_${ConstantCase<Uncapitalize<P2>>}` : Uppercase<S>;
|
|
5
|
+
/**
|
|
6
|
+
* Converts the keys of `T` to CONSTANT_CASE recursively.
|
|
7
|
+
*
|
|
8
|
+
* This is the return type of the `toConstantCaseKeys` function. Recurses into
|
|
9
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
10
|
+
* pass through unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type whose keys are converted.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* type Response = { userId: number; firstName: string };
|
|
16
|
+
* type Converted = ToConstantCaseKeys<Response>;
|
|
17
|
+
* // => { USER_ID: number; FIRST_NAME: string }
|
|
18
|
+
*/
|
|
19
|
+
type ToConstantCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToConstantCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as ConstantCase<string & K>]: ToConstantCaseKeys<T[K]> } : T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ToConstantCaseKeys };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToKebabCaseKeys.d.ts
|
|
4
|
+
type SnakeToKebab<S extends string> = S extends `${infer P1}_${infer P2}` ? Lowercase<`${P1}-${SnakeToKebab<P2>}`> : Lowercase<S>;
|
|
5
|
+
type CamelToKebab<S extends string> = S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${CamelToKebab<P2>}` : `${Lowercase<P1>}-${CamelToKebab<Uncapitalize<P2>>}` : S;
|
|
6
|
+
type KebabCase<S extends string> = S extends `${string}_${string}` ? SnakeToKebab<S> : S extends Uppercase<S> ? Lowercase<S> : CamelToKebab<S>;
|
|
7
|
+
/**
|
|
8
|
+
* Converts the keys of `T` to kebab-case recursively.
|
|
9
|
+
*
|
|
10
|
+
* This is the return type of the `toKebabCaseKeys` function. Recurses into
|
|
11
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
12
|
+
* pass through unchanged.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type whose keys are converted.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* type Response = { userId: number; firstName: string };
|
|
18
|
+
* type Converted = ToKebabCaseKeys<Response>;
|
|
19
|
+
* // => { 'user-id': number; 'first-name': string }
|
|
20
|
+
*/
|
|
21
|
+
type ToKebabCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToKebabCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as KebabCase<string & K>]: ToKebabCaseKeys<T[K]> } : T;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ToKebabCaseKeys };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToKebabCaseKeys.d.ts
|
|
4
|
+
type SnakeToKebab<S extends string> = S extends `${infer P1}_${infer P2}` ? Lowercase<`${P1}-${SnakeToKebab<P2>}`> : Lowercase<S>;
|
|
5
|
+
type CamelToKebab<S extends string> = S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${CamelToKebab<P2>}` : `${Lowercase<P1>}-${CamelToKebab<Uncapitalize<P2>>}` : S;
|
|
6
|
+
type KebabCase<S extends string> = S extends `${string}_${string}` ? SnakeToKebab<S> : S extends Uppercase<S> ? Lowercase<S> : CamelToKebab<S>;
|
|
7
|
+
/**
|
|
8
|
+
* Converts the keys of `T` to kebab-case recursively.
|
|
9
|
+
*
|
|
10
|
+
* This is the return type of the `toKebabCaseKeys` function. Recurses into
|
|
11
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
12
|
+
* pass through unchanged.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type whose keys are converted.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* type Response = { userId: number; firstName: string };
|
|
18
|
+
* type Converted = ToKebabCaseKeys<Response>;
|
|
19
|
+
* // => { 'user-id': number; 'first-name': string }
|
|
20
|
+
*/
|
|
21
|
+
type ToKebabCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToKebabCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as KebabCase<string & K>]: ToKebabCaseKeys<T[K]> } : T;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ToKebabCaseKeys };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToPascalCaseKeys.d.ts
|
|
4
|
+
type SnakeToPascal<S extends string> = S extends `${infer H}_${infer T}` ? `${Capitalize<Lowercase<H>>}${Capitalize<SnakeToPascal<T>>}` : Capitalize<Lowercase<S>>;
|
|
5
|
+
type CamelToPascal<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
6
|
+
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase and capitalize the entire string; otherwise, just uppercase the first letter (including camelCase → PascalCase). */
|
|
7
|
+
type AnyToPascal<S extends string> = S extends `${string}_${string}` ? SnakeToPascal<S> : S extends Uppercase<S> ? Capitalize<Lowercase<S>> : CamelToPascal<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the keys of `T` to PascalCase recursively.
|
|
10
|
+
*
|
|
11
|
+
* This is the return type of the `toPascalCaseKeys` function. Recurses into
|
|
12
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
13
|
+
* pass through unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type whose keys are converted.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* type Response = { userId: number; firstName: string };
|
|
19
|
+
* type Converted = ToPascalCaseKeys<Response>;
|
|
20
|
+
* // => { UserId: number; FirstName: string }
|
|
21
|
+
*/
|
|
22
|
+
type ToPascalCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToPascalCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToPascal<Extract<K, string>>]: ToPascalCaseKeys<T[K]> } : T;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ToPascalCaseKeys };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToPascalCaseKeys.d.ts
|
|
4
|
+
type SnakeToPascal<S extends string> = S extends `${infer H}_${infer T}` ? `${Capitalize<Lowercase<H>>}${Capitalize<SnakeToPascal<T>>}` : Capitalize<Lowercase<S>>;
|
|
5
|
+
type CamelToPascal<S extends string> = S extends `${infer F}${infer R}` ? `${Uppercase<F>}${R}` : S;
|
|
6
|
+
/** If it's snake_case, apply the snake_case rule; for uppercase keys, lowercase and capitalize the entire string; otherwise, just uppercase the first letter (including camelCase → PascalCase). */
|
|
7
|
+
type AnyToPascal<S extends string> = S extends `${string}_${string}` ? SnakeToPascal<S> : S extends Uppercase<S> ? Capitalize<Lowercase<S>> : CamelToPascal<S>;
|
|
8
|
+
/**
|
|
9
|
+
* Converts the keys of `T` to PascalCase recursively.
|
|
10
|
+
*
|
|
11
|
+
* This is the return type of the `toPascalCaseKeys` function. Recurses into
|
|
12
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
13
|
+
* pass through unchanged.
|
|
14
|
+
*
|
|
15
|
+
* @template T - The type whose keys are converted.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* type Response = { userId: number; firstName: string };
|
|
19
|
+
* type Converted = ToPascalCaseKeys<Response>;
|
|
20
|
+
* // => { UserId: number; FirstName: string }
|
|
21
|
+
*/
|
|
22
|
+
type ToPascalCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToPascalCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as AnyToPascal<Extract<K, string>>]: ToPascalCaseKeys<T[K]> } : T;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ToPascalCaseKeys };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToSnakeCaseKeys.d.ts
|
|
4
|
+
type SnakeCase<S extends string> = S extends Uppercase<S> ? Lowercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${SnakeCase<P2>}` : `${Lowercase<P1>}_${SnakeCase<Uncapitalize<P2>>}` : Lowercase<S>;
|
|
5
|
+
/**
|
|
6
|
+
* Converts the keys of `T` to snake_case recursively.
|
|
7
|
+
*
|
|
8
|
+
* This is the return type of the `toSnakeCaseKeys` function. Recurses into
|
|
9
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
10
|
+
* pass through unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type whose keys are converted.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* type Request = { userId: number; firstName: string };
|
|
16
|
+
* type Converted = ToSnakeCaseKeys<Request>;
|
|
17
|
+
* // => { user_id: number; first_name: string }
|
|
18
|
+
*/
|
|
19
|
+
type ToSnakeCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToSnakeCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as SnakeCase<string & K>]: ToSnakeCaseKeys<T[K]> } : T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ToSnakeCaseKeys };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NonPlainObject } from "../_internal/NonPlainObject.js";
|
|
2
|
+
|
|
3
|
+
//#region src/types/ToSnakeCaseKeys.d.ts
|
|
4
|
+
type SnakeCase<S extends string> = S extends Uppercase<S> ? Lowercase<S> : S extends `${infer P1}${infer P2}` ? P2 extends Uncapitalize<P2> ? `${Lowercase<P1>}${SnakeCase<P2>}` : `${Lowercase<P1>}_${SnakeCase<Uncapitalize<P2>>}` : Lowercase<S>;
|
|
5
|
+
/**
|
|
6
|
+
* Converts the keys of `T` to snake_case recursively.
|
|
7
|
+
*
|
|
8
|
+
* This is the return type of the `toSnakeCaseKeys` function. Recurses into
|
|
9
|
+
* plain objects and arrays; built-in objects like `Date`, `Map`, and functions
|
|
10
|
+
* pass through unchanged.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The type whose keys are converted.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* type Request = { userId: number; firstName: string };
|
|
16
|
+
* type Converted = ToSnakeCaseKeys<Request>;
|
|
17
|
+
* // => { user_id: number; first_name: string }
|
|
18
|
+
*/
|
|
19
|
+
type ToSnakeCaseKeys<T> = T extends NonPlainObject ? T : T extends any[] ? Array<ToSnakeCaseKeys<T[number]>> : T extends Record<string, any> ? { [K in keyof T as SnakeCase<string & K>]: ToSnakeCaseKeys<T[K]> } : T;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ToSnakeCaseKeys };
|
package/dist/types/index.d.mts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { ToCamelCaseKeys } from "./ToCamelCaseKeys.mjs";
|
|
2
|
+
import { ToConstantCaseKeys } from "./ToConstantCaseKeys.mjs";
|
|
3
|
+
import { ToKebabCaseKeys } from "./ToKebabCaseKeys.mjs";
|
|
4
|
+
import { ToPascalCaseKeys } from "./ToPascalCaseKeys.mjs";
|
|
5
|
+
import { ToSnakeCaseKeys } from "./ToSnakeCaseKeys.mjs";
|
|
1
6
|
import { DeepPartial } from "./DeepPartial.mjs";
|
|
2
7
|
import { DeepReadonly } from "./DeepReadonly.mjs";
|
|
3
8
|
import { NonEmptyArray } from "./NonEmptyArray.mjs";
|
|
4
9
|
import { Simplify } from "./Simplify.mjs";
|
|
5
10
|
import { ValueOf } from "./ValueOf.mjs";
|
|
6
11
|
import { Writable } from "./Writable.mjs";
|
|
7
|
-
export { type DeepPartial, type DeepReadonly, type NonEmptyArray, type Simplify, type ValueOf, type Writable };
|
|
12
|
+
export { type DeepPartial, type DeepReadonly, type NonEmptyArray, type Simplify, type ToCamelCaseKeys, type ToConstantCaseKeys, type ToKebabCaseKeys, type ToPascalCaseKeys, type ToSnakeCaseKeys, type ValueOf, type Writable };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { ToCamelCaseKeys } from "./ToCamelCaseKeys.js";
|
|
2
|
+
import { ToConstantCaseKeys } from "./ToConstantCaseKeys.js";
|
|
3
|
+
import { ToKebabCaseKeys } from "./ToKebabCaseKeys.js";
|
|
4
|
+
import { ToPascalCaseKeys } from "./ToPascalCaseKeys.js";
|
|
5
|
+
import { ToSnakeCaseKeys } from "./ToSnakeCaseKeys.js";
|
|
1
6
|
import { DeepPartial } from "./DeepPartial.js";
|
|
2
7
|
import { DeepReadonly } from "./DeepReadonly.js";
|
|
3
8
|
import { NonEmptyArray } from "./NonEmptyArray.js";
|
|
4
9
|
import { Simplify } from "./Simplify.js";
|
|
5
10
|
import { ValueOf } from "./ValueOf.js";
|
|
6
11
|
import { Writable } from "./Writable.js";
|
|
7
|
-
export { type DeepPartial, type DeepReadonly, type NonEmptyArray, type Simplify, type ValueOf, type Writable };
|
|
12
|
+
export { type DeepPartial, type DeepReadonly, type NonEmptyArray, type Simplify, type ToCamelCaseKeys, type ToConstantCaseKeys, type ToKebabCaseKeys, type ToPascalCaseKeys, type ToSnakeCaseKeys, type ValueOf, type Writable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.50.0-dev.
|
|
3
|
+
"version": "1.50.0-dev.2055+658bc937",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|