es-toolkit 1.50.0-dev.2001 → 1.50.0-dev.2025

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.
Files changed (58) hide show
  1. package/dist/browser.global.js +3 -3
  2. package/dist/compat/array/chunk.js +1 -0
  3. package/dist/compat/array/chunk.mjs +1 -0
  4. package/dist/compat/array/dropRight.d.mts +2 -3
  5. package/dist/compat/array/dropRight.d.ts +2 -3
  6. package/dist/compat/array/dropRight.js +4 -4
  7. package/dist/compat/array/dropRight.mjs +4 -4
  8. package/dist/compat/array/every.js +9 -9
  9. package/dist/compat/array/every.mjs +9 -9
  10. package/dist/compat/array/fill.js +5 -0
  11. package/dist/compat/array/fill.mjs +5 -0
  12. package/dist/compat/array/findIndex.js +3 -19
  13. package/dist/compat/array/findIndex.mjs +3 -19
  14. package/dist/compat/array/findLast.js +3 -3
  15. package/dist/compat/array/findLast.mjs +3 -3
  16. package/dist/compat/array/flatMap.js +3 -8
  17. package/dist/compat/array/flatMap.mjs +3 -7
  18. package/dist/compat/array/flatMapDepth.js +1 -1
  19. package/dist/compat/array/flatMapDepth.mjs +1 -1
  20. package/dist/compat/array/includes.js +13 -13
  21. package/dist/compat/array/includes.mjs +13 -13
  22. package/dist/compat/array/map.js +3 -3
  23. package/dist/compat/array/map.mjs +3 -3
  24. package/dist/compat/array/orderBy.js +1 -2
  25. package/dist/compat/array/orderBy.mjs +1 -2
  26. package/dist/compat/compat.js +1 -1
  27. package/dist/compat/compat.mjs +1 -1
  28. package/dist/compat/index.js +1 -1
  29. package/dist/compat/index.mjs +1 -1
  30. package/dist/compat/util/toArray.js +5 -1
  31. package/dist/compat/util/toArray.mjs +5 -1
  32. package/dist/compat/util/toString.js +4 -1
  33. package/dist/compat/util/toString.mjs +4 -1
  34. package/dist/function/retry.js +4 -2
  35. package/dist/function/retry.mjs +1 -1
  36. package/dist/index.d.mts +4 -1
  37. package/dist/index.d.ts +4 -1
  38. package/dist/index.js +9 -3
  39. package/dist/index.mjs +7 -4
  40. package/dist/object/index.d.mts +4 -1
  41. package/dist/object/index.d.ts +4 -1
  42. package/dist/object/index.js +6 -0
  43. package/dist/object/index.mjs +4 -1
  44. package/dist/object/toConstantCaseKeys.d.mts +53 -0
  45. package/dist/object/toConstantCaseKeys.d.ts +53 -0
  46. package/dist/object/toConstantCaseKeys.js +66 -0
  47. package/dist/object/toConstantCaseKeys.mjs +66 -0
  48. package/dist/object/toKebabCaseKeys.d.mts +55 -0
  49. package/dist/object/toKebabCaseKeys.d.ts +55 -0
  50. package/dist/object/toKebabCaseKeys.js +66 -0
  51. package/dist/object/toKebabCaseKeys.mjs +66 -0
  52. package/dist/object/toPascalCaseKeys.d.mts +56 -0
  53. package/dist/object/toPascalCaseKeys.d.ts +56 -0
  54. package/dist/object/toPascalCaseKeys.js +66 -0
  55. package/dist/object/toPascalCaseKeys.mjs +66 -0
  56. package/dist/string/index.js +3 -3
  57. package/dist/string/index.mjs +3 -3
  58. package/package.json +1 -1
@@ -14,6 +14,9 @@ import { pick } from "./pick.mjs";
14
14
  import { pickBy } from "./pickBy.mjs";
15
15
  import { sortKeys } from "./sortKeys.mjs";
16
16
  import { toCamelCaseKeys } from "./toCamelCaseKeys.mjs";
