es-toolkit 1.33.0 → 1.34.0-dev.1075

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 (66) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/_chunk/invariant-BfGFfr.js +21 -0
  3. package/dist/_chunk/{isWeakSet-TIM260.js → isWeakSet-C2NpfO.js} +10 -0
  4. package/dist/browser.global.js +1 -1
  5. package/dist/browser.global.js.map +1 -1
  6. package/dist/compat/_internal/assignValue.mjs +10 -0
  7. package/dist/compat/_internal/isKey.mjs +1 -1
  8. package/dist/compat/_internal/toKey.mjs +4 -1
  9. package/dist/compat/array/filter.mjs +14 -31
  10. package/dist/compat/array/intersectionWith.mjs +0 -1
  11. package/dist/compat/array/map.d.mts +1 -1
  12. package/dist/compat/array/map.d.ts +1 -1
  13. package/dist/compat/array/reject.d.mts +117 -0
  14. package/dist/compat/array/reject.d.ts +117 -0
  15. package/dist/compat/array/reject.mjs +9 -0
  16. package/dist/compat/array/sortedIndexOf.d.mts +34 -0
  17. package/dist/compat/array/sortedIndexOf.d.ts +34 -0
  18. package/dist/compat/array/sortedIndexOf.mjs +15 -0
  19. package/dist/compat/index.d.mts +9 -3
  20. package/dist/compat/index.d.ts +9 -3
  21. package/dist/compat/index.js +176 -93
  22. package/dist/compat/index.mjs +9 -3
  23. package/dist/compat/math/add.mjs +17 -0
  24. package/dist/compat/math/divide.mjs +0 -1
  25. package/dist/compat/math/mean.d.mts +16 -0
  26. package/dist/compat/math/mean.d.ts +16 -0
  27. package/dist/compat/math/mean.mjs +8 -0
  28. package/dist/compat/math/meanBy.d.mts +25 -0
  29. package/dist/compat/math/meanBy.d.ts +25 -0
  30. package/dist/compat/math/meanBy.mjs +11 -0
  31. package/dist/compat/math/minBy.d.mts +31 -0
  32. package/dist/compat/math/minBy.d.ts +31 -0
  33. package/dist/compat/math/minBy.mjs +11 -0
  34. package/dist/compat/math/subtract.mjs +17 -0
  35. package/dist/compat/object/functionsIn.d.mts +20 -0
  36. package/dist/compat/object/functionsIn.d.ts +20 -0
  37. package/dist/compat/object/functionsIn.mjs +16 -0
  38. package/dist/compat/object/set.mjs +21 -8
  39. package/dist/compat/util/invoke.mjs +1 -1
  40. package/dist/compat/util/stubObject.d.mts +1 -1
  41. package/dist/compat/util/stubObject.d.ts +1 -1
  42. package/dist/index.d.mts +4 -0
  43. package/dist/index.d.ts +4 -0
  44. package/dist/index.js +7 -2
  45. package/dist/index.mjs +4 -0
  46. package/dist/predicate/index.d.mts +2 -0
  47. package/dist/predicate/index.d.ts +2 -0
  48. package/dist/predicate/index.js +3 -1
  49. package/dist/predicate/index.mjs +2 -0
  50. package/dist/predicate/isBrowser.d.mts +17 -0
  51. package/dist/predicate/isBrowser.d.ts +17 -0
  52. package/dist/predicate/isBrowser.mjs +5 -0
  53. package/dist/predicate/isNode.d.mts +17 -0
  54. package/dist/predicate/isNode.d.ts +17 -0
  55. package/dist/predicate/isNode.mjs +5 -0
  56. package/dist/util/attempt.d.mts +42 -0
  57. package/dist/util/attempt.d.ts +42 -0
  58. package/dist/util/attempt.mjs +10 -0
  59. package/dist/util/attemptAsync.d.mts +35 -0
  60. package/dist/util/attemptAsync.d.ts +35 -0
  61. package/dist/util/attemptAsync.mjs +11 -0
  62. package/dist/util/index.d.mts +2 -0
  63. package/dist/util/index.d.ts +2 -0
  64. package/dist/util/index.js +11 -5
  65. package/dist/util/index.mjs +2 -0
  66. package/package.json +7 -5
