es-toolkit 1.35.0-dev.1206 → 1.35.0-dev.1209

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.
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const zipWith = require('./zipWith-ChDTPy.js');
3
+ const zipWith = require('./zipWith-CsbMsR.js');
4
4
  const AbortError = require('./AbortError-Cg4ZQ1.js');
5
5
  const error_index = require('../error/index.js');
6
6
  const unary = require('./unary-EIEhcF.js');
@@ -805,40 +805,11 @@ function differenceWith(array, ...values) {
805
805
  return zipWith.difference(Array.from(array), flattenedValues);
806
806
  }
807
807
 
808
- function isSymbol(value) {
809
- return typeof value === 'symbol' || value instanceof Symbol;
810
- }
811
-
812
- function toNumber(value) {
813
- if (isSymbol(value)) {
814
- return NaN;
815
- }
816
- return Number(value);
817
- }
818
-
819
- function toFinite(value) {
820
- if (!value) {
821
- return value === 0 ? value : 0;
822
- }
823
- value = toNumber(value);
824
- if (value === Infinity || value === -Infinity) {
825
- const sign = value < 0 ? -1 : 1;
826
- return sign * Number.MAX_VALUE;
827
- }
828
- return value === value ? value : 0;
829
- }
830
-
831
- function toInteger(value) {
832
- const finite = toFinite(value);
833
- const remainder = finite % 1;
834
- return remainder ? finite - remainder : finite;
835
- }
836
-
837
808
  function drop(collection, itemsCount = 1, guard) {
838
809
  if (!isArrayLike(collection)) {
839
810
  return [];
840
811
  }
841
- itemsCount = guard ? 1 : toInteger(itemsCount);
812
+ itemsCount = guard ? 1 : zipWith.toInteger(itemsCount);
842
813
  return zipWith.drop(toArray$1(collection), itemsCount);
843
814
  }
844
815
 
@@ -846,7 +817,7 @@ function dropRight(collection, itemsCount = 1, guard) {
846
817
  if (!isArrayLike(collection)) {
847
818
  return [];
848
819
  }
849
- itemsCount = guard ? 1 : toInteger(itemsCount);
820
+ itemsCount = guard ? 1 : zipWith.toInteger(itemsCount);
850
821
  return zipWith.dropRight(toArray$1(collection), itemsCount);
851
822
  }
852
823
 
@@ -1073,7 +1044,7 @@ function findLast(source, _doesMatch, fromIndex) {
1073
1044
  return undefined;
1074
1045
  }
1075
1046
  const length = Array.isArray(source) ? source.length : Object.keys(source).length;
1076
- fromIndex = toInteger(fromIndex ?? length - 1);
1047
+ fromIndex = zipWith.toInteger(fromIndex ?? length - 1);
1077
1048
  if (fromIndex < 0) {
1078
1049
  fromIndex = Math.max(length + fromIndex, 0);
1079
1050
  }
@@ -1197,7 +1168,7 @@ function includes(source, target, fromIndex, guard) {
1197
1168
  fromIndex = 0;
1198
1169
  }
1199
1170
  else {
1200
- fromIndex = toInteger(fromIndex);
1171
+ fromIndex = zipWith.toInteger(fromIndex);
1201
1172
  }
