es-toolkit 1.50.0-dev.2001 → 1.50.0-dev.2026
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/browser.global.js +3 -3
- package/dist/compat/array/chunk.js +1 -0
- package/dist/compat/array/chunk.mjs +1 -0
- package/dist/compat/array/dropRight.d.mts +2 -3
- package/dist/compat/array/dropRight.d.ts +2 -3
- package/dist/compat/array/dropRight.js +4 -4
- package/dist/compat/array/dropRight.mjs +4 -4
- package/dist/compat/array/every.js +9 -9
- package/dist/compat/array/every.mjs +9 -9
- package/dist/compat/array/fill.js +5 -0
- package/dist/compat/array/fill.mjs +5 -0
- package/dist/compat/array/findIndex.js +3 -19
- package/dist/compat/array/findIndex.mjs +3 -19
- package/dist/compat/array/findLast.js +3 -3
- package/dist/compat/array/findLast.mjs +3 -3
- package/dist/compat/array/flatMap.js +3 -8
- package/dist/compat/array/flatMap.mjs +3 -7
- package/dist/compat/array/flatMapDepth.js +1 -1
- package/dist/compat/array/flatMapDepth.mjs +1 -1
- package/dist/compat/array/includes.js +13 -13
- package/dist/compat/array/includes.mjs +13 -13
- package/dist/compat/array/map.js +3 -3
- package/dist/compat/array/map.mjs +3 -3
- package/dist/compat/array/orderBy.js +1 -2
- package/dist/compat/array/orderBy.mjs +1 -2
- package/dist/compat/array/takeRightWhile.js +2 -2
- package/dist/compat/array/takeRightWhile.mjs +2 -2
- package/dist/compat/array/takeWhile.js +2 -2
- package/dist/compat/array/takeWhile.mjs +2 -2
- package/dist/compat/array/uniqBy.js +2 -2
- package/dist/compat/array/uniqBy.mjs +2 -2
- package/dist/compat/compat.js +1 -1
- package/dist/compat/compat.mjs +1 -1
- package/dist/compat/index.js +1 -1
- package/dist/compat/index.mjs +1 -1
- package/dist/compat/util/toArray.js +5 -1
- package/dist/compat/util/toArray.mjs +5 -1
- package/dist/compat/util/toString.js +4 -1
- package/dist/compat/util/toString.mjs +4 -1
- package/dist/function/retry.js +4 -2
- package/dist/function/retry.mjs +1 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +9 -3
- package/dist/index.mjs +7 -4
- package/dist/object/index.d.mts +4 -1
- package/dist/object/index.d.ts +4 -1
- package/dist/object/index.js +6 -0
- package/dist/object/index.mjs +4 -1
- package/dist/object/toConstantCaseKeys.d.mts +53 -0
- package/dist/object/toConstantCaseKeys.d.ts +53 -0
- package/dist/object/toConstantCaseKeys.js +66 -0
- package/dist/object/toConstantCaseKeys.mjs +66 -0
- package/dist/object/toKebabCaseKeys.d.mts +55 -0
- package/dist/object/toKebabCaseKeys.d.ts +55 -0
- package/dist/object/toKebabCaseKeys.js +66 -0
- package/dist/object/toKebabCaseKeys.mjs +66 -0
- package/dist/object/toPascalCaseKeys.d.mts +56 -0
- package/dist/object/toPascalCaseKeys.d.ts +56 -0
- package/dist/object/toPascalCaseKeys.js +66 -0
- package/dist/object/toPascalCaseKeys.mjs +66 -0
- package/dist/string/index.js +3 -3
- package/dist/string/index.mjs +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -121,7 +121,10 @@ import { pick } from "./object/pick.js";
|
|
|
121
121
|
import { pickBy } from "./object/pickBy.js";
|
|
122
122
|
import { sortKeys } from "./object/sortKeys.js";
|
|
123
123
|
import { toCamelCaseKeys } from "./object/toCamelCaseKeys.js";
|
|
124
|
+
import { toConstantCaseKeys } from "./object/toConstantCaseKeys.js";
|
|
125
|
+
import { toKebabCaseKeys } from "./object/toKebabCaseKeys.js";
|
|
124
126
|
import { toMerged } from "./object/toMerged.js";
|
|
127
|
+
import { toPascalCaseKeys } from "./object/toPascalCaseKeys.js";
|
|
125
128
|
import { toSnakeCaseKeys } from "./object/toSnakeCaseKeys.js";
|
|
126
129
|
import { isArrayBuffer } from "./predicate/isArrayBuffer.js";
|
|
127
130
|
import { isBlob } from "./predicate/isBlob.js";
|
|
@@ -185,4 +188,4 @@ import { words } from "./string/words.js";
|
|
|
185
188
|
import { attempt } from "./util/attempt.js";
|
|
186
189
|
import { attemptAsync } from "./util/attemptAsync.js";
|
|
187
190
|
import { invariant } from "./util/invariant.js";
|
|
188
|
-
export { AbortError, DebounceOptions, DebouncedFunction, MemoizeCache, Mutex, Semaphore, ThrottleOptions, ThrottledFunction, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
191
|
+
export { AbortError, DebounceOptions, DebouncedFunction, MemoizeCache, Mutex, Semaphore, ThrottleOptions, ThrottledFunction, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toConstantCaseKeys, toFilled, toKebabCaseKeys, toMerged, toPascalCaseKeys, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/index.js
CHANGED
|
@@ -134,7 +134,13 @@ const require_capitalize = require("./string/capitalize.js");
|
|
|
134
134
|
const require_words = require("./string/words.js");
|
|
135
135
|
const require_camelCase = require("./string/camelCase.js");
|
|
136
136
|
const require_toCamelCaseKeys = require("./object/toCamelCaseKeys.js");
|
|
137
|
+
const require_constantCase = require("./string/constantCase.js");
|
|
138
|
+
const require_toConstantCaseKeys = require("./object/toConstantCaseKeys.js");
|
|
139
|
+
const require_kebabCase = require("./string/kebabCase.js");
|
|
140
|
+
const require_toKebabCaseKeys = require("./object/toKebabCaseKeys.js");
|
|
137
141
|
const require_toMerged = require("./object/toMerged.js");
|
|
142
|
+
const require_pascalCase = require("./string/pascalCase.js");
|
|
143
|
+
const require_toPascalCaseKeys = require("./object/toPascalCaseKeys.js");
|
|
138
144
|
const require_snakeCase = require("./string/snakeCase.js");
|
|
139
145
|
const require_toSnakeCaseKeys = require("./object/toSnakeCaseKeys.js");
|
|
140
146
|
require("./object/index.js");
|
|
@@ -173,15 +179,12 @@ const require_mutex = require("./promise/mutex.js");
|
|
|
173
179
|
const require_timeout = require("./promise/timeout.js");
|
|
174
180
|
const require_withTimeout = require("./promise/withTimeout.js");
|
|
175
181
|
require("./promise/index.js");
|
|
176
|
-
const require_constantCase = require("./string/constantCase.js");
|
|
177
182
|
const require_deburr = require("./string/deburr.js");
|
|
178
183
|
const require_escape = require("./string/escape.js");
|
|
179
184
|
const require_escapeRegExp = require("./string/escapeRegExp.js");
|
|
180
|
-
const require_kebabCase = require("./string/kebabCase.js");
|
|
181
185
|
const require_lowerCase = require("./string/lowerCase.js");
|
|
182
186
|
const require_lowerFirst = require("./string/lowerFirst.js");
|
|
183
187
|
const require_pad = require("./string/pad.js");
|
|
184
|
-
const require_pascalCase = require("./string/pascalCase.js");
|
|
185
188
|
const require_reverseString = require("./string/reverseString.js");
|
|
186
189
|
const require_startCase = require("./string/startCase.js");
|
|
187
190
|
const require_trimEnd = require("./string/trimEnd.js");
|
|
@@ -357,8 +360,11 @@ exports.takeWhile = require_takeWhile.takeWhile;
|
|
|
357
360
|
exports.throttle = require_throttle.throttle;
|
|
358
361
|
exports.timeout = require_timeout.timeout;
|
|
359
362
|
exports.toCamelCaseKeys = require_toCamelCaseKeys.toCamelCaseKeys;
|
|
363
|
+
exports.toConstantCaseKeys = require_toConstantCaseKeys.toConstantCaseKeys;
|
|
360
364
|
exports.toFilled = require_toFilled.toFilled;
|
|
365
|
+
exports.toKebabCaseKeys = require_toKebabCaseKeys.toKebabCaseKeys;
|
|
361
366
|
exports.toMerged = require_toMerged.toMerged;
|
|
367
|
+
exports.toPascalCaseKeys = require_toPascalCaseKeys.toPascalCaseKeys;
|
|
362
368
|
exports.toSnakeCaseKeys = require_toSnakeCaseKeys.toSnakeCaseKeys;
|
|
363
369
|
exports.trim = require_trim.trim;
|
|
364
370
|
exports.trimEnd = require_trimEnd.trimEnd;
|
package/dist/index.mjs
CHANGED
|
@@ -133,7 +133,13 @@ import { capitalize } from "./string/capitalize.mjs";
|
|
|
133
133
|
import { words } from "./string/words.mjs";
|
|
134
134
|
import { camelCase } from "./string/camelCase.mjs";
|
|
135
135
|
import { toCamelCaseKeys } from "./object/toCamelCaseKeys.mjs";
|
|
136
|
+
import { constantCase } from "./string/constantCase.mjs";
|
|
137
|
+
import { toConstantCaseKeys } from "./object/toConstantCaseKeys.mjs";
|
|
138
|
+
import { kebabCase } from "./string/kebabCase.mjs";
|
|
139
|
+
import { toKebabCaseKeys } from "./object/toKebabCaseKeys.mjs";
|
|
136
140
|
import { toMerged } from "./object/toMerged.mjs";
|
|
141
|
+
import { pascalCase } from "./string/pascalCase.mjs";
|
|
142
|
+
import { toPascalCaseKeys } from "./object/toPascalCaseKeys.mjs";
|
|
137
143
|
import { snakeCase } from "./string/snakeCase.mjs";
|
|
138
144
|
import { toSnakeCaseKeys } from "./object/toSnakeCaseKeys.mjs";
|
|
139
145
|
import "./object/index.mjs";
|
|
@@ -172,15 +178,12 @@ import { Mutex } from "./promise/mutex.mjs";
|
|
|
172
178
|
import { timeout } from "./promise/timeout.mjs";
|
|
173
179
|
import { withTimeout } from "./promise/withTimeout.mjs";
|
|
174
180
|
import "./promise/index.mjs";
|
|
175
|
-
import { constantCase } from "./string/constantCase.mjs";
|
|
176
181
|
import { deburr } from "./string/deburr.mjs";
|
|
177
182
|
import { escape } from "./string/escape.mjs";
|
|
178
183
|
import { escapeRegExp } from "./string/escapeRegExp.mjs";
|
|
179
|
-
import { kebabCase } from "./string/kebabCase.mjs";
|
|
180
184
|
import { lowerCase } from "./string/lowerCase.mjs";
|
|
181
185
|
import { lowerFirst } from "./string/lowerFirst.mjs";
|
|
182
186
|
import { pad } from "./string/pad.mjs";
|
|
183
|
-
import { pascalCase } from "./string/pascalCase.mjs";
|
|
184
187
|
import { reverseString } from "./string/reverseString.mjs";
|
|
185
188
|
import { startCase } from "./string/startCase.mjs";
|
|
186
189
|
import { trimEnd } from "./string/trimEnd.mjs";
|
|
@@ -194,4 +197,4 @@ import { attempt } from "./util/attempt.mjs";
|
|
|
194
197
|
import { attemptAsync } from "./util/attemptAsync.mjs";
|
|
195
198
|
import { invariant } from "./util/invariant.mjs";
|
|
196
199
|
import "./util/index.mjs";
|
|
197
|
-
export { AbortError, Mutex, Semaphore, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toFilled, toMerged, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
|
200
|
+
export { AbortError, Mutex, Semaphore, TimeoutError, after, allKeyed, ary, invariant as assert, asyncNoop, at, attempt, attemptAsync, before, camelCase, capitalize, cartesianProduct, chunk, chunkBy, clamp, clone, cloneDeep, cloneDeepWith, combinations, compact, constantCase, countBy, curry, curryRight, debounce, deburr, delay, difference, differenceBy, differenceWith, drop, dropRight, dropRightWhile, dropWhile, escape, escapeRegExp, fill, filterAsync, findKey, flatMap, flatMapAsync, flatMapDeep, flatten, flattenDeep, flattenObject, flow, flowRight, forEachAsync, forEachRight, groupBy, head, identity, inRange, initial, intersection, intersectionBy, intersectionWith, invariant, invert, isArrayBuffer, isBlob, isBoolean, isBrowser, isBuffer, isDate, isEmptyObject, isEqual, isEqualWith, isError, isFile, isFunction, isIterable, isJSON, isJSONArray, isJSONObject, isJSONValue, isLength, isMap, isNil, isNode, isNotNil, isNull, isNumber, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isString, isSubset, isSubsetWith, isSymbol, isTypedArray, isUndefined, isWeakMap, isWeakSet, kebabCase, keyBy, last, limitAsync, lowerCase, lowerFirst, mapAsync, mapKeys, mapValues, maxBy, mean, meanBy, median, medianBy, memoize, merge, mergeWith, minBy, negate, noop, omit, omitBy, once, orderBy, pad, partial, partialRight, partition, pascalCase, percentile, pick, pickBy, pull, pullAt, random, randomInt, range, rangeRight, reduceAsync, remove, rest, retry, reverseString, round, sample, sampleSize, shuffle, snakeCase, sortBy, sortKeys, spread, startCase, sum, sumBy, tail, take, takeRight, takeRightWhile, takeWhile, throttle, timeout, toCamelCaseKeys, toConstantCaseKeys, toFilled, toKebabCaseKeys, toMerged, toPascalCaseKeys, toSnakeCaseKeys, trim, trimEnd, trimStart, unary, unescape, union, unionBy, unionWith, uniq, uniqBy, uniqWith, unzip, unzipWith, upperCase, upperFirst, windowed, withTimeout, without, words, xor, xorBy, xorWith, zip, zipObject, zipWith };
|
package/dist/object/index.d.mts
CHANGED
|
@@ -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 };
|
package/dist/object/index.d.ts
CHANGED
|
@@ -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 };
|
package/dist/object/index.js
CHANGED
|
@@ -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;
|
package/dist/object/index.mjs
CHANGED
|
@@ -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 };
|