@@ -11,10 +11,10 @@ const range$1 = require('../_chunk/range-HnEIT7.js');
11
11
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
12
12
  const toMerged = require('../_chunk/toMerged-CwnQF6.js');
13
13
  const isPlainObject$1 = require('../_chunk/isPlainObject-Xaozpc.js');
14
- const isWeakSet$1 = require('../_chunk/isWeakSet-TIM260.js');
14
+ const isWeakSet$1 = require('../_chunk/isWeakSet-C2NpfO.js');
15
15
  const promise_index = require('../promise/index.js');
16
16
  const upperFirst$1 = require('../_chunk/upperFirst-nA5L7X.js');
17
- const util_index = require('../util/index.js');
17
+ const invariant = require('../_chunk/invariant-BfGFfr.js');
18
18
 
19
19
  function castArray(value) {
20
20
  if (arguments.length === 0) {
@@ -103,7 +103,10 @@ function isDeepKey(key) {
103
103
  }
104
104
 
105
105
  function toKey(value) {
106
- if (Object.is(value, -0)) {
106
+ if (typeof value === 'string' || typeof value === 'symbol') {
107
+ return value;
108
+ }
109
+ if (Object.is(value.valueOf(), -0)) {
107
110
  return '-0';
108
111
  }
109
112
  return value.toString();
@@ -695,37 +698,22 @@ function filter(source, predicate) {
695
698
  if (!source) {
696
699
  return [];
697
700
  }
698
- if (!predicate) {
699
- predicate = unary.identity;
700
- }
701
701
  const collection = isArray(source) ? source : Object.values(source);
702
- switch (typeof predicate) {
703
- case 'function': {
704
- if (!Array.isArray(source)) {
705
- const result = [];
706
- const keys = Object.keys(source);
707
- for (let i = 0; i < keys.length; i++) {
708
- const key = keys[i];
709
- const value = source[key];
710
- if (predicate(value, key, source)) {
711
- result.push(value);
712
- }
713
- }
714
- return result;
702
+ predicate = iteratee(predicate);
703
+ if (!Array.isArray(source)) {
704
+ const result = [];
705
+ const keys = Object.keys(source);
706
+ const length = isArrayLike(source) ? source.length : keys.length;
707
+ for (let i = 0; i < length; i++) {
708
+ const key = keys[i];
709
+ const value = source[key];
710
+ if (predicate(value, key, source)) {
711
+ result.push(value);
715
712
  }
716
- return collection.filter(predicate);
717
- }
718
- case 'object': {
719
- return isArray(predicate)
720
- ? collection.filter(matchesProperty(predicate[0], predicate[1]))
721
- : collection.filter(matches(predicate));
722
- }
723
- case 'symbol':
724
- case 'number':
725
- case 'string': {
726
- return collection.filter(property(predicate));
727
713
  }
714
+ return result;
728
715
  }
716
+ return collection.filter(predicate);
729
717
  }
730
718
 
731
719
  function find(source, _doesMatch, fromIndex = 0) {
@@ -1014,7 +1002,6 @@ function uniq(arr) {
1014
1002
  }
1015
1003
 
1016
1004
  function intersectionWith(firstArr, ...otherArrs) {
1017
- console.log(firstArr);
1018
1005
  if (firstArr == null) {
1019
1006
  return [];
1020
1007
  }
@@ -1147,7 +1134,7 @@ function isKey(value, object) {
1147
1134
  return true;
1148
1135
  }
1149
1136
  return ((typeof value === 'string' && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value))) ||
1150
- (object != null));
1137
+ (object != null && Object.hasOwn(object, value)));
1151
1138
  }
1152
1139
 
1153
1140
  function orderBy(collection, criteria, orders, guard) {
@@ -1312,6 +1299,19 @@ function reduceRight(collection, iteratee = unary.identity, accumulator) {
1312
1299
  return accumulator;
1313
1300
  }
1314
1301
 
1302
+ function negate(func) {
1303
+ if (typeof func !== 'function') {
1304
+ throw new TypeError('Expected a function');
1305
+ }
1306
+ return function (...args) {
1307
+ return !func.apply(this, args);
1308
+ };
1309
+ }
1310
+
1311
+ function reject(source, predicate) {
1312
+ return filter(source, negate(iteratee(predicate)));
1313
+ }
1314
+
1315
1315
  function remove(arr, shouldRemoveElement) {
1316
1316
  return zipWith.remove(arr, iteratee(shouldRemoveElement));
1317
1317
  }
@@ -1516,6 +1516,17 @@ function sortedIndex(array, value) {
1516
1516
  return sortedIndexBy(array, value, value => value);
1517
1517
  }
1518
1518
 
1519
+ function sortedIndexOf(array, value) {
1520
+ if (!array?.length) {
1521
+ return -1;
1522
+ }
1523
+ const index = sortedIndex(array, value);
1524
+ if (index < array.length && isWeakSet$1.eq(array[index], value)) {
1525
+ return index;
1526
+ }
1527
+ return -1;
1528
+ }
1529
+
1519
1530
  function tail(arr) {
1520
1531
  if (!isArrayLike(arr)) {
1521
1532
  return [];
@@ -1585,19 +1596,35 @@ function zip(...arrays) {
1585
1596
  return zipWith.zip(...arrays.filter(group => isArrayLikeObject(group)));
1586
1597
  }
1587
1598
 
1599
+ const assignValue = (object, key, value) => {
1600
+ const objValue = object[key];
1601
+ if (!(Object.hasOwn(object, key) && isWeakSet$1.eq(objValue, value)) || (value === undefined && !(key in object))) {
1602
+ object[key] = value;
1603
+ }
1604
+ };
1605
+
1588
1606
  function set(obj, path, value) {
1589
- const resolvedPath = Array.isArray(path) ? path : typeof path === 'string' ? toPath(path) : [path];
1607
+ if (obj == null && !isObject(obj)) {
1608
+ return obj;
1609
+ }
1610
+ const resolvedPath = isKey(path, obj)
1611
+ ? [path]
1612
+ : Array.isArray(path)
1613
+ ? path
1614
+ : typeof path === 'string'
1615
+ ? toPath(path)
1616
+ : [path];
1590
1617
  let current = obj;
1591
- for (let i = 0; i < resolvedPath.length - 1; i++) {
1592
- const key = resolvedPath[i];
1593
- const nextKey = resolvedPath[i + 1];
1594
- if (current[key] == null) {
1595
- current[key] = isIndex(nextKey) ? [] : {};
1596
- }
1618
+ for (let i = 0; i < resolvedPath.length && current != null; i++) {
1619
+ const key = toKey(resolvedPath[i]);
1620
+ let newValue = value;
1621
+ if (i !== resolvedPath.length - 1) {
1622
+ const objValue = current[key];
1623
+ newValue = isObject(objValue) ? objValue : isIndex(resolvedPath[i + 1]) ? [] : {};
1624
+ }
1625
+ assignValue(current, key, newValue);
1597
1626
  current = current[key];
1598
1627
  }
1599
- const lastKey = resolvedPath[resolvedPath.length - 1];
1600
- current[lastKey] = value;
1601
1628
  return obj;
1602
1629
  }
1603
1630
 
@@ -1919,15 +1946,6 @@ function flowRight(...funcs) {
1919
1946
  return unary.flowRight(...flattenFuncs);
1920
1947
  }
1921
1948
 
1922
- function negate(func) {
1923
- if (typeof func !== 'function') {
1924
- throw new TypeError('Expected a function');
1925
- }
1926
- return function (...args) {
1927
- return !func.apply(this, args);
1928
- };
1929
- }
1930
-
1931
1949
  function nthArg(n = 0) {
1932
1950
  return function (...args) {
1933
1951
  return args.at(toInteger(n));
@@ -1981,7 +1999,35 @@ function throttle(func, throttleMs = 0, options = {}) {
1981
1999
  });
1982
2000
  }
1983
2001
 
2002
+ function toString(value) {
2003
+ if (value == null) {
2004
+ return '';
2005
+ }
2006
+ if (Array.isArray(value)) {
2007
+ return value.map(toString).join(',');
2008
+ }
2009
+ const result = String(value);
2010
+ if (result === '0' && Object.is(Number(value), -0)) {
2011
+ return '-0';
2012
+ }
2013
+ return result;
2014
+ }
2015
+
1984
2016
  function add(value, other) {
2017
+ if (value === undefined && other === undefined) {
2018
+ return 0;
2019
+ }
2020
+ if (value === undefined || other === undefined) {
2021
+ return value ?? other;
2022
+ }
2023
+ if (typeof value === 'string' || typeof other === 'string') {
2024
+ value = toString(value);
2025
+ other = toString(other);
2026
+ }
2027
+ else {
2028
+ value = toNumber(value);
2029
+ other = toNumber(other);
2030
+ }
1985
2031
  return value + other;
1986
2032
  }
1987
2033
 
@@ -2017,22 +2063,7 @@ function clamp(value, bound1, bound2) {
2017
2063
  return range$1.clamp(value, bound1, bound2);
2018
2064
  }
2019
2065
 
2020
- function toString(value) {
2021
- if (value == null) {
2022
- return '';
2023
- }
2024
- if (Array.isArray(value)) {
2025
- return value.map(toString).join(',');
2026
- }
2027
- const result = String(value);
2028
- if (result === '0' && Object.is(Number(value), -0)) {
2029
- return '-0';
2030
- }
2031
- return result;
2032
- }
2033
-
2034
2066
  function divide(value, other) {
2035
- console.log(value, other);
2036
2067
  if (value === undefined && other === undefined) {
2037
2068
  return 1;
2038
2069
  }
@@ -2099,6 +2130,44 @@ function maxBy(items, iteratee$1) {
2099
2130
  return zipWith.maxBy(Array.from(items), iteratee(iteratee$1));
2100
2131
  }
2101
2132
 
2133
+ function sumBy(array, iteratee$1) {
2134
+ if (!array || !array.length) {
2135
+ return 0;
2136
+ }
2137
+ if (iteratee$1 != null) {
2138
+ iteratee$1 = iteratee(iteratee$1);
2139
+ }
2140
+ let result = undefined;
2141
+ for (let i = 0; i < array.length; i++) {
2142
+ const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
2143
+ if (current !== undefined) {
2144
+ if (result === undefined) {
2145
+ result = current;
2146
+ }
2147
+ else {
2148
+ result += current;
2149
+ }
2150
+ }
2151
+ }
2152
+ return result;
2153
+ }
2154
+
2155
+ function sum(array) {
2156
+ return sumBy(array);
2157
+ }
2158
+
2159
+ function mean(nums) {
2160
+ const length = nums ? nums.length : 0;
2161
+ return length === 0 ? NaN : sum(nums) / length;
2162
+ }
2163
+
2164
+ function meanBy(items, iteratee$1) {
2165
+ if (items == null) {
2166
+ return NaN;
2167
+ }
2168
+ return range$1.meanBy(Array.from(items), iteratee(iteratee$1));
2169
+ }
2170
+
2102
2171
  function min(items = []) {
2103
2172
  let minElement = items[0];
2104
2173
  let min = undefined;
@@ -2112,6 +2181,13 @@ function min(items = []) {
2112
2181
  return minElement;
2113
2182
  }
2114
2183
 
2184
+ function minBy(items, iteratee$1) {
2185
+ if (items == null) {
2186
+ return undefined;
2187
+ }
2188
+ return zipWith.minBy(Array.from(items), iteratee(iteratee$1));
2189
+ }
2190
+
2115
2191
  function multiply(value, other) {
2116
2192
  if (value === undefined && other === undefined) {
2117
2193
  return 1;
@@ -2251,33 +2327,21 @@ function round(number, precision = 0) {
2251
2327
  }
2252
2328
 
2253
2329
  function subtract(value, other) {
2254
- return value - other;
2255
- }
2256
-
2257
- function sumBy(array, iteratee$1) {
2258
- if (!array || !array.length) {
2330
+ if (value === undefined && other === undefined) {
2259
2331
  return 0;
2260
2332
  }
2261
- if (iteratee$1 != null) {
2262
- iteratee$1 = iteratee(iteratee$1);
2333
+ if (value === undefined || other === undefined) {
2334
+ return value ?? other;
2263
2335
  }
2264
- let result = undefined;
2265
- for (let i = 0; i < array.length; i++) {
2266
- const current = iteratee$1 ? iteratee$1(array[i]) : array[i];
2267
- if (current !== undefined) {
2268
- if (result === undefined) {
2269
- result = current;
2270
- }
2271
- else {
2272
- result += current;
2273
- }
2274
- }
2336
+ if (typeof value === 'string' || typeof other === 'string') {
2337
+ value = toString(value);
2338
+ other = toString(other);
2275
2339
  }
2276
- return result;
2277
- }
2278
-
2279
- function sum(array) {
2280
- return sumBy(array);
2340
+ else {
2341
+ value = toNumber(value);
2342
+ other = toNumber(other);
2343
+ }
2344
+ return value - other;
2281
2345
  }
2282
2346
 
2283
2347
  function isPrototype(value) {
@@ -2416,6 +2480,19 @@ function fromPairs(pairs) {
2416
2480
  return result;
2417
2481
  }
2418
2482
 
2483
+ function functionsIn(object) {
2484
+ if (object == null) {
2485
+ return [];
2486
+ }
2487
+ const result = [];
2488
+ for (const key in object) {
2489
+ if (isWeakSet$1.isFunction(object[key])) {
2490
+ result.push(key);
2491
+ }
2492
+ }
2493
+ return result;
2494
+ }
2495
+
2419
2496
  function invertBy(object, iteratee) {
2420
2497
  const result = {};
2421
2498
  if (isWeakSet$1.isNil(object)) {
@@ -3219,7 +3296,7 @@ function invokeImpl(object, path, args) {
3219
3296
  return undefined;
3220
3297
  }
3221
3298
  let lastKey = last(path);
3222
- let lastValue = lastKey?.valueOf();
3299
+ const lastValue = lastKey?.valueOf();
3223
3300
  if (typeof lastValue === 'number') {
3224
3301
  lastKey = toKey(lastValue);
3225
3302
  }
@@ -3349,7 +3426,6 @@ exports.initial = zipWith.initial;
3349
3426
  exports.isSubset = zipWith.isSubset;
3350
3427
  exports.isSubsetWith = zipWith.isSubsetWith;
3351
3428
  exports.keyBy = zipWith.keyBy;
3352
- exports.minBy = zipWith.minBy;
3353
3429
  exports.partition = zipWith.partition;
3354
3430
  exports.pullAt = zipWith.pullAt;
3355
3431
  exports.sampleSize = zipWith.sampleSize;
@@ -3377,8 +3453,6 @@ exports.partialRight = unary.partialRight;
3377
3453
  exports.retry = unary.retry;
3378
3454
  exports.unary = unary.unary;
3379
3455
  exports.noop = noop.noop;
3380
- exports.mean = range$1.mean;
3381
- exports.meanBy = range$1.meanBy;
3382
3456
  exports.median = range$1.median;
3383
3457
  exports.medianBy = range$1.medianBy;
3384
3458
  exports.randomInt = randomInt.randomInt;
@@ -3391,6 +3465,7 @@ exports.toMerged = toMerged.toMerged;
3391
3465
  exports.isPrimitive = isPlainObject$1.isPrimitive;
3392
3466
  exports.eq = isWeakSet$1.eq;
3393
3467
  exports.isBlob = isWeakSet$1.isBlob;
3468
+ exports.isBrowser = isWeakSet$1.isBrowser;
3394
3469
  exports.isEqual = isWeakSet$1.isEqual;
3395
3470
  exports.isFile = isWeakSet$1.isFile;
3396
3471
  exports.isFunction = isWeakSet$1.isFunction;
@@ -3399,6 +3474,7 @@ exports.isJSONArray = isWeakSet$1.isJSONArray;
3399
3474
  exports.isJSONObject = isWeakSet$1.isJSONObject;
3400
3475
  exports.isJSONValue = isWeakSet$1.isJSONValue;
3401
3476
  exports.isLength = isWeakSet$1.isLength;
3477
+ exports.isNode = isWeakSet$1.isNode;
3402
3478
  exports.isNotNil = isWeakSet$1.isNotNil;
3403
3479
  exports.isNull = isWeakSet$1.isNull;
3404
3480
  exports.isPromise = isWeakSet$1.isPromise;
@@ -3411,7 +3487,8 @@ exports.capitalize = upperFirst$1.capitalize;
3411
3487
  exports.constantCase = upperFirst$1.constantCase;
3412
3488
  exports.pascalCase = upperFirst$1.pascalCase;
3413
3489
  exports.reverseString = upperFirst$1.reverseString;
3414
- exports.invariant = util_index.invariant;
3490
+ exports.attemptAsync = invariant.attemptAsync;
3491
+ exports.invariant = invariant.invariant;
3415
3492
  exports.add = add;
3416
3493
  exports.after = after;
3417
3494
  exports.ary = ary;
@@ -3471,6 +3548,7 @@ exports.flow = flow;
3471
3548
  exports.flowRight = flowRight;
3472
3549
  exports.forEach = forEach;
3473
3550
  exports.fromPairs = fromPairs;
3551
+ exports.functionsIn = functionsIn;
3474
3552
  exports.get = get;
3475
3553
  exports.gt = gt;
3476
3554
  exports.gte = gte;
@@ -3531,11 +3609,14 @@ exports.matches = matches;
3531
3609
  exports.matchesProperty = matchesProperty;
3532
3610
  exports.max = max;
3533
3611
  exports.maxBy = maxBy;
3612
+ exports.mean = mean;
3613
+ exports.meanBy = meanBy;
3534
3614
  exports.merge = merge;
3535
3615
  exports.mergeWith = mergeWith;
3536
3616
  exports.method = method;
3537
3617
  exports.methodOf = methodOf;
3538
3618
  exports.min = min;
3619
+ exports.minBy = minBy;
3539
3620
  exports.multiply = multiply;
3540
3621
  exports.negate = negate;
3541
3622
  exports.now = now;
@@ -3560,6 +3641,7 @@ exports.rangeRight = rangeRight;
3560
3641
  exports.rearg = rearg;
3561
3642
  exports.reduce = reduce;
3562
3643
  exports.reduceRight = reduceRight;
3644
+ exports.reject = reject;
3563
3645
  exports.remove = remove;
3564
3646
  exports.repeat = repeat;
3565
3647
  exports.replace = replace;
@@ -3575,6 +3657,7 @@ exports.some = some;
3575
3657
  exports.sortBy = sortBy;
3576
3658
  exports.sortedIndex = sortedIndex;
3577
3659
  exports.sortedIndexBy = sortedIndexBy;
3660
+ exports.sortedIndexOf = sortedIndexOf;
3578
3661
  exports.spread = spread;
3579
3662
  exports.startCase = startCase;
3580
3663
  exports.startsWith = startsWith;
@@ -8,7 +8,6 @@ export { initial } from '../array/initial.mjs';
8
8
  export { isSubset } from '../array/isSubset.mjs';
9
9
  export { isSubsetWith } from '../array/isSubsetWith.mjs';
10
10
  export { keyBy } from '../array/keyBy.mjs';
11
- export { minBy } from '../array/minBy.mjs';
12
11
  export { partition } from '../array/partition.mjs';
13
12
  export { pullAt } from '../array/pullAt.mjs';
14
13
  export { sampleSize } from '../array/sampleSize.mjs';
@@ -36,8 +35,6 @@ export { partial } from '../function/partial.mjs';
36
35
  export { partialRight } from '../function/partialRight.mjs';
37
36
  export { retry } from '../function/retry.mjs';
38
37
  export { unary } from '../function/unary.mjs';
39
- export { mean } from '../math/mean.mjs';
40
- export { meanBy } from '../math/meanBy.mjs';
41
38
  export { median } from '../math/median.mjs';
42
39
  export { medianBy } from '../math/medianBy.mjs';
43
40
  export { randomInt } from '../math/randomInt.mjs';
@@ -49,6 +46,7 @@ export { isObjectLike } from './predicate/isObjectLike.mjs';
49
46
  export { omitBy } from '../object/omitBy.mjs';
50
47
  export { toMerged } from '../object/toMerged.mjs';
51
48
  export { isBlob } from '../predicate/isBlob.mjs';
49
+ export { isBrowser } from '../predicate/isBrowser.mjs';
52
50
  export { isEqual } from '../predicate/isEqual.mjs';
53
51
  export { eq } from './util/eq.mjs';
54
52
  export { isFile } from '../predicate/isFile.mjs';
@@ -56,6 +54,7 @@ export { isFunction } from '../predicate/isFunction.mjs';
56
54
  export { isJSON } from '../predicate/isJSON.mjs';
57
55
  export { isJSONArray, isJSONObject, isJSONValue } from '../predicate/isJSONValue.mjs';
58
56
  export { isLength } from '../predicate/isLength.mjs';
57
+ export { isNode } from '../predicate/isNode.mjs';
59
58
  export { isNotNil } from '../predicate/isNotNil.mjs';
60
59
  export { isNull } from '../predicate/isNull.mjs';
61
60
  export { isPromise } from '../predicate/isPromise.mjs';
@@ -69,6 +68,7 @@ export { constantCase } from '../string/constantCase.mjs';
69
68
  import '../string/deburr.mjs';
70
69
  export { pascalCase } from '../string/pascalCase.mjs';
71
70
  export { reverseString } from '../string/reverseString.mjs';
71
+ export { attemptAsync } from '../util/attemptAsync.mjs';
72
72
  export { invariant } from '../util/invariant.mjs';
73
73
  export { castArray } from './array/castArray.mjs';
74
74
  export { chunk } from './array/chunk.mjs';
@@ -109,6 +109,7 @@ export { pullAll } from './array/pullAll.mjs';
109
109
  export { pullAllBy } from './array/pullAllBy.mjs';
110
110
  export { reduce } from './array/reduce.mjs';
111
111
  export { reduceRight } from './array/reduceRight.mjs';
112
+ export { reject } from './array/reject.mjs';
112
113
  export { remove } from './array/remove.mjs';
113
114
  export { reverse } from './array/reverse.mjs';
114
115
  export { sample } from './array/sample.mjs';
@@ -118,6 +119,7 @@ export { some } from './array/some.mjs';
118
119
  export { sortBy } from './array/sortBy.mjs';
119
120
  export { sortedIndex } from './array/sortedIndex.mjs';
120
121
  export { sortedIndexBy } from './array/sortedIndexBy.mjs';
122
+ export { sortedIndexOf } from './array/sortedIndexOf.mjs';
121
123
  export { tail } from './array/tail.mjs';
122
124
  export { take } from './array/take.mjs';
123
125
  export { takeRight } from './array/takeRight.mjs';
@@ -157,7 +159,10 @@ export { floor } from './math/floor.mjs';
157
159
  export { inRange } from './math/inRange.mjs';
158
160
  export { max } from './math/max.mjs';
159
161
  export { maxBy } from './math/maxBy.mjs';
162
+ export { mean } from './math/mean.mjs';
163
+ export { meanBy } from './math/meanBy.mjs';
160
164
  export { min } from './math/min.mjs';
165
+ export { minBy } from './math/minBy.mjs';
161
166
  export { multiply } from './math/multiply.mjs';
162
167
  export { parseInt } from './math/parseInt.mjs';
163
168
  export { random } from './math/random.mjs';
@@ -173,6 +178,7 @@ export { cloneDeepWith } from './object/cloneDeepWith.mjs';
173
178
  export { defaults } from './object/defaults.mjs';
174
179
  export { findKey } from './object/findKey.mjs';
175
180
  export { fromPairs } from './object/fromPairs.mjs';
181
+ export { functionsIn } from './object/functionsIn.mjs';
176
182
  export { get } from './object/get.mjs';
177
183
  export { has } from './object/has.mjs';
178
184
  export { invertBy } from './object/invertBy.mjs';
@@ -1,4 +1,21 @@
1
+ import { toNumber } from '../util/toNumber.mjs';
2
+ import { toString } from '../util/toString.mjs';
3
+
1
4
  function add(value, other) {
5
+ if (value === undefined && other === undefined) {
6
+ return 0;
7
+ }
8
+ if (value === undefined || other === undefined) {
9
+ return value ?? other;
10
+ }
11
+ if (typeof value === 'string' || typeof other === 'string') {
12
+ value = toString(value);
13
+ other = toString(other);
14
+ }
15
+ else {
16
+ value = toNumber(value);
17
+ other = toNumber(other);
18
+ }
2
19
  return value + other;
3
20
  }
4
21
 
@@ -2,7 +2,6 @@ import { toNumber } from '../util/toNumber.mjs';
2
2
  import { toString } from '../util/toString.mjs';
3
3
 
4
4
  function divide(value, other) {
5
- console.log(value, other);
6
5
  if (value === undefined && other === undefined) {
7
6
  return 1;
8
7
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Calculates the average of an array of numbers.
3
+ *
4
+ * If the array is empty, this function returns `NaN`.
5
+ *
6
+ * @param {number[]} nums - An array of numbers to calculate the average.
7
+ * @returns {number} The average of all the numbers in the array.
8
+ *
9
+ * @example
10
+ * const numbers = [1, 2, 3, 4, 5];
11
+ * const result = mean(numbers);
12
+ * // result will be 3
13
+ */
14
+ declare function mean(nums?: readonly number[]): number;
15
+
16
+ export { mean };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Calculates the average of an array of numbers.
3
+ *
4
+ * If the array is empty, this function returns `NaN`.
5
+ *
6
+ * @param {number[]} nums - An array of numbers to calculate the average.
7
+ * @returns {number} The average of all the numbers in the array.
8
+ *
9
+ * @example
10
+ * const numbers = [1, 2, 3, 4, 5];
11
+ * const result = mean(numbers);
12
+ * // result will be 3
13
+ */
14
+ declare function mean(nums?: readonly number[]): number;
15
+
16
+ export { mean };
@@ -0,0 +1,8 @@
1
+ import { sum } from './sum.mjs';
2
+
3
+ function mean(nums) {
4
+ const length = nums ? nums.length : 0;
5
+ return length === 0 ? NaN : sum(nums) / length;
6
+ }
7
+
8
+ export { mean };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Calculates the average of an array of numbers when applying
3
+ * the `iteratee` function to each element.
4
+ *
5
+ * If the array is empty, this function returns `NaN`.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {T[]} items An array to calculate the average.
9
+ * @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
10
+ * The criteria used to determine the maximum value.
11
+ * - If a **function** is provided, it extracts a numeric value from each element.
12
+ * - If a **string** is provided, it is treated as a key to extract values from the objects.
13
+ * - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
14
+ * - If an **object** is provided, it matches elements that contain the specified properties.
15
+ * @returns {number} The average of all the numbers as determined by the `iteratee` function.
16
+ *
17
+ * @example
18
+ * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
19
+ * meanBy([], x => x.a); // Returns: NaN
20
+ * meanBy([[2], [3], [1]], 0); // Returns: 2
21
+ * meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
22
+ */
23
+ declare function meanBy<T>(items: ArrayLike<T> | null | undefined, iteratee: ((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>): number;
24
+
25
+ export { meanBy };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Calculates the average of an array of numbers when applying
3
+ * the `iteratee` function to each element.
4
+ *
5
+ * If the array is empty, this function returns `NaN`.
6
+ *
7
+ * @template T - The type of elements in the array.
8
+ * @param {T[]} items An array to calculate the average.
9
+ * @param {((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>} iteratee
10
+ * The criteria used to determine the maximum value.
11
+ * - If a **function** is provided, it extracts a numeric value from each element.
12
+ * - If a **string** is provided, it is treated as a key to extract values from the objects.
13
+ * - If a **[key, value]** pair is provided, it matches elements with the specified key-value pair.
14
+ * - If an **object** is provided, it matches elements that contain the specified properties.
15
+ * @returns {number} The average of all the numbers as determined by the `iteratee` function.
16
+ *
17
+ * @example
18
+ * meanBy([{ a: 1 }, { a: 2 }, { a: 3 }], x => x.a); // Returns: 2
19
+ * meanBy([], x => x.a); // Returns: NaN
20
+ * meanBy([[2], [3], [1]], 0); // Returns: 2
21
+ * meanBy([{ a: 2 }, { a: 3 }, { a: 1 }], 'a'); // Returns: 2
22
+ */
23
+ declare function meanBy<T>(items: ArrayLike<T> | null | undefined, iteratee: ((element: T) => number) | keyof T | [keyof T, unknown] | Partial<T>): number;
24
+
25
+ export { meanBy };
@@ -0,0 +1,11 @@
1
+ import { meanBy as meanBy$1 } from '../../math/meanBy.mjs';
2
+ import { iteratee } from '../util/iteratee.mjs';
3
+
4
+ function meanBy(items, iteratee$1) {
5
+ if (items == null) {
6
+ return NaN;
7
+ }
8
+ return meanBy$1(Array.from(items), iteratee(iteratee$1));
9
+ }
10
+
11
+ export { meanBy };