es-toolkit 1.26.1 → 1.27.0-dev.874

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 (109) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_chunk/{sumBy-RVppiV.js → rangeRight-w3WrXN.js} +2 -14
  3. package/dist/_chunk/{toMerged-wNz52b.js → toMerged-CPY8Ug.js} +7 -1
  4. package/dist/_chunk/{upperFirst-BUECmK.js → upperFirst-DK_rTF.js} +23 -23
  5. package/dist/_chunk/{zipWith-Dkv3D1.js → zipWith-Bb2eZI.js} +19 -5
  6. package/dist/array/at.mjs +7 -2
  7. package/dist/array/index.d.mts +1 -0
  8. package/dist/array/index.d.ts +1 -0
  9. package/dist/array/index.js +2 -1
  10. package/dist/array/index.mjs +1 -0
  11. package/dist/array/isSubsetWith.d.mts +33 -0
  12. package/dist/array/isSubsetWith.d.ts +33 -0
  13. package/dist/array/isSubsetWith.mjs +7 -0
  14. package/dist/array/without.mjs +3 -2
  15. package/dist/array/zip.mjs +6 -1
  16. package/dist/browser.global.js +1 -1
  17. package/dist/browser.global.js.map +1 -1
  18. package/dist/compat/_internal/flattenArrayLike.mjs +17 -0
  19. package/dist/compat/_internal/isPrototype.mjs +7 -0
  20. package/dist/compat/_internal/toArray.mjs +5 -0
  21. package/dist/compat/array/chunk.mjs +2 -1
  22. package/dist/compat/array/difference.mjs +2 -1
  23. package/dist/compat/array/differenceBy.d.mts +82 -0
  24. package/dist/compat/array/differenceBy.d.ts +82 -0
  25. package/dist/compat/array/differenceBy.mjs +20 -0
  26. package/dist/compat/array/drop.mjs +2 -1
  27. package/dist/compat/array/dropRight.mjs +2 -1
  28. package/dist/compat/array/dropWhile.mjs +2 -1
  29. package/dist/compat/array/findLastIndex.mjs +2 -1
  30. package/dist/compat/array/forEach.d.mts +106 -0
  31. package/dist/compat/array/forEach.d.ts +106 -0
  32. package/dist/compat/array/forEach.mjs +21 -0
  33. package/dist/compat/array/head.mjs +2 -1
  34. package/dist/compat/array/last.mjs +2 -1
  35. package/dist/compat/array/sample.mjs +2 -1
  36. package/dist/compat/array/tail.mjs +2 -1
  37. package/dist/compat/array/take.mjs +2 -1
  38. package/dist/compat/array/takeRight.mjs +2 -1
  39. package/dist/compat/array/union.d.mts +30 -0
  40. package/dist/compat/array/union.d.ts +30 -0
  41. package/dist/compat/array/union.mjs +11 -0
  42. package/dist/compat/array/uniqBy.d.mts +60 -0
  43. package/dist/compat/array/uniqBy.d.ts +60 -0
  44. package/dist/compat/array/uniqBy.mjs +25 -0
  45. package/dist/compat/array/unzip.d.mts +16 -0
  46. package/dist/compat/array/unzip.d.ts +16 -0
  47. package/dist/compat/array/unzip.mjs +14 -0
  48. package/dist/compat/array/zip.d.mts +134 -0
  49. package/dist/compat/array/zip.d.ts +134 -0
  50. package/dist/compat/array/zip.mjs +11 -0
  51. package/dist/compat/index.d.mts +15 -8
  52. package/dist/compat/index.d.ts +15 -8
  53. package/dist/compat/index.js +312 -104
  54. package/dist/compat/index.mjs +15 -8
  55. package/dist/compat/math/sum.d.mts +37 -0
  56. package/dist/compat/math/sum.d.ts +37 -0
  57. package/dist/compat/math/sum.mjs +7 -0
  58. package/dist/compat/math/sumBy.d.mts +64 -0
  59. package/dist/compat/math/sumBy.d.ts +64 -0
  60. package/dist/compat/math/sumBy.mjs +20 -0
  61. package/dist/compat/predicate/isEmpty.d.mts +78 -0
  62. package/dist/compat/predicate/isEmpty.d.ts +78 -0
  63. package/dist/compat/predicate/isEmpty.mjs +33 -0
  64. package/dist/compat/string/replace.d.mts +17 -0
  65. package/dist/compat/string/replace.d.ts +17 -0
  66. package/dist/compat/string/replace.mjs +10 -0
  67. package/dist/compat/string/startCase.mjs +4 -4
  68. package/dist/compat/util/iteratee.d.mts +44 -0
  69. package/dist/compat/util/iteratee.d.ts +44 -0
  70. package/dist/compat/util/iteratee.mjs +28 -0
  71. package/dist/compat/util/toPath.mjs +56 -25
  72. package/dist/index.d.mts +3 -0
  73. package/dist/index.d.ts +3 -0
  74. package/dist/index.js +17 -14
  75. package/dist/index.mjs +3 -0
  76. package/dist/math/index.js +19 -11
  77. package/dist/math/range.mjs +1 -4
  78. package/dist/math/rangeRight.mjs +1 -4
  79. package/dist/math/sumBy.mjs +5 -4
  80. package/dist/object/cloneDeep.mjs +1 -1
  81. package/dist/object/findKey.d.mts +21 -0
  82. package/dist/object/findKey.d.ts +21 -0
  83. package/dist/object/findKey.mjs +6 -0
  84. package/dist/object/index.d.mts +1 -0
  85. package/dist/object/index.d.ts +1 -0
  86. package/dist/object/index.js +2 -1
  87. package/dist/object/index.mjs +1 -0
  88. package/dist/object/mapKeys.d.mts +4 -5
  89. package/dist/object/mapKeys.d.ts +4 -5
  90. package/dist/object/mergeWith.d.mts +1 -1
  91. package/dist/object/mergeWith.d.ts +1 -1
  92. package/dist/object/toMerged.d.mts +1 -1
  93. package/dist/object/toMerged.d.ts +1 -1
  94. package/dist/string/camelCase.mjs +4 -4
  95. package/dist/string/constantCase.mjs +3 -3
  96. package/dist/string/index.d.mts +1 -0
  97. package/dist/string/index.d.ts +1 -0
  98. package/dist/string/index.js +3 -2
  99. package/dist/string/index.mjs +1 -0
  100. package/dist/string/kebabCase.mjs +3 -3
  101. package/dist/string/lowerCase.mjs +3 -3
  102. package/dist/string/pascalCase.mjs +3 -3
  103. package/dist/string/snakeCase.mjs +3 -3
  104. package/dist/string/startCase.mjs +4 -4
  105. package/dist/string/upperCase.mjs +5 -5
  106. package/dist/string/words.d.mts +20 -0
  107. package/dist/string/words.d.ts +20 -0
  108. package/dist/string/{_internal/getWords.mjs → words.mjs} +2 -2
  109. package/package.json +1 -1
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Returns a `identity` function when `value` is `null` or `undefined`.
3
+ *
4
+ * @param {null} [value] - The value to convert to an iteratee.
5
+ * @returns {<T>(value: T) => T} - Returns a `identity` function.
6
+ *
7
+ * @example
8
+ * const func = iteratee();
9
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [{ a: 1 }, { a: 2 }, { a: 3 }]
10
+ */
11
+ declare function iteratee(value?: null): <T>(value: T) => T;
12
+ /**
13
+ * Returns a given `func` function when `value` is a `function`.
14
+ *
15
+ * @template {(...args: any[]) => unknown} F - The function type.
16
+ * @param {F} func - The function to return.
17
+ * @returns {F} - Returns the given function.
18
+ *
19
+ * @example
20
+ * const func = iteratee((object) => object.a);
21
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
22
+ */
23
+ declare function iteratee<F extends (...args: any[]) => unknown>(func: F): F;
24
+ /**
25
+ * Creates a function that invokes `value` with the arguments of the created function.
26
+ *
27
+ * The created function returns the property value for a given element.
28
+ *
29
+ * @param {symbol | number | string | object} value - The value to convert to an iteratee.
30
+ * @returns {(...args: any[]) => any} - Returns the new iteratee function.
31
+ *
32
+ * @example
33
+ * const func = iteratee('a');
34
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].map(func) // => [1, 2, 3]
35
+ *
36
+ * const func = iteratee({ a: 1 });
37
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].find(func) // => { a: 1 }
38
+ *
39
+ * const func = iteratee(['a', 1]);
40
+ * [{ a: 1 }, { a: 2 }, { a: 3 }].find(func) // => { a: 1 }
41
+ */
42
+ declare function iteratee(value: symbol | number | string | object): (...args: any[]) => any;
43
+
44
+ export { iteratee };
@@ -0,0 +1,28 @@
1
+ import { identity } from '../../function/identity.mjs';
2
+ import { property } from '../object/property.mjs';
3
+ import { matches } from '../predicate/matches.mjs';
4
+ import { matchesProperty } from '../predicate/matchesProperty.mjs';
5
+
6
+ function iteratee(value) {
7
+ if (value == null) {
8
+ return identity;
9
+ }
10
+ switch (typeof value) {
11
+ case 'function': {
12
+ return value;
13
+ }
14
+ case 'object': {
15
+ if (Array.isArray(value) && value.length === 2) {
16
+ return matchesProperty(value[0], value[1]);
17
+ }
18
+ return matches(value);
19
+ }
20
+ case 'string':
21
+ case 'symbol':
22
+ case 'number': {
23
+ return property(value);
24
+ }
25
+ }
26
+ }
27
+
28
+ export { iteratee };
@@ -1,34 +1,65 @@
1
- const DOTS_KEY = /^[\w.]+$/g;
2
- const ESCAPE_REGEXP = /\\(\\)?/g;
3
- const PROPERTY_REGEXP = RegExp('[^.[\\]]+' +
4
- '|' +
5
- '\\[(?:' +
6
- '([^"\'][^[]*)' +
7
- '|' +
8
- '(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
9
- ')\\]' +
10
- '|' +
11
- '(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
12
1
  function toPath(deepKey) {
13
- if (DOTS_KEY.test(deepKey)) {
14
- return deepKey.split('.');
15
- }
16
2
  const result = [];
17
- if (deepKey[0] === '.') {
3
+ const length = deepKey.length;
4
+ if (length === 0) {
5
+ return result;
6
+ }
7
+ let index = 0;
8
+ let key = '';
9
+ let quoteChar = '';
10
+ let bracket = false;
11
+ if (deepKey.charCodeAt(0) === 46) {
18
12
  result.push('');
13
+ index++;
19
14
  }
20
- const matches = deepKey.matchAll(PROPERTY_REGEXP);
21
- for (const match of matches) {
22
- let key = match[0];
23
- const expr = match[1];
24
- const quote = match[2];
25
- const substr = match[3];
26
- if (quote) {
27
- key = substr.replace(ESCAPE_REGEXP, '$1');
15
+ while (index < length) {
16
+ const char = deepKey[index];
17
+ if (quoteChar) {
18
+ if (char === '\\' && index + 1 < length) {
19
+ index++;
20
+ key += deepKey[index];
21
+ }
22
+ else if (char === quoteChar) {
23
+ quoteChar = '';
24
+ }
25
+ else {
26
+ key += char;
27
+ }
28
28
  }
29
- else if (expr) {
30
- key = expr;
29
+ else if (bracket) {
30
+ if (char === '"' || char === "'") {
31
+ quoteChar = char;
32
+ }
33
+ else if (char === ']') {
34
+ bracket = false;
35
+ result.push(key);
36
+ key = '';
37
+ }
38
+ else {
39
+ key += char;
40
+ }
31
41
  }
42
+ else {
43
+ if (char === '[') {
44
+ bracket = true;
45
+ if (key) {
46
+ result.push(key);
47
+ key = '';
48
+ }
49
+ }
50
+ else if (char === '.') {
51
+ if (key) {
52
+ result.push(key);
53
+ key = '';
54
+ }
55
+ }
56
+ else {
57
+ key += char;
58
+ }
59
+ }
60
+ index++;
61
+ }
62
+ if (key) {
32
63
  result.push(key);
33
64
  }
34
65
  return result;
package/dist/index.d.mts CHANGED
@@ -22,6 +22,7 @@ export { intersection } from './array/intersection.mjs';
22
22
  export { intersectionBy } from './array/intersectionBy.mjs';
23
23
  export { intersectionWith } from './array/intersectionWith.mjs';
24
24
  export { isSubset } from './array/isSubset.mjs';
25
+ export { isSubsetWith } from './array/isSubsetWith.mjs';
25
26
  export { keyBy } from './array/keyBy.mjs';
26
27
  export { last } from './array/last.mjs';
27
28
  export { maxBy } from './array/maxBy.mjs';
@@ -90,6 +91,7 @@ export { sum } from './math/sum.mjs';
90
91
  export { sumBy } from './math/sumBy.mjs';
91
92
  export { clone } from './object/clone.mjs';
92
93
  export { cloneDeep } from './object/cloneDeep.mjs';
94
+ export { findKey } from './object/findKey.mjs';
93
95
  export { flattenObject } from './object/flattenObject.mjs';
94
96
  export { invert } from './object/invert.mjs';
95
97
  export { mapKeys } from './object/mapKeys.mjs';
@@ -148,4 +150,5 @@ export { trimStart } from './string/trimStart.mjs';
148
150
  export { unescape } from './string/unescape.mjs';
149
151
  export { upperCase } from './string/upperCase.mjs';
150
152
  export { upperFirst } from './string/upperFirst.mjs';
153
+ export { words } from './string/words.mjs';
151
154
  export { invariant } from './util/invariant.mjs';
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export { intersection } from './array/intersection.js';
22
22
  export { intersectionBy } from './array/intersectionBy.js';
23
23
  export { intersectionWith } from './array/intersectionWith.js';
24
24
  export { isSubset } from './array/isSubset.js';
25
+ export { isSubsetWith } from './array/isSubsetWith.js';
25
26
  export { keyBy } from './array/keyBy.js';
26
27
  export { last } from './array/last.js';
27
28
  export { maxBy } from './array/maxBy.js';
@@ -90,6 +91,7 @@ export { sum } from './math/sum.js';
90
91
  export { sumBy } from './math/sumBy.js';
91
92
  export { clone } from './object/clone.js';
92
93
  export { cloneDeep } from './object/cloneDeep.js';
94
+ export { findKey } from './object/findKey.js';
93
95
  export { flattenObject } from './object/flattenObject.js';
94
96
  export { invert } from './object/invert.js';
95
97
  export { mapKeys } from './object/mapKeys.js';
@@ -148,4 +150,5 @@ export { trimStart } from './string/trimStart.js';
148
150
  export { unescape } from './string/unescape.js';
149
151
  export { upperCase } from './string/upperCase.js';
150
152
  export { upperFirst } from './string/upperFirst.js';
153
+ export { words } from './string/words.js';
151
154
  export { invariant } from './util/invariant.js';
package/dist/index.js CHANGED
@@ -2,21 +2,21 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('./_chunk/zipWith-Dkv3D1.js');
5
+ const zipWith = require('./_chunk/zipWith-Bb2eZI.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
8
  const unary = require('./_chunk/unary-CcTNuC.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const noop = require('./_chunk/noop-2IwLUk.js');
11
- const sumBy = require('./_chunk/sumBy-RVppiV.js');
11
+ const rangeRight = require('./_chunk/rangeRight-w3WrXN.js');
12
12
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
13
13
  const math_index = require('./math/index.js');
14
- const toMerged = require('./_chunk/toMerged-wNz52b.js');
14
+ const toMerged = require('./_chunk/toMerged-CPY8Ug.js');
15
15
  const object_index = require('./object/index.js');
16
16
  const isWeakSet = require('./_chunk/isWeakSet-D8h8bS.js');
17
17
  const predicate_index = require('./predicate/index.js');
18
18
  const isPlainObject = require('./_chunk/isPlainObject-octpoD.js');
19
- const upperFirst = require('./_chunk/upperFirst-BUECmK.js');
19
+ const upperFirst = require('./_chunk/upperFirst-DK_rTF.js');
20
20
  const string_index = require('./string/index.js');
21
21
  const util_index = require('./util/index.js');
22
22
 
@@ -46,6 +46,7 @@ exports.intersection = zipWith.intersection;
46
46
  exports.intersectionBy = zipWith.intersectionBy;
47
47
  exports.intersectionWith = zipWith.intersectionWith;
48
48
  exports.isSubset = zipWith.isSubset;
49
+ exports.isSubsetWith = zipWith.isSubsetWith;
49
50
  exports.keyBy = zipWith.keyBy;
50
51
  exports.last = zipWith.last;
51
52
  exports.maxBy = zipWith.maxBy;
@@ -102,21 +103,22 @@ exports.curryRight = function_index.curryRight;
102
103
  exports.spread = function_index.spread;
103
104
  exports.throttle = function_index.throttle;
104
105
  exports.noop = noop.noop;
105
- exports.clamp = sumBy.clamp;
106
- exports.inRange = sumBy.inRange;
107
- exports.mean = sumBy.mean;
108
- exports.meanBy = sumBy.meanBy;
109
- exports.median = sumBy.median;
110
- exports.medianBy = sumBy.medianBy;
111
- exports.range = sumBy.range;
112
- exports.rangeRight = sumBy.rangeRight;
113
- exports.sum = sumBy.sum;
114
- exports.sumBy = sumBy.sumBy;
106
+ exports.clamp = rangeRight.clamp;
107
+ exports.inRange = rangeRight.inRange;
108
+ exports.mean = rangeRight.mean;
109
+ exports.meanBy = rangeRight.meanBy;
110
+ exports.median = rangeRight.median;
111
+ exports.medianBy = rangeRight.medianBy;
112
+ exports.range = rangeRight.range;
113
+ exports.rangeRight = rangeRight.rangeRight;
114
+ exports.sum = rangeRight.sum;
115
115
  exports.random = randomInt.random;
116
116
  exports.randomInt = randomInt.randomInt;
117
117
  exports.round = math_index.round;
118
+ exports.sumBy = math_index.sumBy;
118
119
  exports.clone = toMerged.clone;
119
120
  exports.cloneDeep = toMerged.cloneDeep;
121
+ exports.findKey = toMerged.findKey;
120
122
  exports.flattenObject = toMerged.flattenObject;
121
123
  exports.invert = toMerged.invert;
122
124
  exports.mapKeys = toMerged.mapKeys;
@@ -173,5 +175,6 @@ exports.trimStart = upperFirst.trimStart;
173
175
  exports.unescape = upperFirst.unescape;
174
176
  exports.upperCase = upperFirst.upperCase;
175
177
  exports.upperFirst = upperFirst.upperFirst;
178
+ exports.words = upperFirst.words;
176
179
  exports.startCase = string_index.startCase;
177
180
  exports.invariant = util_index.invariant;
package/dist/index.mjs CHANGED
@@ -22,6 +22,7 @@ export { intersection } from './array/intersection.mjs';
22
22
  export { intersectionBy } from './array/intersectionBy.mjs';
23
23
  export { intersectionWith } from './array/intersectionWith.mjs';
24
24
  export { isSubset } from './array/isSubset.mjs';
25
+ export { isSubsetWith } from './array/isSubsetWith.mjs';
25
26
  export { keyBy } from './array/keyBy.mjs';
26
27
  export { last } from './array/last.mjs';
27
28
  export { maxBy } from './array/maxBy.mjs';
@@ -90,6 +91,7 @@ export { sum } from './math/sum.mjs';
90
91
  export { sumBy } from './math/sumBy.mjs';
91
92
  export { clone } from './object/clone.mjs';
92
93
  export { cloneDeep } from './object/cloneDeep.mjs';
94
+ export { findKey } from './object/findKey.mjs';
93
95
  export { flattenObject } from './object/flattenObject.mjs';
94
96
  export { invert } from './object/invert.mjs';
95
97
  export { mapKeys } from './object/mapKeys.mjs';
@@ -148,4 +150,5 @@ export { trimStart } from './string/trimStart.mjs';
148
150
  export { unescape } from './string/unescape.mjs';
149
151
  export { upperCase } from './string/upperCase.mjs';
150
152
  export { upperFirst } from './string/upperFirst.mjs';
153
+ export { words } from './string/words.mjs';
151
154
  export { invariant } from './util/invariant.mjs';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const sumBy = require('../_chunk/sumBy-RVppiV.js');
5
+ const rangeRight = require('../_chunk/rangeRight-w3WrXN.js');
6
6
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
7
7
 
8
8
  function round(value, precision = 0) {
@@ -13,16 +13,24 @@ function round(value, precision = 0) {
13
13
  return Math.round(value * multiplier) / multiplier;
14
14
  }
15
15
 
16
- exports.clamp = sumBy.clamp;
17
- exports.inRange = sumBy.inRange;
18
- exports.mean = sumBy.mean;
19
- exports.meanBy = sumBy.meanBy;
20
- exports.median = sumBy.median;
21
- exports.medianBy = sumBy.medianBy;
22
- exports.range = sumBy.range;
23
- exports.rangeRight = sumBy.rangeRight;
24
- exports.sum = sumBy.sum;
25
- exports.sumBy = sumBy.sumBy;
16
+ function sumBy(items, getValue) {
17
+ let result = 0;
18
+ for (let i = 0; i < items.length; i++) {
19
+ result += getValue(items[i]);
20
+ }
21
+ return result;
22
+ }
23
+
24
+ exports.clamp = rangeRight.clamp;
25
+ exports.inRange = rangeRight.inRange;
26
+ exports.mean = rangeRight.mean;
27
+ exports.meanBy = rangeRight.meanBy;
28
+ exports.median = rangeRight.median;
29
+ exports.medianBy = rangeRight.medianBy;
30
+ exports.range = rangeRight.range;
31
+ exports.rangeRight = rangeRight.rangeRight;
32
+ exports.sum = rangeRight.sum;
26
33
  exports.random = randomInt.random;
27
34
  exports.randomInt = randomInt.randomInt;
28
35
  exports.round = round;
36
+ exports.sumBy = sumBy;
@@ -1,11 +1,8 @@
1
- function range(start, end, step) {
1
+ function range(start, end, step = 1) {
2
2
  if (end == null) {
3
3
  end = start;
4
4
  start = 0;
5
5
  }
6
- if (step == null) {
7
- step = 1;
8
- }
9
6
  if (!Number.isInteger(step) || step === 0) {
10
7
  throw new Error(`The step value must be a non-zero integer.`);
11
8
  }
@@ -1,11 +1,8 @@
1
- function rangeRight(start, end, step) {
1
+ function rangeRight(start, end, step = 1) {
2
2
  if (end == null) {
3
3
  end = start;
4
4
  start = 0;
5
5
  }
6
- if (step == null) {
7
- step = 1;
8
- }
9
6
  if (!Number.isInteger(step) || step === 0) {
10
7
  throw new Error(`The step value must be a non-zero integer.`);
11
8
  }
@@ -1,8 +1,9 @@
1
- import { sum } from './sum.mjs';
2
-
3
1
  function sumBy(items, getValue) {
4
- const nums = items.map(x => getValue(x));
5
- return sum(nums);
2
+ let result = 0;
3
+ for (let i = 0; i < items.length; i++) {
4
+ result += getValue(items[i]);
5
+ }
6
+ return result;
6
7
  }
7
8
 
8
9
  export { sumBy };
@@ -93,7 +93,7 @@ function cloneDeepImpl(obj, stack = new Map()) {
93
93
  return result;
94
94
  }
95
95
  if (typeof obj === 'object' && obj !== null) {
96
- const result = {};
96
+ const result = Object.create(Object.getPrototypeOf(obj));
97
97
  stack.set(obj, result);
98
98
  copyProperties(result, obj, stack);
99
99
  return result;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Finds the key of the first element in the object that satisfies the provided testing function.
3
+ *
4
+ * @param {T} obj - The object to search.
5
+ * @param {(value: T[keyof T], key: keyof T, obj: T) => boolean} predicate - The function to execute on each value in the object. It takes three arguments:
6
+ * - value: The current value being processed in the object.
7
+ * - key: The key of the current value being processed in the object.
8
+ * - obj: The object that findKey was called upon.
9
+ * @returns {keyof T | undefined} The key of the first element in the object that passes the test, or undefined if no element passes.
10
+ *
11
+ * @example
12
+ * const users = {
13
+ * 'barney': { 'age': 36, 'active': true },
14
+ * 'fred': { 'age': 40, 'active': false },
15
+ * 'pebbles': { 'age': 1, 'active': true }
16
+ * };
17
+ * findKey(users, function(o) { return o.age < 40; }); => 'barney'
18
+ */
19
+ declare function findKey<T extends Record<any, any>>(obj: T, predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean): keyof T | undefined;
20
+
21
+ export { findKey };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Finds the key of the first element in the object that satisfies the provided testing function.
3
+ *
4
+ * @param {T} obj - The object to search.
5
+ * @param {(value: T[keyof T], key: keyof T, obj: T) => boolean} predicate - The function to execute on each value in the object. It takes three arguments:
6
+ * - value: The current value being processed in the object.
7
+ * - key: The key of the current value being processed in the object.
8
+ * - obj: The object that findKey was called upon.
9
+ * @returns {keyof T | undefined} The key of the first element in the object that passes the test, or undefined if no element passes.
10
+ *
11
+ * @example
12
+ * const users = {
13
+ * 'barney': { 'age': 36, 'active': true },
14
+ * 'fred': { 'age': 40, 'active': false },
15
+ * 'pebbles': { 'age': 1, 'active': true }
16
+ * };
17
+ * findKey(users, function(o) { return o.age < 40; }); => 'barney'
18
+ */
19
+ declare function findKey<T extends Record<any, any>>(obj: T, predicate: (value: T[keyof T], key: keyof T, obj: T) => boolean): keyof T | undefined;
20
+
21
+ export { findKey };
@@ -0,0 +1,6 @@
1
+ function findKey(obj, predicate) {
2
+ const keys = Object.keys(obj);
3
+ return keys.find(key => predicate(obj[key], key, obj));
4
+ }
5
+
6
+ export { findKey };
@@ -1,5 +1,6 @@
1
1
  export { clone } from './clone.mjs';
2
2
  export { cloneDeep } from './cloneDeep.mjs';
3
+ export { findKey } from './findKey.mjs';
3
4
  export { flattenObject } from './flattenObject.mjs';
4
5
  export { invert } from './invert.mjs';
5
6
  export { mapKeys } from './mapKeys.mjs';
@@ -1,5 +1,6 @@
1
1
  export { clone } from './clone.js';
2
2
  export { cloneDeep } from './cloneDeep.js';
3
+ export { findKey } from './findKey.js';
3
4
  export { flattenObject } from './flattenObject.js';
4
5
  export { invert } from './invert.js';
5
6
  export { mapKeys } from './mapKeys.js';
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const toMerged = require('../_chunk/toMerged-wNz52b.js');
5
+ const toMerged = require('../_chunk/toMerged-CPY8Ug.js');
6
6
 
7
7
  function mergeWith(target, source, merge) {
8
8
  const sourceKeys = Object.keys(source);
@@ -49,6 +49,7 @@ function pick(obj, keys) {
49
49
 
50
50
  exports.clone = toMerged.clone;
51
51
  exports.cloneDeep = toMerged.cloneDeep;
52
+ exports.findKey = toMerged.findKey;
52
53
  exports.flattenObject = toMerged.flattenObject;
53
54
  exports.invert = toMerged.invert;
54
55
  exports.mapKeys = toMerged.mapKeys;
@@ -1,5 +1,6 @@
1
1
  export { clone } from './clone.mjs';
2
2
  export { cloneDeep } from './cloneDeep.mjs';
3
+ export { findKey } from './findKey.mjs';
3
4
  export { flattenObject } from './flattenObject.mjs';
4
5
  export { invert } from './invert.mjs';
5
6
  export { mapKeys } from './mapKeys.mjs';
@@ -3,12 +3,11 @@
3
3
  * by running each own enumerable property of the object through the iteratee function.
4
4
  *
5
5
  * @template T - The type of the object.
6
- * @template K1 - The type of the keys in the object.
7
- * @template K2 - The type of the new keys generated by the iteratee function.
6
+ * @template K - The type of the new keys generated by the iteratee function.
8
7
  *
9
8
  * @param {T} object - The object to iterate over.
10
- * @param {(value: T[K1], key: K1, object: T) => K2} getNewKey - The function invoked per own enumerable property.
11
- * @returns {Record<K2, T[K1]>} - Returns the new mapped object.
9
+ * @param {(value: T[keyof T], key: keyof T, object: T) => K} getNewKey - The function invoked per own enumerable property.
10
+ * @returns {Record<K, T[keyof T]>} - Returns the new mapped object.
12
11
  *
13
12
  * @example
14
13
  * // Example usage:
@@ -16,6 +15,6 @@
16
15
  * const result = mapKeys(obj, (value, key) => key + value);
17
16
  * console.log(result); // { a1: 1, b2: 2 }
18
17
  */
19
- declare function mapKeys<T extends object, K1 extends keyof T, K2 extends PropertyKey>(object: T, getNewKey: (value: T[K1], key: K1, object: T) => K2): Record<K2, T[K1]>;
18
+ declare function mapKeys<T extends Record<PropertyKey, any>, K extends PropertyKey>(object: T, getNewKey: (value: T[keyof T], key: keyof T, object: T) => K): Record<K, T[keyof T]>;
20
19
 
21
20
  export { mapKeys };
@@ -3,12 +3,11 @@
3
3
  * by running each own enumerable property of the object through the iteratee function.
4
4
  *
5
5
  * @template T - The type of the object.
6
- * @template K1 - The type of the keys in the object.
7
- * @template K2 - The type of the new keys generated by the iteratee function.
6
+ * @template K - The type of the new keys generated by the iteratee function.
8
7
  *
9
8
  * @param {T} object - The object to iterate over.
10
- * @param {(value: T[K1], key: K1, object: T) => K2} getNewKey - The function invoked per own enumerable property.
11
- * @returns {Record<K2, T[K1]>} - Returns the new mapped object.
9
+ * @param {(value: T[keyof T], key: keyof T, object: T) => K} getNewKey - The function invoked per own enumerable property.
10
+ * @returns {Record<K, T[keyof T]>} - Returns the new mapped object.
12
11
  *
13
12
  * @example
14
13
  * // Example usage:
@@ -16,6 +15,6 @@
16
15
  * const result = mapKeys(obj, (value, key) => key + value);
17
16
  * console.log(result); // { a1: 1, b2: 2 }
18
17
  */
19
- declare function mapKeys<T extends object, K1 extends keyof T, K2 extends PropertyKey>(object: T, getNewKey: (value: T[K1], key: K1, object: T) => K2): Record<K2, T[K1]>;
18
+ declare function mapKeys<T extends Record<PropertyKey, any>, K extends PropertyKey>(object: T, getNewKey: (value: T[keyof T], key: keyof T, object: T) => K): Record<K, T[keyof T]>;
20
19
 
21
20
  export { mapKeys };
@@ -46,6 +46,6 @@
46
46
  *
47
47
  * expect(result).toEqual({ a: [1, 3], b: [2, 4] });
48
48
  */
49
- declare function mergeWith<T, S>(target: T, source: S, merge: (targetValue: any, sourceValue: any, key: string, target: T, source: S) => any): T & S;
49
+ declare function mergeWith<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S, merge: (targetValue: any, sourceValue: any, key: string, target: T, source: S) => any): T & S;
50
50
 
51
51
  export { mergeWith };
@@ -46,6 +46,6 @@
46
46
  *
47
47
  * expect(result).toEqual({ a: [1, 3], b: [2, 4] });
48
48
  */
49
- declare function mergeWith<T, S>(target: T, source: S, merge: (targetValue: any, sourceValue: any, key: string, target: T, source: S) => any): T & S;
49
+ declare function mergeWith<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S, merge: (targetValue: any, sourceValue: any, key: string, target: T, source: S) => any): T & S;
50
50
 
51
51
  export { mergeWith };
@@ -40,6 +40,6 @@
40
40
  * console.log(result);
41
41
  * // Output: { a: [1, 2, 3] }
42
42
  */
43
- declare function toMerged<T, S>(target: T, source: S): T & S;
43
+ declare function toMerged<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
44
44
 
45
45
  export { toMerged };
@@ -40,6 +40,6 @@
40
40
  * console.log(result);
41
41
  * // Output: { a: [1, 2, 3] }
42
42
  */
43
- declare function toMerged<T, S>(target: T, source: S): T & S;
43
+ declare function toMerged<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
44
44
 
45
45
  export { toMerged };
@@ -1,12 +1,12 @@
1
- import { getWords } from './_internal/getWords.mjs';
2
1
  import { capitalize } from './capitalize.mjs';
2
+ import { words } from './words.mjs';
3
3
 
4
4
  function camelCase(str) {
5
- const words = getWords(str);
6
- if (words.length === 0) {
5
+ const words$1 = words(str);
6
+ if (words$1.length === 0) {
7
7
  return '';
8
8
  }
9
- const [first, ...rest] = words;
9
+ const [first, ...rest] = words$1;
10
10
  return `${first.toLowerCase()}${rest.map(word => capitalize(word)).join('')}`;
11
11
  }
12
12
 
@@ -1,8 +1,8 @@
1
- import { getWords } from './_internal/getWords.mjs';
1
+ import { words } from './words.mjs';
2
2
 
3
3
  function constantCase(str) {
4
- const words = getWords(str);
5
- return words.map(word => word.toUpperCase()).join('_');
4
+ const words$1 = words(str);
5
+ return words$1.map(word => word.toUpperCase()).join('_');
6
6
  }
7
7
 
8
8
  export { constantCase };
@@ -17,3 +17,4 @@ export { trimStart } from './trimStart.mjs';
17
17
  export { unescape } from './unescape.mjs';
18
18
  export { upperCase } from './upperCase.mjs';
19
19
  export { upperFirst } from './upperFirst.mjs';
20
+ export { words } from './words.mjs';
@@ -17,3 +17,4 @@ export { trimStart } from './trimStart.js';
17
17
  export { unescape } from './unescape.js';
18
18
  export { upperCase } from './upperCase.js';
19
19
  export { upperFirst } from './upperFirst.js';
20
+ export { words } from './words.js';
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const upperFirst = require('../_chunk/upperFirst-BUECmK.js');
5
+ const upperFirst = require('../_chunk/upperFirst-DK_rTF.js');
6
6
 
7
7
  function startCase(str) {
8
- const words = upperFirst.getWords(str.trim());
8
+ const words = upperFirst.words(str.trim());
9
9
  let result = '';
10
10
  for (let i = 0; i < words.length; i++) {
11
11
  const word = words[i];
@@ -35,4 +35,5 @@ exports.trimStart = upperFirst.trimStart;
35
35
  exports.unescape = upperFirst.unescape;
36
36
  exports.upperCase = upperFirst.upperCase;
37
37
  exports.upperFirst = upperFirst.upperFirst;
38
+ exports.words = upperFirst.words;
38
39
  exports.startCase = startCase;