17
+ import { toConstantCaseKeys } from "./toConstantCaseKeys.mjs";
18
+ import { toKebabCaseKeys } from "./toKebabCaseKeys.mjs";
17
19
  import { toMerged } from "./toMerged.mjs";
20
+ import { toPascalCaseKeys } from "./toPascalCaseKeys.mjs";
18
21
  import { toSnakeCaseKeys } from "./toSnakeCaseKeys.mjs";
19
- export { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, sortKeys, toCamelCaseKeys, toMerged, toSnakeCaseKeys };
22
+ export { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, sortKeys, toCamelCaseKeys, toConstantCaseKeys, toKebabCaseKeys, toMerged, toPascalCaseKeys, toSnakeCaseKeys };
@@ -14,6 +14,9 @@ import { pick } from "./pick.js";
14
14
  import { pickBy } from "./pickBy.js";
15
15
  import { sortKeys } from "./sortKeys.js";
16
16
  import { toCamelCaseKeys } from "./toCamelCaseKeys.js";
17
+ import { toConstantCaseKeys } from "./toConstantCaseKeys.js";
18
+ import { toKebabCaseKeys } from "./toKebabCaseKeys.js";
17
19
  import { toMerged } from "./toMerged.js";
20
+ import { toPascalCaseKeys } from "./toPascalCaseKeys.js";
18
21
  import { toSnakeCaseKeys } from "./toSnakeCaseKeys.js";
19
- export { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, sortKeys, toCamelCaseKeys, toMerged, toSnakeCaseKeys };
22
+ export { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, sortKeys, toCamelCaseKeys, toConstantCaseKeys, toKebabCaseKeys, toMerged, toPascalCaseKeys, toSnakeCaseKeys };
@@ -15,7 +15,10 @@ const require_pick = require("./pick.js");
15
15
  const require_pickBy = require("./pickBy.js");
16
16
  const require_sortKeys = require("./sortKeys.js");
17
17
  const require_toCamelCaseKeys = require("./toCamelCaseKeys.js");
18
+ const require_toConstantCaseKeys = require("./toConstantCaseKeys.js");
19
+ const require_toKebabCaseKeys = require("./toKebabCaseKeys.js");
18
20
  const require_toMerged = require("./toMerged.js");
21
+ const require_toPascalCaseKeys = require("./toPascalCaseKeys.js");
19
22
  const require_toSnakeCaseKeys = require("./toSnakeCaseKeys.js");
20
23
  exports.clone = require_clone.clone;
21
24
  exports.cloneDeep = require_cloneDeep.cloneDeep;
@@ -33,5 +36,8 @@ exports.pick = require_pick.pick;
33
36
  exports.pickBy = require_pickBy.pickBy;
34
37
  exports.sortKeys = require_sortKeys.sortKeys;
35
38
  exports.toCamelCaseKeys = require_toCamelCaseKeys.toCamelCaseKeys;
39
+ exports.toConstantCaseKeys = require_toConstantCaseKeys.toConstantCaseKeys;
40
+ exports.toKebabCaseKeys = require_toKebabCaseKeys.toKebabCaseKeys;
36
41
  exports.toMerged = require_toMerged.toMerged;
42
+ exports.toPascalCaseKeys = require_toPascalCaseKeys.toPascalCaseKeys;
37
43
  exports.toSnakeCaseKeys = require_toSnakeCaseKeys.toSnakeCaseKeys;
@@ -14,6 +14,9 @@ import { pick } from "./pick.mjs";
14
14
  import { pickBy } from "./pickBy.mjs";
15
15
  import { sortKeys } from "./sortKeys.mjs";
16
16
  import { toCamelCaseKeys } from "./toCamelCaseKeys.mjs";
17
+ import { toConstantCaseKeys } from "./toConstantCaseKeys.mjs";
18
+ import { toKebabCaseKeys } from "./toKebabCaseKeys.mjs";
17
19
  import { toMerged } from "./toMerged.mjs";
20
+ import { toPascalCaseKeys } from "./toPascalCaseKeys.mjs";
18
21
  import { toSnakeCaseKeys } from "./toSnakeCaseKeys.mjs";
