es-toolkit 1.13.0 → 1.13.1-dev.297

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # es-toolkit Changelog
2
2
 
3
+ ## Version v1.13.1
4
+
5
+ Released on July 20th, 2024.
6
+
7
+ - Use the compatibility layer `es-toolkit/compat` in legacy CDN builds.
8
+
3
9
  ## Version v1.13.0
4
10
 
5
11
  Released on July 20th, 2024.
package/dist/browser.js CHANGED
@@ -40,33 +40,37 @@ var __async = (__this, __arguments, generator) => {
40
40
  });
41
41
  };
42
42
 
43
- // src/index.ts
44
- var src_exports = {};
45
- __export(src_exports, {
43
+ // src/compat/index.ts
44
+ var compat_exports = {};
45
+ __export(compat_exports, {
46
46
  AbortError: () => AbortError,
47
47
  TimeoutError: () => TimeoutError,
48
48
  camelCase: () => camelCase,
49
49
  capitalize: () => capitalize,
50
- chunk: () => chunk,
50
+ chunk: () => chunk2,
51
51
  clamp: () => clamp,
52
52
  clone: () => clone,
53
53
  compact: () => compact,
54
+ concat: () => concat,
54
55
  countBy: () => countBy,
55
56
  debounce: () => debounce,
56
57
  delay: () => delay,
57
- difference: () => difference,
58
+ difference: () => difference2,
58
59
  differenceBy: () => differenceBy,
59
60
  differenceWith: () => differenceWith,
60
61
  drop: () => drop,
61
62
  dropRight: () => dropRight,
62
63
  dropRightWhile: () => dropRightWhile,
63
64
  dropWhile: () => dropWhile,
65
+ endsWith: () => endsWith,
64
66
  fill: () => fill,
67
+ first: () => head,
65
68
  flatMap: () => flatMap,
66
69
  flatten: () => flatten,
67
70
  flattenDeep: () => flattenDeep,
68
71
  flattenObject: () => flattenObject,
69
72
  forEachRight: () => forEachRight,
73
+ get: () => get,
70
74
  groupBy: () => groupBy,
71
75
  head: () => head,
72
76
  inRange: () => inRange,
@@ -80,15 +84,17 @@ __export(src_exports, {
80
84
  isNil: () => isNil,
81
85
  isNotNil: () => isNotNil,
82
86
  isNull: () => isNull,
83
- isPlainObject: () => isPlainObject,
87
+ isPlainObject: () => isPlainObject2,
84
88
  isUndefined: () => isUndefined,
85
89
  kebabCase: () => kebabCase,
86
90
  keyBy: () => keyBy,
87
91
  last: () => last,
88
92
  lowerCase: () => lowerCase,
93
+ max: () => max,
89
94
  maxBy: () => maxBy,
90
95
  mean: () => mean,
91
96
  meanBy: () => meanBy,
97
+ min: () => min,
92
98
  minBy: () => minBy,
93
99
  negate: () => negate,
94
100
  noop: () => noop,
@@ -105,9 +111,11 @@ __export(src_exports, {
105
111
  round: () => round,
106
112
  sample: () => sample,
107
113
  sampleSize: () => sampleSize,
114
+ set: () => set,
108
115
  shuffle: () => shuffle,
109
116
  snakeCase: () => snakeCase,
110
117
  startCase: () => startCase,
118
+ startsWith: () => startsWith,
111
119
  sum: () => sum,
112
120
  sumBy: () => sumBy,
113
121
  tail: () => tail,
@@ -132,6 +140,7 @@ __export(src_exports, {
132
140
  xorWith: () => xorWith,
133
141
  zip: () => zip,
134
142
  zipObject: () => zipObject,
143
+ zipObjectDeep: () => zipObjectDeep,
135
144
  zipWith: () => zipWith
136
145
  });
137
146
 
@@ -324,11 +333,11 @@ function keyBy(arr, getKeyFromItem) {
324
333
  // src/array/maxBy.ts
325
334
  function maxBy(items, getValue) {
326
335
  let maxElement = items[0];
327
- let max = -Infinity;
336
+ let max2 = -Infinity;
328
337
  for (const element of items) {
329
338
  const value = getValue(element);
330
- if (value > max) {
331
- max = value;
339
+ if (value > max2) {
340
+ max2 = value;
332
341
  maxElement = element;
333
342
  }
334
343
  }
@@ -338,11 +347,11 @@ function maxBy(items, getValue) {
338
347
  // src/array/minBy.ts
339
348
  function minBy(items, getValue) {
340
349
  let minElement = items[0];
341
- let min = Infinity;
350
+ let min2 = Infinity;
342
351
  for (const element of items) {
343
352
  const value = getValue(element);
344
- if (value < min) {
345
- min = value;
353
+ if (value < min2) {
354
+ min2 = value;
346
355
  minElement = element;
347
356
  }
348
357
  }
@@ -1103,6 +1112,214 @@ function startCase(str) {
1103
1112
  return result;
1104
1113
  }
1105
1114
 
1115
+ // src/compat/array/chunk.ts
1116
+ function chunk2(arr, size = 1) {
1117
+ size = Math.max(Math.floor(size), 0);
1118
+ if (size === 0) {
1119
+ return [];
1120
+ }
1121
+ return chunk(arr, size);
1122
+ }
1123
+
1124
+ // src/compat/array/concat.ts
1125
+ function concat(...values) {
1126
+ return flatten(values);
1127
+ }
1128
+
1129
+ // src/compat/array/difference.ts
1130
+ function difference2(arr, ...values) {
1131
+ const arr1 = arr;
1132
+ const arr2 = flatten(values);
1133
+ return difference(arr1, arr2);
1134
+ }
1135
+
1136
+ // src/compat/_internal/isIndex.ts
1137
+ var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
1138
+ function isIndex(value) {
1139
+ switch (typeof value) {
1140
+ case "number": {
1141
+ return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;
1142
+ }
1143
+ case "symbol": {
1144
+ return false;
1145
+ }
1146
+ case "string": {
1147
+ return IS_UNSIGNED_INTEGER.test(value);
1148
+ }
1149
+ }
1150
+ }
1151
+
1152
+ // src/compat/_internal/toPath.ts
1153
+ function toPath(deepKey) {
1154
+ const ESCAPE_REGEXP = /\\(\\)?/g;
1155
+ const PROPERTY_REGEXP = RegExp(
1156
+ // Match anything that isn't a dot or bracket.
1157
+ `[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,
1158
+ "g"
1159
+ );
1160
+ const result = [];
1161
+ if (deepKey[0] === ".") {
1162
+ result.push("");
1163
+ }
1164
+ let match;
1165
+ let lastIndex = 0;
1166
+ let count = 0;
1167
+ while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
1168
+ let [key, expr, quote, substr] = match;
1169
+ if (quote) {
1170
+ key = substr.replace(ESCAPE_REGEXP, "$1");
1171
+ } else if (expr) {
1172
+ key = expr;
1173
+ }
1174
+ result.push(key);
1175
+ if (PROPERTY_REGEXP.lastIndex === lastIndex) {
1176
+ PROPERTY_REGEXP.lastIndex++;
1177
+ } else {
1178
+ lastIndex = PROPERTY_REGEXP.lastIndex;
1179
+ }
1180
+ }
1181
+ return result;
1182
+ }
1183
+
1184
+ // src/compat/object/set.ts
1185
+ function set(obj, path, value) {
1186
+ const resolvedPath = Array.isArray(path) ? path : typeof path === "string" ? toPath(path) : [path];
1187
+ let current = obj;
1188
+ for (let i = 0; i < resolvedPath.length - 1; i++) {
1189
+ const key = resolvedPath[i];
1190
+ const nextKey = resolvedPath[i + 1];
1191
+ if (current[key] == null) {
1192
+ current[key] = isIndex(nextKey) ? [] : {};
1193
+ }
1194
+ current = current[key];
1195
+ }
1196
+ const lastKey = resolvedPath[resolvedPath.length - 1];
1197
+ current[lastKey] = value;
1198
+ return obj;
1199
+ }
1200
+
1201
+ // src/compat/array/zipObjectDeep.ts
1202
+ function zipObjectDeep(keys, values) {
1203
+ const result = {};
1204
+ const zipped = zip(keys, values);
1205
+ for (let i = 0; i < zipped.length; i++) {
1206
+ const [key, value] = zipped[i];
1207
+ if (key != null) {
1208
+ set(result, key, value);
1209
+ }
1210
+ }
1211
+ return result;
1212
+ }
1213
+
1214
+ // src/compat/_internal/isDeepKey.ts
1215
+ var IS_PLAIN = /^\w*$/;
1216
+ var IS_DEEP = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
1217
+ function isDeepKey(key) {
1218
+ switch (typeof key) {
1219
+ case "number":
1220
+ case "symbol": {
1221
+ return false;
1222
+ }
1223
+ case "string": {
1224
+ return !IS_PLAIN.test(key) && IS_DEEP.test(key);
1225
+ }
1226
+ }
1227
+ }
1228
+
1229
+ // src/compat/object/get.ts
1230
+ function get(object, path, defaultValue) {
1231
+ let resolvedPath;
1232
+ if (Array.isArray(path)) {
1233
+ resolvedPath = path;
1234
+ } else if (typeof path === "string" && isDeepKey(path) && (object == null ? void 0 : object[path]) == null) {
1235
+ resolvedPath = toPath(path);
1236
+ } else {
1237
+ resolvedPath = [path];
1238
+ }
1239
+ if (resolvedPath.length === 0) {
1240
+ return defaultValue;
1241
+ }
1242
+ let current = object;
1243
+ let index;
1244
+ for (index = 0; index < resolvedPath.length && current != null; index++) {
1245
+ let key = resolvedPath[index];
1246
+ if (Object.is(key.valueOf(), -0)) {
1247
+ key = "-0";
1248
+ }
1249
+ current = current[key];
1250
+ }
1251
+ if (current === null && index === resolvedPath.length) {
1252
+ return current;
1253
+ }
1254
+ return current != null ? current : defaultValue;
1255
+ }
1256
+
1257
+ // src/compat/predicate/isPlainObject.ts
1258
+ function isPlainObject2(object) {
1259
+ var _a;
1260
+ if (typeof object !== "object") {
1261
+ return false;
1262
+ }
1263
+ if (object == null) {
1264
+ return false;
1265
+ }
1266
+ if (Object.getPrototypeOf(object) === null) {
1267
+ return true;
1268
+ }
1269
+ if (object.toString() !== "[object Object]") {
1270
+ const tag = object[Symbol.toStringTag];
1271
+ if (tag == null) {
1272
+ return false;
1273
+ }
1274
+ const isTagReadonly = !((_a = Object.getOwnPropertyDescriptor(object, Symbol.toStringTag)) == null ? void 0 : _a.writable);
1275
+ if (isTagReadonly) {
1276
+ return false;
1277
+ }
1278
+ return object.toString() === `[object ${tag}]`;
1279
+ }
1280
+ let proto = object;
1281
+ while (Object.getPrototypeOf(proto) !== null) {
1282
+ proto = Object.getPrototypeOf(proto);
1283
+ }
1284
+ return Object.getPrototypeOf(object) === proto;
1285
+ }
1286
+
1287
+ // src/compat/string/startsWith.ts
1288
+ var startsWith = (str, target, position = 0) => {
1289
+ return str.startsWith(target, position);
1290
+ };
1291
+
1292
+ // src/compat/string/endsWith.ts
1293
+ var endsWith = (str, target, position = str.length) => {
1294
+ return str.endsWith(target, position);
1295
+ };
1296
+
1297
+ // src/compat/math/max.ts
1298
+ function max(items = []) {
1299
+ let maxElement = items[0];
1300
+ let max2 = void 0;
1301
+ for (const element of items) {
1302
+ if (max2 == null || element > max2) {
1303
+ max2 = element;
1304
+ maxElement = element;
1305
+ }
1306
+ }
1307
+ return maxElement;
1308
+ }
1309
+
1310
+ // src/compat/math/min.ts
1311
+ function min(items = []) {
1312
+ let minElement = items[0];
1313
+ let min2 = void 0;
1314
+ for (const element of items) {
1315
+ if (min2 == null || element < min2) {
1316
+ min2 = element;
1317
+ minElement = element;
1318
+ }
1319
+ }
1320
+ return minElement;
1321
+ }
1322
+
1106
1323
  // src/browser.ts
1107
- window._ = src_exports;
1324
+ window._ = compat_exports;
1108
1325
  //# sourceMappingURL=browser.js.map