es-toolkit 1.25.2 → 1.26.0-dev.826

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 (87) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/_chunk/{sumBy-BkErWJ.js → sumBy-RVppiV.js} +21 -0
  3. package/dist/_chunk/{toMerged-BLnW4M.js → toMerged-wNz52b.js} +2 -2
  4. package/dist/_chunk/{unary-CMvKXy.js → unary-CcTNuC.js} +5 -0
  5. package/dist/browser.global.js +1 -1
  6. package/dist/browser.global.js.map +1 -1
  7. package/dist/compat/array/drop.d.mts +2 -1
  8. package/dist/compat/array/drop.d.ts +2 -1
  9. package/dist/compat/array/drop.mjs +3 -1
  10. package/dist/compat/array/dropRight.d.mts +2 -1
  11. package/dist/compat/array/dropRight.d.ts +2 -1
  12. package/dist/compat/array/dropRight.mjs +3 -1
  13. package/dist/compat/array/every.d.mts +2 -2
  14. package/dist/compat/array/every.d.ts +2 -2
  15. package/dist/compat/array/every.mjs +6 -2
  16. package/dist/compat/array/filter.d.mts +3 -3
  17. package/dist/compat/array/filter.d.ts +3 -3
  18. package/dist/compat/array/filter.mjs +1 -1
  19. package/dist/compat/array/find.d.mts +6 -6
  20. package/dist/compat/array/find.d.ts +6 -6
  21. package/dist/compat/array/intersectionBy.d.mts +111 -0
  22. package/dist/compat/array/intersectionBy.d.ts +111 -0
  23. package/dist/compat/array/intersectionBy.mjs +36 -0
  24. package/dist/compat/array/orderBy.d.mts +3 -2
  25. package/dist/compat/array/orderBy.d.ts +3 -2
  26. package/dist/compat/array/orderBy.mjs +7 -3
  27. package/dist/compat/array/some.d.mts +68 -21
  28. package/dist/compat/array/some.d.ts +68 -21
  29. package/dist/compat/array/some.mjs +21 -9
  30. package/dist/compat/array/sortBy.d.mts +3 -3
  31. package/dist/compat/array/sortBy.d.ts +3 -3
  32. package/dist/compat/array/sortBy.mjs +11 -2
  33. package/dist/compat/array/take.d.mts +2 -1
  34. package/dist/compat/array/take.d.ts +2 -1
  35. package/dist/compat/array/take.mjs +3 -1
  36. package/dist/compat/array/takeRight.d.mts +2 -1
  37. package/dist/compat/array/takeRight.d.ts +2 -1
  38. package/dist/compat/array/takeRight.mjs +3 -1
  39. package/dist/compat/array/zipObjectDeep.d.mts +2 -4
  40. package/dist/compat/array/zipObjectDeep.d.ts +2 -4
  41. package/dist/compat/index.d.mts +7 -1
  42. package/dist/compat/index.d.ts +7 -1
  43. package/dist/compat/index.js +218 -70
  44. package/dist/compat/index.mjs +7 -1
  45. package/dist/compat/object/invertBy.mjs +1 -1
  46. package/dist/compat/object/mapKeys.mjs +1 -1
  47. package/dist/compat/object/mapValues.mjs +1 -1
  48. package/dist/compat/string/template.d.mts +89 -0
  49. package/dist/compat/string/template.d.ts +89 -0
  50. package/dist/compat/string/template.mjs +86 -0
  51. package/dist/compat/util/uniqueId.d.mts +25 -0
  52. package/dist/compat/util/uniqueId.d.ts +25 -0
  53. package/dist/compat/util/uniqueId.mjs +7 -0
  54. package/dist/function/identity.d.mts +22 -0
  55. package/dist/function/identity.d.ts +22 -0
  56. package/dist/function/index.d.mts +1 -0
  57. package/dist/function/index.d.ts +1 -0
  58. package/dist/function/index.js +2 -1
  59. package/dist/function/index.mjs +1 -0
  60. package/dist/index.d.mts +4 -0
  61. package/dist/index.d.ts +4 -0
  62. package/dist/index.js +8 -3
  63. package/dist/index.mjs +4 -0
  64. package/dist/math/index.d.mts +2 -0
  65. package/dist/math/index.d.ts +2 -0
  66. package/dist/math/index.js +3 -1
  67. package/dist/math/index.mjs +2 -0
  68. package/dist/math/median.d.mts +25 -0
  69. package/dist/math/median.d.ts +25 -0
  70. package/dist/math/median.mjs +15 -0
  71. package/dist/math/medianBy.d.mts +23 -0
  72. package/dist/math/medianBy.d.ts +23 -0
  73. package/dist/math/medianBy.mjs +8 -0
  74. package/dist/object/cloneDeep.mjs +2 -2
  75. package/dist/object/index.js +1 -1
  76. package/dist/object/merge.d.mts +1 -1
  77. package/dist/object/merge.d.ts +1 -1
  78. package/dist/util/index.d.mts +1 -0
  79. package/dist/util/index.d.ts +1 -0
  80. package/dist/util/index.js +12 -0
  81. package/dist/util/index.mjs +1 -0
  82. package/dist/util/invariant.d.mts +27 -0
  83. package/dist/util/invariant.d.ts +27 -0
  84. package/dist/util/invariant.mjs +8 -0
  85. package/package.json +21 -1
  86. package/util.d.ts +1 -0
  87. /package/dist/{compat/_internal → function}/identity.mjs +0 -0