19
- export { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, sortKeys, toCamelCaseKeys, toMerged, toSnakeCaseKeys };
22
+ export { clone, cloneDeep, cloneDeepWith, findKey, flattenObject, invert, mapKeys, mapValues, merge, mergeWith, omit, omitBy, pick, pickBy, sortKeys, toCamelCaseKeys, toConstantCaseKeys, toKebabCaseKeys, toMerged, toPascalCaseKeys, toSnakeCaseKeys };
@@ -0,0 +1,53 @@
1
+ //#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
+ /**
6
+ * Creates a new object composed of the properties with keys converted to CONSTANT_CASE.
7
+ *
8
+ * This function takes an object and returns a new object that includes the same properties,
9
+ * but with all keys converted to CONSTANT_CASE format.
10
+ *
11
+ * @template T - The type of object.
12
+ * @param obj - The object to convert keys from.
13
+ * @returns A new object with all keys converted to CONSTANT_CASE.
14
+ *
15
+ * @example
16
+ * // Example with objects
17
+ * const obj = { userId: 1, firstName: 'John' };
18
+ * const result = toConstantCaseKeys(obj);
19
+ * // result will be { USER_ID: 1, FIRST_NAME: 'John' }
20
+ *
21
+ * // Example with arrays of objects
22
+ * const arr = [
23
+ * { userId: 1, firstName: 'John' },
24
+ * { userId: 2, firstName: 'Jane' }
25
+ * ];
26
+ * const arrResult = toConstantCaseKeys(arr);
27
+ * // arrResult will be [{ USER_ID: 1, FIRST_NAME: 'John' }, { USER_ID: 2, FIRST_NAME: 'Jane' }]
28
+ *
29
+ * // Example with nested objects
30
+ * const nested = {
31
+ * userData: {
32
+ * userId: 1,
33
+ * userAddress: {
34
+ * streetName: 'Main St',
35
+ * zipCode: '12345'
36
+ * }
37
+ * }
38
+ * };
39
+ * const nestedResult = toConstantCaseKeys(nested);
40
+ * // nestedResult will be:
41
+ * // {
42
+ * // USER_DATA: {
43
+ * // USER_ID: 1,
44
+ * // USER_ADDRESS: {
45
+ * // STREET_NAME: 'Main St',
46
+ * // ZIP_CODE: '12345'
47
+ * // }
48
+ * // }
49
+ * // }
50
+ */
51
+ declare function toConstantCaseKeys<T>(obj: T): ToConstantCaseKeys<T>;
52
+ //#endregion
53
+ export { toConstantCaseKeys };
@@ -0,0 +1,53 @@
1
+ //#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
+ /**
6
+ * Creates a new object composed of the properties with keys converted to CONSTANT_CASE.
7
+ *
8
+ * This function takes an object and returns a new object that includes the same properties,
9
+ * but with all keys converted to CONSTANT_CASE format.
10
+ *
11
+ * @template T - The type of object.
12
+ * @param obj - The object to convert keys from.
13
+ * @returns A new object with all keys converted to CONSTANT_CASE.
14
+ *
15
+ * @example
16
+ * // Example with objects
17
+ * const obj = { userId: 1, firstName: 'John' };
18
+ * const result = toConstantCaseKeys(obj);
19
+ * // result will be { USER_ID: 1, FIRST_NAME: 'John' }
20
+ *
21
+ * // Example with arrays of objects
22
+ * const arr = [
23
+ * { userId: 1, firstName: 'John' },
24
+ * { userId: 2, firstName: 'Jane' }
25
+ * ];
26
+ * const arrResult = toConstantCaseKeys(arr);
27
+ * // arrResult will be [{ USER_ID: 1, FIRST_NAME: 'John' }, { USER_ID: 2, FIRST_NAME: 'Jane' }]
28
+ *
29
+ * // Example with nested objects
30
+ * const nested = {
31
+ * userData: {
32
+ * userId: 1,
33
+ * userAddress: {
34
+ * streetName: 'Main St',
35
+ * zipCode: '12345'
36
+ * }
37
+ * }
38
+ * };
39
+ * const nestedResult = toConstantCaseKeys(nested);
40
+ * // nestedResult will be:
41
+ * // {
42
+ * // USER_DATA: {
43
+ * // USER_ID: 1,
44
+ * // USER_ADDRESS: {
45
+ * // STREET_NAME: 'Main St',
46
+ * // ZIP_CODE: '12345'
47
+ * // }
48
+ * // }
49
+ * // }
50
+ */
51
+ declare function toConstantCaseKeys<T>(obj: T): ToConstantCaseKeys<T>;
52
+ //#endregion
53
+ export { toConstantCaseKeys };
@@ -0,0 +1,66 @@
1
+ const require_isArray = require("../compat/predicate/isArray.js");
2
+ const require_isPlainObject = require("../compat/predicate/isPlainObject.js");
3
+ const require_constantCase = require("../string/constantCase.js");
4
+ //#region src/object/toConstantCaseKeys.ts
5
+ /**
6
+ * Creates a new object composed of the properties with keys converted to CONSTANT_CASE.
7
+ *
8
+ * This function takes an object and returns a new object that includes the same properties,
9
+ * but with all keys converted to CONSTANT_CASE format.
10
+ *
11
+ * @template T - The type of object.
12
+ * @param obj - The object to convert keys from.
13
+ * @returns A new object with all keys converted to CONSTANT_CASE.
14
+ *
15
+ * @example
16
+ * // Example with objects
17
+ * const obj = { userId: 1, firstName: 'John' };
18
+ * const result = toConstantCaseKeys(obj);
19
+ * // result will be { USER_ID: 1, FIRST_NAME: 'John' }
20
+ *
21
+ * // Example with arrays of objects
22
+ * const arr = [
23
+ * { userId: 1, firstName: 'John' },
24
+ * { userId: 2, firstName: 'Jane' }
25
+ * ];
26
+ * const arrResult = toConstantCaseKeys(arr);
27
+ * // arrResult will be [{ USER_ID: 1, FIRST_NAME: 'John' }, { USER_ID: 2, FIRST_NAME: 'Jane' }]
28
+ *
29
+ * // Example with nested objects
30
+ * const nested = {
31
+ * userData: {
32
+ * userId: 1,
33
+ * userAddress: {
34
+ * streetName: 'Main St',
35
+ * zipCode: '12345'
36
+ * }
37
+ * }
38
+ * };
39
+ * const nestedResult = toConstantCaseKeys(nested);
40
+ * // nestedResult will be:
41
+ * // {
42
+ * // USER_DATA: {
43
+ * // USER_ID: 1,
44
+ * // USER_ADDRESS: {
45
+ * // STREET_NAME: 'Main St',
46
+ * // ZIP_CODE: '12345'
47
+ * // }
48
+ * // }
49
+ * // }
50
+ */
51
+ function toConstantCaseKeys(obj) {
52
+ if (require_isArray.isArray(obj)) return obj.map((item) => toConstantCaseKeys(item));
53
+ if (require_isPlainObject.isPlainObject(obj)) {
54
+ const result = {};
55
+ const keys = Object.keys(obj);
56
+ for (let i = 0; i < keys.length; i++) {
57
+ const key = keys[i];
58
+ const constantKey = require_constantCase.constantCase(key);
59
+ result[constantKey] = toConstantCaseKeys(obj[key]);
60
+ }
61
+ return result;
62
+ }
63
+ return obj;
64
+ }
65
+ //#endregion
66
+ exports.toConstantCaseKeys = toConstantCaseKeys;
@@ -0,0 +1,66 @@
1
+ import { isArray } from "../compat/predicate/isArray.mjs";
2
+ import { isPlainObject } from "../compat/predicate/isPlainObject.mjs";
3
+ import { constantCase } from "../string/constantCase.mjs";
4
+ //#region src/object/toConstantCaseKeys.ts
5
+ /**
6
+ * Creates a new object composed of the properties with keys converted to CONSTANT_CASE.
7
+ *
8
+ * This function takes an object and returns a new object that includes the same properties,
9
+ * but with all keys converted to CONSTANT_CASE format.
10
+ *
11
+ * @template T - The type of object.
12
+ * @param obj - The object to convert keys from.
13
+ * @returns A new object with all keys converted to CONSTANT_CASE.
14
+ *
15
+ * @example
16
+ * // Example with objects
17
+ * const obj = { userId: 1, firstName: 'John' };
18
+ * const result = toConstantCaseKeys(obj);
19
+ * // result will be { USER_ID: 1, FIRST_NAME: 'John' }
20
+ *
21
+ * // Example with arrays of objects
22
+ * const arr = [
23
+ * { userId: 1, firstName: 'John' },
24
+ * { userId: 2, firstName: 'Jane' }
25
+ * ];
26
+ * const arrResult = toConstantCaseKeys(arr);
27
+ * // arrResult will be [{ USER_ID: 1, FIRST_NAME: 'John' }, { USER_ID: 2, FIRST_NAME: 'Jane' }]
28
+ *
29
+ * // Example with nested objects
30
+ * const nested = {
31
+ * userData: {
32
+ * userId: 1,
33
+ * userAddress: {
34
+ * streetName: 'Main St',
35
+ * zipCode: '12345'
36
+ * }
37
+ * }
38
+ * };
39
+ * const nestedResult = toConstantCaseKeys(nested);
40
+ * // nestedResult will be:
41
+ * // {
42
+ * // USER_DATA: {
43
+ * // USER_ID: 1,
44
+ * // USER_ADDRESS: {
45
+ * // STREET_NAME: 'Main St',
46
+ * // ZIP_CODE: '12345'
47
+ * // }
48
+ * // }
49
+ * // }
50
+ */
51
+ function toConstantCaseKeys(obj) {
52
+ if (isArray(obj)) return obj.map((item) => toConstantCaseKeys(item));
53
+ if (isPlainObject(obj)) {
54
+ const result = {};
55
+ const keys = Object.keys(obj);
56
+ for (let i = 0; i < keys.length; i++) {
57
+ const key = keys[i];
58
+ const constantKey = constantCase(key);
59
+ result[constantKey] = toConstantCaseKeys(obj[key]);
60
+ }
61
+ return result;
62
+ }
63
+ return obj;
64
+ }
65
+ //#endregion
66
+ export { toConstantCaseKeys };
@@ -0,0 +1,55 @@
1
+ //#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
+ /**
8
+ * Creates a new object composed of the properties with keys converted to kebab-case.
9
+ *
10
+ * This function takes an object and returns a new object that includes the same properties,
11
+ * but with all keys converted to kebab-case format.
12
+ *
13
+ * @template T - The type of object.
14
+ * @param obj - The object to convert keys from.
15
+ * @returns A new object with all keys converted to kebab-case.
16
+ *
17
+ * @example
18
+ * // Example with objects
19
+ * const obj = { userId: 1, firstName: 'John' };
20
+ * const result = toKebabCaseKeys(obj);
21
+ * // result will be { 'user-id': 1, 'first-name': 'John' }
22
+ *
23
+ * // Example with arrays of objects
24
+ * const arr = [
25
+ * { userId: 1, firstName: 'John' },
26
+ * { userId: 2, firstName: 'Jane' }
27
+ * ];
28
+ * const arrResult = toKebabCaseKeys(arr);
29
+ * // arrResult will be [{ 'user-id': 1, 'first-name': 'John' }, { 'user-id': 2, 'first-name': 'Jane' }]
30
+ *
31
+ * // Example with nested objects
32
+ * const nested = {
33
+ * userData: {
34
+ * userId: 1,
35
+ * userAddress: {
36
+ * streetName: 'Main St',
37
+ * zipCode: '12345'
38
+ * }
39
+ * }
40
+ * };
41
+ * const nestedResult = toKebabCaseKeys(nested);
42
+ * // nestedResult will be:
43
+ * // {
44
+ * // 'user-data': {
45
+ * // 'user-id': 1,
46
+ * // 'user-address': {
47
+ * // 'street-name': 'Main St',
48
+ * // 'zip-code': '12345'
49
+ * // }
50
+ * // }
51
+ * // }
52
+ */
53
+ declare function toKebabCaseKeys<T>(obj: T): ToKebabCaseKeys<T>;
54
+ //#endregion
55
+ export { toKebabCaseKeys };
@@ -0,0 +1,55 @@
1
+ //#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
+ /**
8
+ * Creates a new object composed of the properties with keys converted to kebab-case.
9
+ *
10
+ * This function takes an object and returns a new object that includes the same properties,
11
+ * but with all keys converted to kebab-case format.
12
+ *
13
+ * @template T - The type of object.
14
+ * @param obj - The object to convert keys from.
15
+ * @returns A new object with all keys converted to kebab-case.
16
+ *
17
+ * @example
18
+ * // Example with objects
19
+ * const obj = { userId: 1, firstName: 'John' };
20
+ * const result = toKebabCaseKeys(obj);
21
+ * // result will be { 'user-id': 1, 'first-name': 'John' }
22
+ *
23
+ * // Example with arrays of objects
24
+ * const arr = [
25
+ * { userId: 1, firstName: 'John' },
26
+ * { userId: 2, firstName: 'Jane' }
27
+ * ];
28
+ * const arrResult = toKebabCaseKeys(arr);
29
+ * // arrResult will be [{ 'user-id': 1, 'first-name': 'John' }, { 'user-id': 2, 'first-name': 'Jane' }]
30
+ *
31
+ * // Example with nested objects
32
+ * const nested = {
33
+ * userData: {
34
+ * userId: 1,
35
+ * userAddress: {
36
+ * streetName: 'Main St',
37
+ * zipCode: '12345'
38
+ * }
39
+ * }
40
+ * };
41
+ * const nestedResult = toKebabCaseKeys(nested);
42
+ * // nestedResult will be:
43
+ * // {
44
+ * // 'user-data': {
45
+ * // 'user-id': 1,
46
+ * // 'user-address': {
47
+ * // 'street-name': 'Main St',
48
+ * // 'zip-code': '12345'
49
+ * // }
50
+ * // }
51
+ * // }
52
+ */
53
+ declare function toKebabCaseKeys<T>(obj: T): ToKebabCaseKeys<T>;
54
+ //#endregion
55
+ export { toKebabCaseKeys };
@@ -0,0 +1,66 @@
1
+ const require_isArray = require("../compat/predicate/isArray.js");
2
+ const require_isPlainObject = require("../compat/predicate/isPlainObject.js");
3
+ const require_kebabCase = require("../string/kebabCase.js");
4
+ //#region src/object/toKebabCaseKeys.ts
5
+ /**
6
+ * Creates a new object composed of the properties with keys converted to kebab-case.
7
+ *
8
+ * This function takes an object and returns a new object that includes the same properties,
9
+ * but with all keys converted to kebab-case format.
10
+ *
11
+ * @template T - The type of object.
12
+ * @param obj - The object to convert keys from.
13
+ * @returns A new object with all keys converted to kebab-case.
14
+ *
15
+ * @example
16
+ * // Example with objects
17
+ * const obj = { userId: 1, firstName: 'John' };
18
+ * const result = toKebabCaseKeys(obj);
19
+ * // result will be { 'user-id': 1, 'first-name': 'John' }
20
+ *
21
+ * // Example with arrays of objects
22
+ * const arr = [
23
+ * { userId: 1, firstName: 'John' },
24
+ * { userId: 2, firstName: 'Jane' }
25
+ * ];
26
+ * const arrResult = toKebabCaseKeys(arr);
27
+ * // arrResult will be [{ 'user-id': 1, 'first-name': 'John' }, { 'user-id': 2, 'first-name': 'Jane' }]
28
+ *
29
+ * // Example with nested objects
30
+ * const nested = {
31
+ * userData: {
32
+ * userId: 1,
33
+ * userAddress: {
34
+ * streetName: 'Main St',
35
+ * zipCode: '12345'
36
+ * }
37
+ * }
38
+ * };
39
+ * const nestedResult = toKebabCaseKeys(nested);
40
+ * // nestedResult will be:
41
+ * // {
42
+ * // 'user-data': {
43
+ * // 'user-id': 1,
44
+ * // 'user-address': {
45
+ * // 'street-name': 'Main St',
46
+ * // 'zip-code': '12345'
47
+ * // }
48
+ * // }
49
+ * // }
50
+ */
51
+ function toKebabCaseKeys(obj) {
52
+ if (require_isArray.isArray(obj)) return obj.map((item) => toKebabCaseKeys(item));
53
+ if (require_isPlainObject.isPlainObject(obj)) {
54
+ const result = {};
55
+ const keys = Object.keys(obj);
56
+ for (let i = 0; i < keys.length; i++) {
57
+ const key = keys[i];
58
+ const kebabKey = require_kebabCase.kebabCase(key);
59
+ result[kebabKey] = toKebabCaseKeys(obj[key]);
60
+ }
61
+ return result;
62
+ }
63
+ return obj;
64
+ }
65
+ //#endregion
66
+ exports.toKebabCaseKeys = toKebabCaseKeys;
@@ -0,0 +1,66 @@
1
+ import { isArray } from "../compat/predicate/isArray.mjs";
2
+ import { isPlainObject } from "../compat/predicate/isPlainObject.mjs";
3
+ import { kebabCase } from "../string/kebabCase.mjs";
4
+ //#region src/object/toKebabCaseKeys.ts
5
+ /**
6
+ * Creates a new object composed of the properties with keys converted to kebab-case.
7
+ *
8
+ * This function takes an object and returns a new object that includes the same properties,
9
+ * but with all keys converted to kebab-case format.
10
+ *
11
+ * @template T - The type of object.
12
+ * @param obj - The object to convert keys from.
13
+ * @returns A new object with all keys converted to kebab-case.
14
+ *
15
+ * @example
16
+ * // Example with objects
17
+ * const obj = { userId: 1, firstName: 'John' };
18
+ * const result = toKebabCaseKeys(obj);
19
+ * // result will be { 'user-id': 1, 'first-name': 'John' }
20
+ *
21
+ * // Example with arrays of objects
22
+ * const arr = [
23
+ * { userId: 1, firstName: 'John' },
24
+ * { userId: 2, firstName: 'Jane' }
25
+ * ];
26
+ * const arrResult = toKebabCaseKeys(arr);
27
+ * // arrResult will be [{ 'user-id': 1, 'first-name': 'John' }, { 'user-id': 2, 'first-name': 'Jane' }]
28
+ *
29
+ * // Example with nested objects
30
+ * const nested = {
31
+ * userData: {
32
+ * userId: 1,
33
+ * userAddress: {
34
+ * streetName: 'Main St',
35
+ * zipCode: '12345'
36
+ * }
37
+ * }
38
+ * };
39
+ * const nestedResult = toKebabCaseKeys(nested);
40
+ * // nestedResult will be:
41
+ * // {
42
+ * // 'user-data': {
43
+ * // 'user-id': 1,
44
+ * // 'user-address': {
45
+ * // 'street-name': 'Main St',
46
+ * // 'zip-code': '12345'
47
+ * // }
48
+ * // }
49
+ * // }
50
+ */
51
+ function toKebabCaseKeys(obj) {
52
+ if (isArray(obj)) return obj.map((item) => toKebabCaseKeys(item));
53
+ if (isPlainObject(obj)) {
54
+ const result = {};
55
+ const keys = Object.keys(obj);
56
+ for (let i = 0; i < keys.length; i++) {
57
+ const key = keys[i];
58
+ const kebabKey = kebabCase(key);
59
+ result[kebabKey] = toKebabCaseKeys(obj[key]);
60
+ }
61
+ return result;
62
+ }
63
+ return obj;
64
+ }
65
+ //#endregion
66
+ export { toKebabCaseKeys };
@@ -0,0 +1,56 @@
1
+ //#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
+ /**
9
+ * Creates a new object composed of the properties with keys converted to PascalCase.
10
+ *
11
+ * This function takes an object and returns a new object that includes the same properties,
12
+ * but with all keys converted to PascalCase format.
13
+ *
14
+ * @template T - The type of object.
15
+ * @param obj - The object to convert keys from.
16
+ * @returns A new object with all keys converted to PascalCase.
17
+ *
18
+ * @example
19
+ * // Example with objects
20
+ * const obj = { userId: 1, firstName: 'John' };
21
+ * const result = toPascalCaseKeys(obj);
22
+ * // result will be { UserId: 1, FirstName: 'John' }
23
+ *
24
+ * // Example with arrays of objects
25
+ * const arr = [
26
+ * { userId: 1, firstName: 'John' },
27
+ * { userId: 2, firstName: 'Jane' }
28
+ * ];
29
+ * const arrResult = toPascalCaseKeys(arr);
30
+ * // arrResult will be [{ UserId: 1, FirstName: 'John' }, { UserId: 2, FirstName: 'Jane' }]
31
+ *
32
+ * // Example with nested objects
33
+ * const nested = {
34
+ * userData: {
35
+ * userId: 1,
36
+ * userAddress: {
37
+ * streetName: 'Main St',
38
+ * zipCode: '12345'
39
+ * }
40
+ * }
41
+ * };
42
+ * const nestedResult = toPascalCaseKeys(nested);
43
+ * // nestedResult will be:
44
+ * // {
45
+ * // UserData: {
46
+ * // UserId: 1,
47
+ * // UserAddress: {
48
+ * // StreetName: 'Main St',
49
+ * // ZipCode: '12345'
50
+ * // }
51
+ * // }
52
+ * // }
53
+ */
54
+ declare function toPascalCaseKeys<T>(obj: T): ToPascalCaseKeys<T>;
55
+ //#endregion
56
+ export { toPascalCaseKeys };
@@ -0,0 +1,56 @@
1
+ //#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
+ /**
9
+ * Creates a new object composed of the properties with keys converted to PascalCase.
10
+ *
11
+ * This function takes an object and returns a new object that includes the same properties,
12
+ * but with all keys converted to PascalCase format.
13
+ *
14
+ * @template T - The type of object.
15
+ * @param obj - The object to convert keys from.
16
+ * @returns A new object with all keys converted to PascalCase.
17
+ *
18
+ * @example
19
+ * // Example with objects
20
+ * const obj = { userId: 1, firstName: 'John' };
21
+ * const result = toPascalCaseKeys(obj);
22
+ * // result will be { UserId: 1, FirstName: 'John' }
23
+ *
24
+ * // Example with arrays of objects
25
+ * const arr = [
26
+ * { userId: 1, firstName: 'John' },
27
+ * { userId: 2, firstName: 'Jane' }
28
+ * ];
29
+ * const arrResult = toPascalCaseKeys(arr);
30
+ * // arrResult will be [{ UserId: 1, FirstName: 'John' }, { UserId: 2, FirstName: 'Jane' }]
31
+ *
32
+ * // Example with nested objects
33
+ * const nested = {
34
+ * userData: {
35
+ * userId: 1,
36
+ * userAddress: {
37
+ * streetName: 'Main St',
38
+ * zipCode: '12345'
39
+ * }
40
+ * }
41
+ * };
42
+ * const nestedResult = toPascalCaseKeys(nested);
43
+ * // nestedResult will be:
44
+ * // {
45
+ * // UserData: {
46
+ * // UserId: 1,
47
+ * // UserAddress: {
48
+ * // StreetName: 'Main St',
49
+ * // ZipCode: '12345'
50
+ * // }
51
+ * // }
52
+ * // }
53
+ */
54
+ declare function toPascalCaseKeys<T>(obj: T): ToPascalCaseKeys<T>;
55
+ //#endregion
56
+ export { toPascalCaseKeys };