1202
1173
  if (isString(source)) {
1203
1174
  if (fromIndex > source.length || target instanceof RegExp) {
@@ -1377,7 +1348,7 @@ function nth(array, n = 0) {
1377
1348
  if (!isArrayLikeObject(array) || array.length === 0) {
1378
1349
  return undefined;
1379
1350
  }
1380
- n = toInteger(n);
1351
+ n = zipWith.toInteger(n);
1381
1352
  if (n < 0) {
1382
1353
  n += array.length;
1383
1354
  }
@@ -1425,7 +1396,7 @@ function isKey(value, object) {
1425
1396
  if (Array.isArray(value)) {
1426
1397
  return false;
1427
1398
  }
1428
- if (typeof value === 'number' || typeof value === 'boolean' || value == null || isSymbol(value)) {
1399
+ if (typeof value === 'number' || typeof value === 'boolean' || value == null || zipWith.isSymbol(value)) {
1429
1400
  return true;
1430
1401
  }
1431
1402
  return ((typeof value === 'string' && (regexIsPlainProp.test(value) || !regexIsDeepProp.test(value))) ||
@@ -1650,8 +1621,8 @@ function slice(array, start, end) {
1650
1621
  start = 0;
1651
1622
  end = length;
1652
1623
  }
1653
- start = toInteger(start);
1654
- end = toInteger(end);
1624
+ start = zipWith.toInteger(start);
1625
+ end = zipWith.toInteger(end);
1655
1626
  if (start < 0) {
1656
1627
  start = Math.max(length + start, 0);
1657
1628
  }
@@ -1747,7 +1718,7 @@ function sortedIndexBy(array, value, iteratee$1, retHighest) {
1747
1718
  const transformedValue = iterateeFunction(value);
1748
1719
  const valIsNaN = isNaN(transformedValue);
1749
1720
  const valIsNull = isPromise.isNull(transformedValue);
1750
- const valIsSymbol = isSymbol(transformedValue);
1721
+ const valIsSymbol = zipWith.isSymbol(transformedValue);
1751
1722
  const valIsUndefined = isPromise.isUndefined(transformedValue);
1752
1723
  while (low < high) {
1753
1724
  let setLow;
@@ -1756,7 +1727,7 @@ function sortedIndexBy(array, value, iteratee$1, retHighest) {
1756
1727
  const othIsDefined = !isPromise.isUndefined(computed);
1757
1728
  const othIsNull = isPromise.isNull(computed);
1758
1729
  const othIsReflexive = !isNaN(computed);
1759
- const othIsSymbol = isSymbol(computed);
1730
+ const othIsSymbol = zipWith.isSymbol(computed);
1760
1731
  if (valIsNaN) {
1761
1732
  setLow = retHighest || othIsReflexive;
1762
1733
  }
@@ -1859,7 +1830,7 @@ function tail(arr) {
1859
1830
  }
1860
1831
 
1861
1832
  function take(arr, count = 1, guard) {
1862
- count = guard ? 1 : toInteger(count);
1833
+ count = guard ? 1 : zipWith.toInteger(count);
1863
1834
  if (count < 1 || !isArrayLike(arr)) {
1864
1835
  return [];
1865
1836
  }
@@ -1867,7 +1838,7 @@ function take(arr, count = 1, guard) {
1867
1838
  }
1868
1839
 
1869
1840
  function takeRight(arr, count = 1, guard) {
1870
- count = guard ? 1 : toInteger(count);
1841
+ count = guard ? 1 : zipWith.toInteger(count);
1871
1842
  if (count <= 0 || !isArrayLike(arr)) {
1872
1843
  return [];
1873
1844
  }
@@ -2022,7 +1993,7 @@ function after(n, func) {
2022
1993
  if (typeof func !== 'function') {
2023
1994
  throw new TypeError('Expected a function');
2024
1995
  }
2025
- n = toInteger(n);
1996
+ n = zipWith.toInteger(n);
2026
1997
  return function (...args) {
2027
1998
  if (--n < 1) {
2028
1999
  return func.apply(this, args);
@@ -2054,7 +2025,7 @@ function before(n, func) {
2054
2025
  throw new TypeError('Expected a function');
2055
2026
  }
2056
2027
  let result;
2057
- n = toInteger(n);
2028
+ n = zipWith.toInteger(n);
2058
2029
  return function (...args) {
2059
2030
  if (--n > 0) {
2060
2031
  result = func.apply(this, args);
@@ -2293,7 +2264,7 @@ function delay(func, wait, ...args) {
2293
2264
  if (typeof func !== 'function') {
2294
2265
  throw new TypeError('Expected a function');
2295
2266
  }
2296
- return setTimeout(func, toNumber(wait) || 0, ...args);
2267
+ return setTimeout(func, zipWith.toNumber(wait) || 0, ...args);
2297
2268
  }
2298
2269
 
2299
2270
  function flip(func) {
@@ -2320,7 +2291,7 @@ function flowRight(...funcs) {
2320
2291
 
2321
2292
  function nthArg(n = 0) {
2322
2293
  return function (...args) {
2323
- return args.at(toInteger(n));
2294
+ return args.at(zipWith.toInteger(n));
2324
2295
  };
2325
2296
  }
2326
2297
 
@@ -2407,8 +2378,8 @@ function add(value, other) {
2407
2378
  other = toString(other);
2408
2379
  }
2409
2380
  else {
2410
- value = toNumber(value);
2411
- other = toNumber(other);
2381
+ value = zipWith.toNumber(value);
2382
+ other = zipWith.toNumber(other);
2412
2383
  }
2413
2384
  return value + other;
2414
2385
  }
@@ -2457,8 +2428,8 @@ function divide(value, other) {
2457
2428
  other = toString(other);
2458
2429
  }
2459
2430
  else {
2460
- value = toNumber(value);
2461
- other = toNumber(other);
2431
+ value = zipWith.toNumber(value);
2432
+ other = zipWith.toNumber(other);
2462
2433
  }
2463
2434
  return value / other;
2464
2435
  }
@@ -2582,8 +2553,8 @@ function multiply(value, other) {
2582
2553
  other = toString(other);
2583
2554
  }
2584
2555
  else {
2585
- value = toNumber(value);
2586
- other = toNumber(other);
2556
+ value = zipWith.toNumber(value);
2557
+ other = zipWith.toNumber(other);
2587
2558
  }
2588
2559
  return value * other;
2589
2560
  }
@@ -2664,15 +2635,15 @@ function range(start, end, step) {
2664
2635
  if (step && typeof step !== 'number' && isIterateeCall(start, end, step)) {
2665
2636
  end = step = undefined;
2666
2637
  }
2667
- start = toFinite(start);
2638
+ start = zipWith.toFinite(start);
2668
2639
  if (end === undefined) {
2669
2640
  end = start;
2670
2641
  start = 0;
2671
2642
  }
2672
2643
  else {
2673
- end = toFinite(end);
2644
+ end = zipWith.toFinite(end);
2674
2645
  }
2675
- step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
2646
+ step = step === undefined ? (start < end ? 1 : -1) : zipWith.toFinite(step);
2676
2647
  const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
2677
2648
  const result = new Array(length);
2678
2649
  for (let index = 0; index < length; index++) {
@@ -2686,15 +2657,15 @@ function rangeRight(start, end, step) {
2686
2657
  if (step && typeof step !== 'number' && isIterateeCall(start, end, step)) {
2687
2658
  end = step = undefined;
2688
2659
  }
2689
- start = toFinite(start);
2660
+ start = zipWith.toFinite(start);
2690
2661
  if (end === undefined) {
2691
2662
  end = start;
2692
2663
  start = 0;
2693
2664
  }
2694
2665
  else {
2695
- end = toFinite(end);
2666
+ end = zipWith.toFinite(end);
2696
2667
  }
2697
- step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
2668
+ step = step === undefined ? (start < end ? 1 : -1) : zipWith.toFinite(step);
2698
2669
  const length = Math.max(Math.ceil((end - start) / (step || 1)), 0);
2699
2670
  const result = new Array(length);
2700
2671
  for (let index = length - 1; index >= 0; index--) {
@@ -2720,8 +2691,8 @@ function subtract(value, other) {
2720
2691
  other = toString(other);
2721
2692
  }
2722
2693
  else {
2723
- value = toNumber(value);
2724
- other = toNumber(other);
2694
+ value = zipWith.toNumber(value);
2695
+ other = zipWith.toNumber(other);
2725
2696
  }
2726
2697
  return value - other;
2727
2698
  }
@@ -2737,7 +2708,7 @@ function isTypedArray(x) {
2737
2708
  }
2738
2709
 
2739
2710
  function times(n, getValue) {
2740
- n = toInteger(n);
2711
+ n = zipWith.toInteger(n);
2741
2712
  if (n < 1 || !Number.isSafeInteger(n)) {
2742
2713
  return [];
2743
2714
  }
@@ -2919,7 +2890,12 @@ function create(prototype, properties) {
2919
2890
  function defaults(object, ...sources) {
2920
2891
  object = Object(object);
2921
2892
  const objectProto = Object.prototype;
2922
- for (let i = 0; i < sources.length; i++) {
2893
+ let length = sources.length;
2894
+ const guard = length > 2 ? sources[2] : undefined;
2895
+ if (guard && isIterateeCall(sources[0], sources[1], guard)) {
2896
+ length = 1;
2897
+ }
2898
+ for (let i = 0; i < length; i++) {
2923
2899
  const source = sources[i];
2924
2900
  const keys = Object.keys(source);
2925
2901
  for (let j = 0; j < keys.length; j++) {
@@ -3303,7 +3279,7 @@ function pickBy(obj, shouldPick) {
3303
3279
  }
3304
3280
  const keys = isArrayLike(obj) ? range$1.range(0, obj.length) : [...keysIn(obj), ...getSymbolsIn(obj)];
3305
3281
  for (let i = 0; i < keys.length; i++) {
3306
- const key = (isSymbol(keys[i]) ? keys[i] : keys[i].toString());
3282
+ const key = (zipWith.isSymbol(keys[i]) ? keys[i] : keys[i].toString());
3307
3283
  const value = obj[key];
3308
3284
  if (shouldPick(value, key, obj)) {
3309
3285
  result[key] = value;
@@ -3573,8 +3549,14 @@ function padStart(str, length = 0, chars = ' ') {
3573
3549
  return toString(str).padStart(length, chars);
3574
3550
  }
3575
3551
 
3576
- function repeat(str, n) {
3577
- return str.repeat(n);
3552
+ function repeat(str, n, guard) {
3553
+ if (guard ? isIterateeCall(str, n, guard) : n === undefined) {
3554
+ n = 1;
3555
+ }
3556
+ else {
3557
+ n = zipWith.toInteger(n);
3558
+ }
3559
+ return toString(str).repeat(n);
3578
3560
  }
3579
3561
 
3580
3562
  function replace(target = '', pattern, replacement) {
@@ -3776,8 +3758,9 @@ function upperFirst(str) {
3776
3758
  return reverseString.upperFirst(toString(str));
3777
3759
  }
3778
3760
 
3779
- function words(str, pattern = reverseString.CASE_SPLIT_PATTERN) {
3761
+ function words(str, pattern = reverseString.CASE_SPLIT_PATTERN, guard) {
3780
3762
  const input = toString(str);
3763
+ pattern = guard ? reverseString.CASE_SPLIT_PATTERN : pattern;
3781
3764
  const words = Array.from(input.match(pattern) ?? []);
3782
3765
  return words.filter(x => x !== '');
3783
3766
  }
@@ -3819,14 +3802,14 @@ function gt(value, other) {
3819
3802
  if (typeof value === 'string' && typeof other === 'string') {
3820
3803
  return value > other;
3821
3804
  }
3822
- return toNumber(value) > toNumber(other);
3805
+ return zipWith.toNumber(value) > zipWith.toNumber(other);
3823
3806
  }
3824
3807
 
3825
3808
  function gte(value, other) {
3826
3809
  if (typeof value === 'string' && typeof other === 'string') {
3827
3810
  return value >= other;
3828
3811
  }
3829
- return toNumber(value) >= toNumber(other);
3812
+ return zipWith.toNumber(value) >= zipWith.toNumber(other);
3830
3813
  }
3831
3814
 
3832
3815
  function invoke(object, path, args = []) {
@@ -3875,14 +3858,14 @@ function lt(value, other) {
3875
3858
  if (typeof value === 'string' && typeof other === 'string') {
3876
3859
  return value < other;
3877
3860
  }
3878
- return toNumber(value) < toNumber(other);
3861
+ return zipWith.toNumber(value) < zipWith.toNumber(other);
3879
3862
  }
3880
3863
 
3881
3864
  function lte(value, other) {
3882
3865
  if (typeof value === 'string' && typeof other === 'string') {
3883
3866
  return value <= other;
3884
3867
  }
3885
- return toNumber(value) <= toNumber(other);
3868
+ return zipWith.toNumber(value) <= zipWith.toNumber(other);
3886
3869
  }
3887
3870
 
3888
3871
  function method(path, ...args) {
@@ -3981,7 +3964,7 @@ function toSafeInteger(value) {
3981
3964
  if (value == null) {
3982
3965
  return 0;
3983
3966
  }
3984
- return clamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
3967
+ return clamp(zipWith.toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
3985
3968
  }
3986
3969
 
3987
3970
  let idCounter = 0;
@@ -4136,7 +4119,7 @@ const compat = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4136
4119
  isString,
4137
4120
  isSubset: zipWith.isSubset,
4138
4121
  isSubsetWith: zipWith.isSubsetWith,
4139
- isSymbol,
4122
+ isSymbol: zipWith.isSymbol,
4140
4123
  isTypedArray,
4141
4124
  isUndefined: isPromise.isUndefined,
4142
4125
  isWeakMap,
@@ -4253,12 +4236,12 @@ const compat = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4253
4236
  toCamelCaseKeys,
4254
4237
  toDefaulted,
4255
4238
  toFilled: zipWith.toFilled,
4256
- toFinite,
4257
- toInteger,
4239
+ toFinite: zipWith.toFinite,
4240
+ toInteger: zipWith.toInteger,
4258
4241
  toLength,
4259
4242
  toLower,
4260
4243
  toMerged,
4261
- toNumber,
4244
+ toNumber: zipWith.toNumber,
4262
4245
  toPairs,
4263
4246
  toPairsIn,
4264
4247
  toPath,
@@ -4456,7 +4439,6 @@ exports.isRegExp = isRegExp;
4456
4439
  exports.isSafeInteger = isSafeInteger;
4457
4440
  exports.isSet = isSet;
4458
4441
  exports.isString = isString;
4459
- exports.isSymbol = isSymbol;
4460
4442
  exports.isTypedArray = isTypedArray;
4461
4443
  exports.isWeakMap = isWeakMap;
4462
4444
  exports.isWeakSet = isWeakSet;
@@ -4559,12 +4541,9 @@ exports.times = times;
4559
4541
  exports.toArray = toArray;
4560
4542
  exports.toCamelCaseKeys = toCamelCaseKeys;
4561
4543
  exports.toDefaulted = toDefaulted;
4562
- exports.toFinite = toFinite;
4563
- exports.toInteger = toInteger;
4564
4544
  exports.toLength = toLength;
4565
4545
  exports.toLower = toLower;
4566
4546
  exports.toMerged = toMerged;
4567
- exports.toNumber = toNumber;
4568
4547
  exports.toPairs = toPairs;
4569
4548
  exports.toPairsIn = toPairsIn;
4570
4549
  exports.toPath = toPath;
@@ -334,12 +334,43 @@ function tail(arr) {
334
334
  return arr.slice(1);
335
335
  }
336
336
 
337
- function take(arr, count) {
337
+ function isSymbol(value) {
338
+ return typeof value === 'symbol' || value instanceof Symbol;
339
+ }
340
+
341
+ function toNumber(value) {
342
+ if (isSymbol(value)) {
343
+ return NaN;
344
+ }
345
+ return Number(value);
346
+ }
347
+
348
+ function toFinite(value) {
349
+ if (!value) {
350
+ return value === 0 ? value : 0;
351
+ }
352
+ value = toNumber(value);
353
+ if (value === Infinity || value === -Infinity) {
354
+ const sign = value < 0 ? -1 : 1;
355
+ return sign * Number.MAX_VALUE;
356
+ }
357
+ return value === value ? value : 0;
358
+ }
359
+
360
+ function toInteger(value) {
361
+ const finite = toFinite(value);
362
+ const remainder = finite % 1;
363
+ return remainder ? finite - remainder : finite;
364
+ }
365
+
366
+ function take(arr, count, guard) {
367
+ count = guard || count === undefined ? 1 : toInteger(count);
338
368
  return arr.slice(0, count);
339
369
  }
340
370
 
341
- function takeRight(arr, count = 1) {
342
- if (count <= 0) {
371
+ function takeRight(arr, count = 1, guard) {
372
+ count = guard || count === undefined ? 1 : toInteger(count);
373
+ if (count <= 0 || arr == null || arr.length === 0) {
343
374
  return [];
344
375
  }
345
376
  return arr.slice(-count);
@@ -525,6 +556,7 @@ exports.intersectionBy = intersectionBy;
525
556
  exports.intersectionWith = intersectionWith;
526
557
  exports.isSubset = isSubset;
527
558
  exports.isSubsetWith = isSubsetWith;
559
+ exports.isSymbol = isSymbol;
528
560
  exports.keyBy = keyBy;
529
561
  exports.last = last;
530
562
  exports.maxBy = maxBy;
@@ -540,6 +572,9 @@ exports.tail = tail;
540
572
  exports.take = take;
541
573
  exports.takeRight = takeRight;
542
574
  exports.toFilled = toFilled;
575
+ exports.toFinite = toFinite;
576
+ exports.toInteger = toInteger;
577
+ exports.toNumber = toNumber;
543
578
  exports.union = union;
544
579
  exports.unionBy = unionBy;
545
580
  exports.unionWith = unionWith;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const zipWith = require('../_chunk/zipWith-ChDTPy.js');
5
+ const zipWith = require('../_chunk/zipWith-CsbMsR.js');
6
6
 
7
7
  function compareValues(a, b, order) {
8
8
  if (a < b) {
@@ -20,6 +20,6 @@
20
20
  * // Returns [1, 2, 3]
21
21
  * take([1, 2, 3], 5);
22
22
  */
23
- declare function take<T>(arr: readonly T[], count: number): T[];
23
+ declare function take<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
24
24
 
25
25
  export { take };
@@ -20,6 +20,6 @@
20
20
  * // Returns [1, 2, 3]
21
21
  * take([1, 2, 3], 5);
22
22
  */
23
- declare function take<T>(arr: readonly T[], count: number): T[];
23
+ declare function take<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
24
24
 
25
25
  export { take };
@@ -1,4 +1,7 @@
1
- function take(arr, count) {
1
+ import { toInteger } from '../compat/util/toInteger.mjs';
2
+
3
+ function take(arr, count, guard) {
4
+ count = guard || count === undefined ? 1 : toInteger(count);
2
5
  return arr.slice(0, count);
3
6
  }
4
7
 
@@ -19,6 +19,6 @@
19
19
  * // Returns [1, 2, 3]
20
20
  * takeRight([1, 2, 3], 5);
21
21
  */
22
- declare function takeRight<T>(arr: readonly T[], count?: number): T[];
22
+ declare function takeRight<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
23
23
 
24
24
  export { takeRight };
@@ -19,6 +19,6 @@
19
19
  * // Returns [1, 2, 3]
20
20
  * takeRight([1, 2, 3], 5);
21
21
  */
22
- declare function takeRight<T>(arr: readonly T[], count?: number): T[];
22
+ declare function takeRight<T>(arr: readonly T[], count?: number, guard?: unknown): T[];
23
23
 
24
24
  export { takeRight };
@@ -1,5 +1,8 @@
1
- function takeRight(arr, count = 1) {
2
- if (count <= 0) {
1
+ import { toInteger } from '../compat/util/toInteger.mjs';
2
+
3
+ function takeRight(arr, count = 1, guard) {
4
+ count = guard || count === undefined ? 1 : toInteger(count);
5
+ if (count <= 0 || arr == null || arr.length === 0) {
3
6
  return [];
4
7
  }
5
8
  return arr.slice(-count);