@@ -7,7 +7,6 @@ export { flatMapDeep } from '../array/flatMapDeep.js';
7
7
  export { forEachRight } from '../array/forEachRight.js';
8
8
  export { groupBy } from '../array/groupBy.js';
9
9
  export { initial } from '../array/initial.js';
10
- export { intersectionBy } from '../array/intersectionBy.js';
11
10
  export { intersectionWith } from '../array/intersectionWith.js';
12
11
  export { isSubset } from '../array/isSubset.js';
13
12
  export { keyBy } from '../array/keyBy.js';
@@ -36,6 +35,7 @@ export { zipWith } from '../array/zipWith.js';
36
35
  export { AbortError } from '../error/AbortError.js';
37
36
  export { TimeoutError } from '../error/TimeoutError.js';
38
37
  export { after } from '../function/after.js';
38
+ export { identity } from '../function/identity.js';
39
39
  export { MemoizeCache, memoize } from '../function/memoize.js';
40
40
  export { negate } from '../function/negate.js';
41
41
  export { noop } from '../function/noop.js';
@@ -45,6 +45,8 @@ export { partialRight } from '../function/partialRight.js';
45
45
  export { unary } from '../function/unary.js';
46
46
  export { mean } from '../math/mean.js';
47
47
  export { meanBy } from '../math/meanBy.js';
48
+ export { median } from '../math/median.js';
49
+ export { medianBy } from '../math/medianBy.js';
48
50
  export { randomInt } from '../math/randomInt.js';
49
51
  export { range } from '../math/range.js';
50
52
  export { rangeRight } from '../math/rangeRight.js';
@@ -77,6 +79,7 @@ export { lowerFirst } from '../string/lowerFirst.js';
77
79
  export { pascalCase } from '../string/pascalCase.js';
78
80
  export { unescape } from '../string/unescape.js';
79
81
  export { upperFirst } from '../string/upperFirst.js';
82
+ export { invariant } from '../util/invariant.js';
80
83
  export { castArray } from './array/castArray.js';
81
84
  export { chunk } from './array/chunk.js';
82
85
  export { compact } from './array/compact.js';
@@ -99,6 +102,7 @@ export { head as first, head } from './array/head.js';
99
102
  export { includes } from './array/includes.js';
100
103
  export { indexOf } from './array/indexOf.js';
101
104
  export { intersection } from './array/intersection.js';
105
+ export { intersectionBy } from './array/intersectionBy.js';
102
106
  export { join } from './array/join.js';
103
107
  export { last } from './array/last.js';
104
108
  export { orderBy } from './array/orderBy.js';
@@ -198,6 +202,7 @@ export { snakeCase } from './string/snakeCase.js';
198
202
  export { startCase } from './string/startCase.js';
199
203
  export { startsWith } from './string/startsWith.js';
200
204
  export { upperCase } from './string/upperCase.js';
205
+ export { template, templateSettings } from './string/template.js';
201
206
  export { trim } from './string/trim.js';
202
207
  export { trimEnd } from './string/trimEnd.js';
203
208
  export { trimStart } from './string/trimStart.js';
@@ -212,3 +217,4 @@ export { toNumber } from './util/toNumber.js';
212
217
  export { toPath } from './util/toPath.js';
213
218
  export { toSafeInteger } from './util/toSafeInteger.js';
214
219
  export { toString } from './util/toString.js';
220
+ export { uniqueId } from './util/uniqueId.js';
@@ -4,14 +4,15 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const zipWith = require('../_chunk/zipWith-Dkv3D1.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const unary = require('../_chunk/unary-CMvKXy.js');
7
+ const unary = require('../_chunk/unary-CcTNuC.js');
8
8
  const noop = require('../_chunk/noop-2IwLUk.js');
9
- const sumBy = require('../_chunk/sumBy-BkErWJ.js');
9
+ const sumBy = require('../_chunk/sumBy-RVppiV.js');
10
10
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
11
- const toMerged = require('../_chunk/toMerged-BLnW4M.js');
11
+ const toMerged = require('../_chunk/toMerged-wNz52b.js');
12
12
  const isPlainObject$1 = require('../_chunk/isPlainObject-octpoD.js');
13
13
  const isWeakSet$1 = require('../_chunk/isWeakSet-D8h8bS.js');
14
14
  const upperFirst = require('../_chunk/upperFirst-BUECmK.js');
15
+ const util_index = require('../util/index.js');
15
16
 
16
17
  function castArray(value) {
17
18
  if (arguments.length === 0) {
@@ -62,17 +63,48 @@ function difference(arr, ...values) {
62
63
  return zipWith.difference(arr1, arr2);
63
64
  }
64
65
 
65
- function drop(collection, itemsCount) {
66
+ function isSymbol(value) {
67
+ return typeof value === 'symbol' || value instanceof Symbol;
68
+ }
69
+
70
+ function toNumber(value) {
71
+ if (isSymbol(value)) {
72
+ return NaN;
73
+ }
74
+ return Number(value);
75
+ }
76
+
77
+ function toFinite(value) {
78
+ if (!value) {
79
+ return value === 0 ? value : 0;
80
+ }
81
+ value = toNumber(value);
82
+ if (value === Infinity || value === -Infinity) {
83
+ const sign = value < 0 ? -1 : 1;
84
+ return sign * Number.MAX_VALUE;
85
+ }
86
+ return value === value ? value : 0;
87
+ }
88
+
89
+ function toInteger(value) {
90
+ const finite = toFinite(value);
91
+ const remainder = finite % 1;
92
+ return remainder ? finite - remainder : finite;
93
+ }
94
+
95
+ function drop(collection, itemsCount = 1, guard) {
66
96
  if (!isArrayLike(collection)) {
67
97
  return [];
68
98
  }
99
+ itemsCount = guard ? 1 : toInteger(itemsCount);
69
100
  return zipWith.drop(Array.from(collection), itemsCount);
70
101
  }
71
102
 
72
- function dropRight(collection, itemsCount) {
103
+ function dropRight(collection, itemsCount = 1, guard) {
73
104
  if (!isArrayLike(collection)) {
74
105
  return [];
75
106
  }
107
+ itemsCount = guard ? 1 : toInteger(itemsCount);
76
108
  return zipWith.dropRight(Array.from(collection), itemsCount);
77
109
  }
78
110
 
@@ -460,17 +492,27 @@ function dropWhileImpl(arr, predicate) {
460
492
  }
461
493
  }
462
494
 
463
- function identity(x) {
464
- return x;
495
+ function isIterateeCall(value, index, object) {
496
+ if (!isObject(object)) {
497
+ return false;
498
+ }
499
+ if ((typeof index === 'number' && isArrayLike(object) && isIndex(index) && index < object.length) ||
500
+ (typeof index === 'string' && index in object)) {
501
+ return isWeakSet$1.eq(object[index], value);
502
+ }
503
+ return false;
465
504
  }
466
505
 
467
- function every(source, doesMatch) {
506
+ function every(source, doesMatch, guard) {
468
507
  if (!source) {
469
508
  return true;
470
509
  }
471
510
  const values = Array.isArray(source) ? source : Object.values(source);
511
+ if (guard && isIterateeCall(source, doesMatch, guard)) {
512
+ doesMatch = undefined;
513
+ }
472
514
  if (!doesMatch) {
473
- doesMatch = identity;
515
+ doesMatch = unary.identity;
474
516
  }
475
517
  switch (typeof doesMatch) {
476
518
  case 'function': {
@@ -534,7 +576,7 @@ function filter(source, predicate) {
534
576
  return [];
535
577
  }
536
578
  if (!predicate) {
537
- predicate = identity;
579
+ predicate = unary.identity;
538
580
  }
539
581
  const collection = isArray(source) ? source : Object.values(source);
540
582
  switch (typeof predicate) {
@@ -707,35 +749,6 @@ function head(arr) {
707
749
  return zipWith.head(Array.from(arr));
708
750
  }
709
751
 
710
- function isSymbol(value) {
711
- return typeof value === 'symbol' || value instanceof Symbol;
712
- }
713
-
714
- function toNumber(value) {
715
- if (isSymbol(value)) {
716
- return NaN;
717
- }
718
- return Number(value);
719
- }
720
-
721
- function toFinite(value) {
722
- if (!value) {
723
- return value === 0 ? value : 0;
724
- }
725
- value = toNumber(value);
726
- if (value === Infinity || value === -Infinity) {
727
- const sign = value < 0 ? -1 : 1;
728
- return sign * Number.MAX_VALUE;
729
- }
730
- return value === value ? value : 0;
731
- }
732
-
733
- function toInteger(value) {
734
- const finite = toFinite(value);
735
- const remainder = finite % 1;
736
- return remainder ? finite - remainder : finite;
737
- }
738
-
739
752
  function includes(source, target, fromIndex, guard) {
740
753
  if (source == null) {
741
754
  return false;
@@ -808,6 +821,34 @@ function intersection(...arrays) {
808
821
  return result;
809
822
  }
810
823
 
824
+ function intersectionBy(array, ...values) {
825
+ if (!isArrayLikeObject(array)) {
826
+ return [];
827
+ }
828
+ const lastValue = zipWith.last(values);
829
+ if (lastValue === undefined) {
830
+ return Array.from(array);
831
+ }
832
+ let result = zipWith.uniq(Array.from(array));
833
+ const count = isArrayLikeObject(lastValue) ? values.length : values.length - 1;
834
+ for (let i = 0; i < count; ++i) {
835
+ const value = values[i];
836
+ if (!isArrayLikeObject(value)) {
837
+ return [];
838
+ }
839
+ if (isArrayLikeObject(lastValue)) {
840
+ result = zipWith.intersectionBy(result, Array.from(value), unary.identity);
841
+ }
842
+ else if (typeof lastValue === 'function') {
843
+ result = zipWith.intersectionBy(result, Array.from(value), value => lastValue(value));
844
+ }
845
+ else if (typeof lastValue === 'string') {
846
+ result = zipWith.intersectionBy(result, Array.from(value), property(lastValue));
847
+ }
848
+ }
849
+ return result;
850
+ }
851
+
811
852
  function join(array, separator = ',') {
812
853
  if (!isArrayLike(array)) {
813
854
  return '';
@@ -870,16 +911,20 @@ function isKey(value, object) {
870
911
  (object != null));
871
912
  }
872
913
 
873
- function orderBy(collection, criteria, orders) {
874
- if (collection == null || typeof collection === 'number') {
914
+ function orderBy(collection, criteria, orders, guard) {
915
+ if (collection == null) {
875
916
  return [];
876
917
  }
877
- if (typeof collection === 'object' && !Array.isArray(collection)) {
918
+ orders = guard ? undefined : orders;
919
+ if (!Array.isArray(collection)) {
878
920
  collection = Object.values(collection);
879
921
  }
880
922
  if (!Array.isArray(criteria)) {
881
923
  criteria = criteria == null ? [null] : [criteria];
882
924
  }
925
+ if (criteria.length === 0) {
926
+ criteria = [null];
927
+ }
883
928
  if (!Array.isArray(orders)) {
884
929
  orders = orders == null ? [] : [orders];
885
930
  }
@@ -959,17 +1004,6 @@ function size(target) {
959
1004
  return Object.keys(target).length;
960
1005
  }
961
1006
 
962
- function isIterateeCall(value, index, object) {
963
- if (!isObject(object)) {
964
- return false;
965
- }
966
- if ((typeof index === 'number' && isArrayLike(object) && isIndex(index) && index < object.length) ||
967
- (typeof index === 'string' && index in object)) {
968
- return isWeakSet$1.eq(object[index], value);
969
- }
970
- return false;
971
- }
972
-
973
1007
  function slice(array, start, end) {
974
1008
  if (!isArrayLike(array)) {
975
1009
  return [];
@@ -1004,38 +1038,57 @@ function slice(array, start, end) {
1004
1038
  return result;
1005
1039
  }
1006
1040
 
1007
- function some(arr, predicate, guard) {
1041
+ function some(source, predicate, guard) {
1042
+ if (!source) {
1043
+ return false;
1044
+ }
1008
1045
  if (guard != null) {
1009
1046
  predicate = undefined;
1010
1047
  }
1011
1048
  if (!predicate) {
1012
- predicate = identity;
1013
- }
1014
- if (!Array.isArray(arr)) {
1015
- return false;
1049
+ predicate = unary.identity;
1016
1050
  }
1051
+ const values = Array.isArray(source) ? source : Object.values(source);
1017
1052
  switch (typeof predicate) {
1018
1053
  case 'function': {
1019
- return arr.some(predicate);
1054
+ if (!Array.isArray(source)) {
1055
+ const keys = Object.keys(source);
1056
+ for (let i = 0; i < keys.length; i++) {
1057
+ const key = keys[i];
1058
+ const value = source[key];
1059
+ if (predicate(value, key, source)) {
1060
+ return true;
1061
+ }
1062
+ }
1063
+ return false;
1064
+ }
1065
+ return values.some(predicate);
1020
1066
  }
1021
1067
  case 'object': {
1022
1068
  if (Array.isArray(predicate) && predicate.length === 2) {
1023
1069
  const key = predicate[0];
1024
1070
  const value = predicate[1];
1025
- return arr.some(matchesProperty(key, value));
1071
+ return values.some(matchesProperty(key, value));
1026
1072
  }
1027
1073
  else {
1028
- return arr.some(matches(predicate));
1074
+ return values.some(matches(predicate));
1029
1075
  }
1030
1076
  }
1031
1077
  case 'string': {
1032
- return arr.some(property(predicate));
1078
+ return values.some(property(predicate));
1033
1079
  }
1034
1080
  }
1035
1081
  }
1036
1082
 
1037
- function sortBy(collection, criteria) {
1038
- return orderBy(collection, criteria, ['asc']);
1083
+ function sortBy(collection, ...criteria) {
1084
+ const length = criteria.length;
1085
+ if (length > 1 && isIterateeCall(collection, criteria[0], criteria[1])) {
1086
+ criteria = [];
1087
+ }
1088
+ else if (length > 2 && isIterateeCall(criteria[0], criteria[1], criteria[2])) {
1089
+ criteria = [criteria[0]];
1090
+ }
1091
+ return orderBy(collection, zipWith.flatten(criteria), ['asc']);
1039
1092
  }
1040
1093
 
1041
1094
  function tail(arr) {
@@ -1045,14 +1098,16 @@ function tail(arr) {
1045
1098
  return zipWith.tail(Array.from(arr));
1046
1099
  }
1047
1100
 
1048
- function take(arr, count = 1) {
1101
+ function take(arr, count = 1, guard) {
1102
+ count = guard ? 1 : toInteger(count);
1049
1103
  if (count < 1 || !isArrayLike(arr)) {
1050
1104
  return [];
1051
1105
  }
1052
1106
  return zipWith.take(Array.from(arr), count);
1053
1107
  }
1054
1108
 
1055
- function takeRight(arr, count = 1) {
1109
+ function takeRight(arr, count = 1, guard) {
1110
+ count = guard ? 1 : toInteger(count);
1056
1111
  if (count <= 0 || !isArrayLike(arr)) {
1057
1112
  return [];
1058
1113
  }
@@ -1628,7 +1683,7 @@ function invertBy(object, iteratee) {
1628
1683
  return result;
1629
1684
  }
1630
1685
  if (iteratee == null) {
1631
- iteratee = identity;
1686
+ iteratee = unary.identity;
1632
1687
  }
1633
1688
  const keys = Object.keys(object);
1634
1689
  for (let i = 0; i < keys.length; i++) {
@@ -1646,7 +1701,7 @@ function invertBy(object, iteratee) {
1646
1701
  }
1647
1702
 
1648
1703
  function mapKeys(object, getNewKey) {
1649
- getNewKey = getNewKey ?? identity;
1704
+ getNewKey = getNewKey ?? unary.identity;
1650
1705
  switch (typeof getNewKey) {
1651
1706
  case 'string':
1652
1707
  case 'symbol':
@@ -1661,7 +1716,7 @@ function mapKeys(object, getNewKey) {
1661
1716
  }
1662
1717
 
1663
1718
  function mapValues(object, getNewValue) {
1664
- getNewValue = getNewValue ?? identity;
1719
+ getNewValue = getNewValue ?? unary.identity;
1665
1720
  switch (typeof getNewValue) {
1666
1721
  case 'string':
1667
1722
  case 'symbol':
@@ -2110,6 +2165,86 @@ function upperCase(str) {
2110
2165
  return upperFirst.upperCase(normalizeForCase(str));
2111
2166
  }
2112
2167
 
2168
+ const esTemplateRegExp = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
2169
+ const unEscapedRegExp = /['\n\r\u2028\u2029\\]/g;
2170
+ const noMatchExp = /($^)/;
2171
+ const escapeMap = new Map([
2172
+ ['\\', '\\'],
2173
+ ["'", "'"],
2174
+ ['\n', 'n'],
2175
+ ['\r', 'r'],
2176
+ ['\u2028', 'u2028'],
2177
+ ['\u2029', 'u2029'],
2178
+ ]);
2179
+ function escapeString(match) {
2180
+ return `\\${escapeMap.get(match)}`;
2181
+ }
2182
+ const templateSettings = {
2183
+ escape: /<%-([\s\S]+?)%>/g,
2184
+ evaluate: /<%([\s\S]+?)%>/g,
2185
+ interpolate: /<%=([\s\S]+?)%>/g,
2186
+ variable: '',
2187
+ imports: {
2188
+ _: {
2189
+ escape,
2190
+ template,
2191
+ },
2192
+ },
2193
+ };
2194
+ function template(string, options, guard) {
2195
+ string = toString(string);
2196
+ if (guard) {
2197
+ options = templateSettings;
2198
+ }
2199
+ options = defaults({ ...options }, templateSettings);
2200
+ const delimitersRegExp = new RegExp([
2201
+ options.escape?.source ?? noMatchExp.source,
2202
+ options.interpolate?.source ?? noMatchExp.source,
2203
+ options.interpolate ? esTemplateRegExp.source : noMatchExp.source,
2204
+ options.evaluate?.source ?? noMatchExp.source,
2205
+ '$',
2206
+ ].join('|'), 'g');
2207
+ let lastIndex = 0;
2208
+ let isEvaluated = false;
2209
+ let source = `__p += ''`;
2210
+ for (const match of string.matchAll(delimitersRegExp)) {
2211
+ const [fullMatch, escapeValue, interpolateValue, esTemplateValue, evaluateValue] = match;
2212
+ const { index } = match;
2213
+ source += ` + '${string.slice(lastIndex, index).replace(unEscapedRegExp, escapeString)}'`;
2214
+ if (escapeValue) {
2215
+ source += ` + _.escape(${escapeValue})`;
2216
+ }
2217
+ if (interpolateValue) {
2218
+ source += ` + ((${interpolateValue}) == null ? '' : ${interpolateValue})`;
2219
+ }
2220
+ else if (esTemplateValue) {
2221
+ source += ` + ((${esTemplateValue}) == null ? '' : ${esTemplateValue})`;
2222
+ }
2223
+ if (evaluateValue) {
2224
+ source += `;\n${evaluateValue};\n __p += ''`;
2225
+ isEvaluated = true;
2226
+ }
2227
+ lastIndex = index + fullMatch.length;
2228
+ }
2229
+ const imports = defaults({ ...options.imports }, templateSettings.imports);
2230
+ const importsKeys = Object.keys(imports);
2231
+ const importValues = Object.values(imports);
2232
+ const sourceURL = `//# sourceURL=${options.sourceURL ? String(options.sourceURL).replace(/[\r\n]/g, ' ') : `es-toolkit.templateSource[${Date.now()}]`}\n`;
2233
+ const compiledFunction = `function(${options.variable || 'obj'}) {
2234
+ let __p = '';
2235
+ ${options.variable ? '' : 'if (obj == null) { obj = {}; }'}
2236
+ ${isEvaluated ? `function print() { __p += Array.prototype.join.call(arguments, ''); }` : ''}
2237
+ ${options.variable ? source : `with(obj) {\n${source}\n}`}
2238
+ return __p;
2239
+ }`;
2240
+ const result = attempt(() => new Function(...importsKeys, `${sourceURL}return ${compiledFunction}`)(...importValues));
2241
+ result.source = compiledFunction;
2242
+ if (result instanceof Error) {
2243
+ throw result;
2244
+ }
2245
+ return result;
2246
+ }
2247
+
2113
2248
  function trim(str, chars, guard) {
2114
2249
  if (str == null) {
2115
2250
  return '';
@@ -2218,6 +2353,12 @@ function toSafeInteger(value) {
2218
2353
  return clamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
2219
2354
  }
2220
2355
 
2356
+ let idCounter = 0;
2357
+ function uniqueId(prefix = '') {
2358
+ const id = ++idCounter;
2359
+ return `${prefix}${id}`;
2360
+ }
2361
+
2221
2362
  exports.at = zipWith.at;
2222
2363
  exports.countBy = zipWith.countBy;
2223
2364
  exports.differenceBy = zipWith.differenceBy;
@@ -2227,7 +2368,6 @@ exports.flatMapDeep = zipWith.flatMapDeep;
2227
2368
  exports.forEachRight = zipWith.forEachRight;
2228
2369
  exports.groupBy = zipWith.groupBy;
2229
2370
  exports.initial = zipWith.initial;
2230
- exports.intersectionBy = zipWith.intersectionBy;
2231
2371
  exports.intersectionWith = zipWith.intersectionWith;
2232
2372
  exports.isSubset = zipWith.isSubset;
2233
2373
  exports.keyBy = zipWith.keyBy;
@@ -2259,6 +2399,7 @@ exports.delay = promise_index.delay;
2259
2399
  exports.timeout = promise_index.timeout;
2260
2400
  exports.withTimeout = promise_index.withTimeout;
2261
2401
  exports.after = unary.after;
2402
+ exports.identity = unary.identity;
2262
2403
  exports.memoize = unary.memoize;
2263
2404
  exports.negate = unary.negate;
2264
2405
  exports.once = unary.once;
@@ -2268,6 +2409,8 @@ exports.unary = unary.unary;
2268
2409
  exports.noop = noop.noop;
2269
2410
  exports.mean = sumBy.mean;
2270
2411
  exports.meanBy = sumBy.meanBy;
2412
+ exports.median = sumBy.median;
2413
+ exports.medianBy = sumBy.medianBy;
2271
2414
  exports.range = sumBy.range;
2272
2415
  exports.rangeRight = sumBy.rangeRight;
2273
2416
  exports.sum = sumBy.sum;
@@ -2301,6 +2444,7 @@ exports.lowerFirst = upperFirst.lowerFirst;
2301
2444
  exports.pascalCase = upperFirst.pascalCase;
2302
2445
  exports.unescape = upperFirst.unescape;
2303
2446
  exports.upperFirst = upperFirst.upperFirst;
2447
+ exports.invariant = util_index.invariant;
2304
2448
  exports.ary = ary;
2305
2449
  exports.attempt = attempt;
2306
2450
  exports.before = before;
@@ -2352,6 +2496,7 @@ exports.inRange = inRange;
2352
2496
  exports.includes = includes;
2353
2497
  exports.indexOf = indexOf;
2354
2498
  exports.intersection = intersection;
2499
+ exports.intersectionBy = intersectionBy;
2355
2500
  exports.invertBy = invertBy;
2356
2501
  exports.isArguments = isArguments;
2357
2502
  exports.isArray = isArray;
@@ -2417,6 +2562,8 @@ exports.startsWith = startsWith;
2417
2562
  exports.tail = tail;
2418
2563
  exports.take = take;
2419
2564
  exports.takeRight = takeRight;
2565
+ exports.template = template;
2566
+ exports.templateSettings = templateSettings;
2420
2567
  exports.throttle = throttle;
2421
2568
  exports.times = times;
2422
2569
  exports.toDefaulted = toDefaulted;
@@ -2431,6 +2578,7 @@ exports.trim = trim;
2431
2578
  exports.trimEnd = trimEnd;
2432
2579
  exports.trimStart = trimStart;
2433
2580
  exports.uniq = uniq;
2581
+ exports.uniqueId = uniqueId;
2434
2582
  exports.unset = unset;
2435
2583
  exports.upperCase = upperCase;
2436
2584
  exports.without = without;
@@ -7,7 +7,6 @@ export { flatMapDeep } from '../array/flatMapDeep.mjs';
7
7
  export { forEachRight } from '../array/forEachRight.mjs';
8
8
  export { groupBy } from '../array/groupBy.mjs';
9
9
  export { initial } from '../array/initial.mjs';
10
- export { intersectionBy } from '../array/intersectionBy.mjs';
11
10
  export { intersectionWith } from '../array/intersectionWith.mjs';
12
11
  export { isSubset } from '../array/isSubset.mjs';
13
12
  export { keyBy } from '../array/keyBy.mjs';
@@ -36,6 +35,7 @@ export { zipWith } from '../array/zipWith.mjs';
36
35
  export { AbortError } from '../error/AbortError.mjs';
37
36
  export { TimeoutError } from '../error/TimeoutError.mjs';
38
37
  export { after } from '../function/after.mjs';
38
+ export { identity } from '../function/identity.mjs';
39
39
  export { memoize } from '../function/memoize.mjs';
40
40
  export { negate } from '../function/negate.mjs';
41
41
  export { noop } from '../function/noop.mjs';
@@ -45,6 +45,8 @@ export { partialRight } from '../function/partialRight.mjs';
45
45
  export { unary } from '../function/unary.mjs';
46
46
  export { mean } from '../math/mean.mjs';
47
47
  export { meanBy } from '../math/meanBy.mjs';
48
+ export { median } from '../math/median.mjs';
49
+ export { medianBy } from '../math/medianBy.mjs';
48
50
  export { randomInt } from '../math/randomInt.mjs';
49
51
  export { range } from '../math/range.mjs';
50
52
  export { rangeRight } from '../math/rangeRight.mjs';
@@ -79,6 +81,7 @@ export { lowerFirst } from '../string/lowerFirst.mjs';
79
81
  export { pascalCase } from '../string/pascalCase.mjs';
80
82
  export { unescape } from '../string/unescape.mjs';
81
83
  export { upperFirst } from '../string/upperFirst.mjs';
84
+ export { invariant } from '../util/invariant.mjs';
82
85
  export { castArray } from './array/castArray.mjs';
83
86
  export { chunk } from './array/chunk.mjs';
84
87
  export { compact } from './array/compact.mjs';
@@ -101,6 +104,7 @@ export { head as first, head } from './array/head.mjs';
101
104
  export { includes } from './array/includes.mjs';
102
105
  export { indexOf } from './array/indexOf.mjs';
103
106
  export { intersection } from './array/intersection.mjs';
107
+ export { intersectionBy } from './array/intersectionBy.mjs';
104
108
  export { join } from './array/join.mjs';
105
109
  export { last } from './array/last.mjs';
106
110
  export { orderBy } from './array/orderBy.mjs';
@@ -199,6 +203,7 @@ export { snakeCase } from './string/snakeCase.mjs';
199
203
  export { startCase } from './string/startCase.mjs';
200
204
  export { startsWith } from './string/startsWith.mjs';
201
205
  export { upperCase } from './string/upperCase.mjs';
206
+ export { template, templateSettings } from './string/template.mjs';
202
207
  export { trim } from './string/trim.mjs';
203
208
  export { trimEnd } from './string/trimEnd.mjs';
204
209
  export { trimStart } from './string/trimStart.mjs';
@@ -212,3 +217,4 @@ export { toNumber } from './util/toNumber.mjs';
212
217
  export { toPath } from './util/toPath.mjs';
213
218
  export { toSafeInteger } from './util/toSafeInteger.mjs';
214
219
  export { toString } from './util/toString.mjs';
220
+ export { uniqueId } from './util/uniqueId.mjs';
@@ -1,5 +1,5 @@
1
+ import { identity } from '../../function/identity.mjs';
1
2
  import { isNil } from '../../predicate/isNil.mjs';
2
- import { identity } from '../_internal/identity.mjs';
3
3
 
4
4
  function invertBy(object, iteratee) {
5
5
  const result = {};
@@ -1,6 +1,6 @@
1
1
  import { property } from './property.mjs';
2
+ import { identity } from '../../function/identity.mjs';
2
3
  import { mapKeys as mapKeys$1 } from '../../object/mapKeys.mjs';
3
- import { identity } from '../_internal/identity.mjs';
4
4
 
5
5
  function mapKeys(object, getNewKey) {
6
6
  getNewKey = getNewKey ?? identity;
@@ -1,6 +1,6 @@
1
1
  import { property } from './property.mjs';
2
+ import { identity } from '../../function/identity.mjs';
2
3
  import { mapValues as mapValues$1 } from '../../object/mapValues.mjs';
3
- import { identity } from '../_internal/identity.mjs';
4
4
 
5
5
  function mapValues(object, getNewValue) {
6
6
  getNewValue = getNewValue ?? identity;