es-toolkit 1.10.1-dev.241 → 1.10.1-dev.243

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.
@@ -17,7 +17,7 @@ import {
17
17
  } from "../chunk-F3WCQQET.mjs";
18
18
  import {
19
19
  startCase
20
- } from "../chunk-MJA7DAOJ.mjs";
20
+ } from "../chunk-QXTNZR7B.mjs";
21
21
  import "../chunk-WVQ7YVRK.mjs";
22
22
  import "../chunk-ASJF5D6C.mjs";
23
23
  import {
@@ -83,10 +83,7 @@ import {
83
83
  import {
84
84
  inRange
85
85
  } from "../chunk-BH6HLGBA.mjs";
86
- import {
87
- set,
88
- zipObjectDeep
89
- } from "../chunk-MKCRW4QT.mjs";
86
+ import "../chunk-DDH7K4QM.mjs";
90
87
  import {
91
88
  xor
92
89
  } from "../chunk-L7FQX5MN.mjs";
@@ -276,6 +273,77 @@ function chunk2(arr, size = 1) {
276
273
  }
277
274
  return chunk(arr, size);
278
275
  }
276
+
277
+ // src/compat/_internal/isIndex.ts
278
+ var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
279
+ function isIndex(value) {
280
+ switch (typeof value) {
281
+ case "number": {
282
+ return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;
283
+ }
284
+ case "symbol": {
285
+ return false;
286
+ }
287
+ case "string": {
288
+ return IS_UNSIGNED_INTEGER.test(value);
289
+ }
290
+ }
291
+ }
292
+
293
+ // src/compat/_internal/toPath.ts
294
+ var ESCAPE_REGEXP = /\\(\\)?/g;
295
+ var PROPERTY_REGEXP = RegExp(
296
+ // Match anything that isn't a dot or bracket.
297
+ `[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,
298
+ "g"
299
+ );
300
+ function toPath(deepKey) {
301
+ const result = [];
302
+ if (deepKey[0] === ".") {
303
+ result.push("");
304
+ }
305
+ let match;
306
+ while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
307
+ let [key, expr, quote, substr] = match;
308
+ if (quote) {
309
+ key = substr.replace(ESCAPE_REGEXP, "$1");
310
+ } else if (expr) {
311
+ key = expr.trim();
312
+ }
313
+ result.push(key);
314
+ }
315
+ return result;
316
+ }
317
+
318
+ // src/compat/object/set.ts
319
+ function set(obj, path, value) {
320
+ const resolvedPath = Array.isArray(path) ? path : typeof path === "string" ? toPath(path) : [path];
321
+ let current = obj;
322
+ for (let i = 0; i < resolvedPath.length - 1; i++) {
323
+ const key = resolvedPath[i];
324
+ const nextKey = resolvedPath[i + 1];
325
+ if (current[key] == null) {
326
+ current[key] = isIndex(nextKey) ? [] : {};
327
+ }
328
+ current = current[key];
329
+ }
330
+ const lastKey = resolvedPath[resolvedPath.length - 1];
331
+ current[lastKey] = value;
332
+ return obj;
333
+ }
334
+
335
+ // src/compat/array/zipObjectDeep.ts
336
+ function zipObjectDeep(keys, values) {
337
+ const result = {};
338
+ const zipped = zip(keys, values);
339
+ for (let i = 0; i < zipped.length; i++) {
340
+ const [key, value] = zipped[i];
341
+ if (key != null) {
342
+ set(result, key, value);
343
+ }
344
+ }
345
+ return result;
346
+ }
279
347
  export {
280
348
  AbortError,
281
349
  camelCase,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compat/array/chunk.ts"],"sourcesContent":["import { chunk as chunkToolkit } from '../../array/chunk.ts';\n\n/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number = 1): T[][] {\n size = Math.max(Math.floor(size), 0);\n\n if (size === 0) {\n return [];\n }\n\n return chunkToolkit(arr, size);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAASA,OAAS,KAAmB,OAAe,GAAU;AACnE,SAAO,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC;AAEnC,MAAI,SAAS,GAAG;AACd,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,MAAa,KAAK,IAAI;AAC/B;","names":["chunk"]}
1
+ {"version":3,"sources":["../../src/compat/array/chunk.ts","../../src/compat/_internal/isIndex.ts","../../src/compat/_internal/toPath.ts","../../src/compat/object/set.ts","../../src/compat/array/zipObjectDeep.ts"],"sourcesContent":["import { chunk as chunkToolkit } from '../../array/chunk.ts';\n\n/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number = 1): T[][] {\n size = Math.max(Math.floor(size), 0);\n\n if (size === 0) {\n return [];\n }\n\n return chunkToolkit(arr, size);\n}\n","const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\\d*)$/\n\nexport function isIndex(value: PropertyKey) {\n switch (typeof value) {\n case 'number': {\n return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;\n }\n case 'symbol': {\n return false;\n }\n case 'string': {\n return IS_UNSIGNED_INTEGER.test(value);\n }\n }\n}","const ESCAPE_REGEXP = /\\\\(\\\\)?/g;\nconst PROPERTY_REGEXP = RegExp(\n // Match anything that isn't a dot or bracket.\n \"[^.[\\\\]]+\" +\n \"|\" +\n // Or match property names within brackets.\n \"\\\\[(?:\" +\n // Match a non-string expression.\n \"([^\\\"'][^[]*)\" +\n \"|\" +\n // Or match strings (supports escaping characters).\n \"([\\\"'])((?:(?!\\\\2)[^\\\\\\\\]|\\\\\\\\.)*?)\\\\2\" +\n \")\\\\]\" +\n \"|\" +\n // Or match \"\" as the space between consecutive dots or empty brackets.\n \"(?=(?:\\\\.|\\\\[\\\\])(?:\\\\.|\\\\[\\\\]|$))\",\n \"g\",\n);\n\n/**\n * Converts a deep key string into an array of path segments.\n *\n * This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.\n *\n * @param deepKey - The deep key string to convert.\n * @returns An array of strings, each representing a segment of the path.\n *\n * Examples:\n *\n * toPath('a.b.c') // Returns ['a', 'b', 'c']\n * toPath('a[b][c]') // Returns ['a', 'b', 'c']\n * toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']\n * toPath('a[\"b.c\"].d') // Returns ['a', 'b.c', 'd']\n * toPath('') // Returns []\n * toPath('.a[b].c.d[e][\"f.g\"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']\n */\nexport function toPath(deepKey: string): string[] {\n const result: string[] = [];\n\n if (deepKey[0] === \".\") {\n result.push(\"\");\n }\n\n let match: RegExpExecArray | null;\n\n while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {\n let [key, expr, quote, substr] = match;\n\n if (quote) {\n key = substr.replace(ESCAPE_REGEXP, \"$1\");\n } else if (expr) {\n key = expr.trim();\n }\n\n result.push(key);\n }\n\n return result;\n}\n","import { isIndex } from \"../_internal/isIndex.ts\";\nimport { toPath } from \"../_internal/toPath.ts\";\n\n/**\n * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.\n *\n * @template T - The type of the object.\n * @param {Settable} obj - The object to modify.\n * @param {Path} path - The path of the property to set.\n * @param {any} value - The value to set.\n * @returns {T} - The modified object.\n *\n * @example\n * // Set a value in a nested object\n * const obj = { a: { b: { c: 3 } } };\n * set(obj, 'a.b.c', 4);\n * console.log(obj.a.b.c); // 4\n *\n * @example\n * // Set a value in an array\n * const arr = [1, 2, 3];\n * set(arr, 1, 4);\n * console.log(arr[1]); // 4\n *\n * @example\n * // Create non-existent path and set value\n * const obj = {};\n * set(obj, 'a.b.c', 4);\n * console.log(obj); // { a: { b: { c: 4 } } }\n */\nexport function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;\nexport function set<T extends object>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown): T {\n const resolvedPath = Array.isArray(path)\n ? path\n : typeof path === 'string'\n ? toPath(path)\n : [path];\n\n let current: any = obj;\n\n for (let i = 0; i < resolvedPath.length - 1; i++) {\n const key = resolvedPath[i];\n const nextKey = resolvedPath[i + 1];\n\n if (current[key] == null) {\n current[key] = isIndex(nextKey) ? [] : {};\n }\n\n current = current[key];\n }\n\n const lastKey = resolvedPath[resolvedPath.length - 1];\n current[lastKey] = value;\n\n return obj;\n}\n","import { zip } from \"../../array/zip.ts\";\nimport { set } from \"../object/set.ts\";\n\n/**\n * Creates a deeply nested object given arrays of paths and values.\n *\n * This function takes two arrays: one containing arrays of property paths, and the other containing corresponding values.\n * It returns a new object where paths from the first array are used as key paths to set values, with corresponding elements from the second array as values.\n * Paths can be dot-separated strings or arrays of property names.\n * \n * If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values.\n *\n * @template V - The type of elements in the array.\n * @param {string[] | string[][]} keys - An array of property paths, each path can be a dot-separated string or an array of property names.\n * @param {V[]} values - An array of values corresponding to the property paths.\n * @returns {object} A new object composed of the given property paths and values.\n *\n * @example\n * const paths = ['a.b.c', 'd.e.f'];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }\n *\n * @example\n * const paths = [['a', 'b', 'c'], ['d', 'e', 'f']];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }\n * \n * @example\n * const paths = ['a.b[0].c', 'a.b[1].d'];\n * const values = [1, 2];\n * const result = zipObjectDeep(paths, values);\n * // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }\n */\nexport function zipObjectDeep<P extends string | number | symbol, V>(keys: P[], values: V[]): { [K in P]: V } {\n const result = {} as { [K in P]: V };\n const zipped = zip(keys, values);\n\n for (let i = 0; i < zipped.length; i++) {\n const [key, value] = zipped[i];\n\n if (key != null) {\n set(result, key, value);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,QAAQ,IAAI,IACnC,OACA,OAAO,SAAS,WACd,OAAO,IAAI,IACX,CAAC,IAAI;AAEX,MAAI,UAAe;AAEnB,WAAS,IAAI,GAAG,IAAI,aAAa,SAAS,GAAG,KAAK;AAChD,UAAM,MAAM,aAAa,CAAC;AAC1B,UAAM,UAAU,aAAa,IAAI,CAAC;AAElC,QAAI,QAAQ,GAAG,KAAK,MAAM;AACxB,cAAQ,GAAG,IAAI,QAAQ,OAAO,IAAI,CAAC,IAAI,CAAC;AAAA,IAC1C;AAEA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,QAAM,UAAU,aAAa,aAAa,SAAS,CAAC;AACpD,UAAQ,OAAO,IAAI;AAEnB,SAAO;AACT;;;ACpBO,SAAS,cAAqD,MAAW,QAA8B;AAC5G,QAAM,SAAS,CAAC;AAChB,QAAM,SAAS,IAAI,MAAM,MAAM;AAE/B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,UAAM,CAAC,KAAK,KAAK,IAAI,OAAO,CAAC;AAE7B,QAAI,OAAO,MAAM;AACf,UAAI,QAAQ,KAAK,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SAAO;AACT;","names":["chunk"]}
package/dist/index.d.mts CHANGED
@@ -42,7 +42,6 @@ export { xorBy } from './array/xorBy.mjs';
42
42
  export { xorWith } from './array/xorWith.mjs';
43
43
  export { zip } from './array/zip.mjs';
44
44
  export { zipObject } from './array/zipObject.mjs';
45
- export { z as zipObjectDeep } from './zipObjectDeep-eeZxUsAU.mjs';
46
45
  export { zipWith } from './array/zipWith.mjs';
47
46
  export { without } from './array/without.mjs';
48
47
  export { head } from './array/head.mjs';
package/dist/index.d.ts CHANGED
@@ -42,7 +42,6 @@ export { xorBy } from './array/xorBy.js';
42
42
  export { xorWith } from './array/xorWith.js';
43
43
  export { zip } from './array/zip.js';
44
44
  export { zipObject } from './array/zipObject.js';
45
- export { z as zipObjectDeep } from './zipObjectDeep-eeZxUsAU.js';
46
45
  export { zipWith } from './array/zipWith.js';
47
46
  export { without } from './array/without.js';
48
47
  export { head } from './array/head.js';
package/dist/index.js CHANGED
@@ -118,7 +118,6 @@ __export(src_exports, {
118
118
  xorWith: () => xorWith,
119
119
  zip: () => zip,
120
120
  zipObject: () => zipObject,
121
- zipObjectDeep: () => zipObjectDeep,
122
121
  zipWith: () => zipWith
123
122
  });
124
123
  module.exports = __toCommonJS(src_exports);
@@ -581,77 +580,6 @@ function zipObject(keys, values) {
581
580
  return result;
582
581
  }
583
582
 
584
- // src/compat/_internal/isIndex.ts
585
- var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
586
- function isIndex(value) {
587
- switch (typeof value) {
588
- case "number": {
589
- return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;
590
- }
591
- case "symbol": {
592
- return false;
593
- }
594
- case "string": {
595
- return IS_UNSIGNED_INTEGER.test(value);
596
- }
597
- }
598
- }
599
-
600
- // src/compat/_internal/toPath.ts
601
- var ESCAPE_REGEXP = /\\(\\)?/g;
602
- var PROPERTY_REGEXP = RegExp(
603
- // Match anything that isn't a dot or bracket.
604
- `[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,
605
- "g"
606
- );
607
- function toPath(deepKey) {
608
- const result = [];
609
- if (deepKey[0] === ".") {
610
- result.push("");
611
- }
612
- let match;
613
- while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
614
- let [key, expr, quote, substr] = match;
615
- if (quote) {
616
- key = substr.replace(ESCAPE_REGEXP, "$1");
617
- } else if (expr) {
618
- key = expr.trim();
619
- }
620
- result.push(key);
621
- }
622
- return result;
623
- }
624
-
625
- // src/compat/object/set.ts
626
- function set(obj, path, value) {
627
- const resolvedPath = Array.isArray(path) ? path : typeof path === "string" ? toPath(path) : [path];
628
- let current = obj;
629
- for (let i = 0; i < resolvedPath.length - 1; i++) {
630
- const key = resolvedPath[i];
631
- const nextKey = resolvedPath[i + 1];
632
- if (current[key] == null) {
633
- current[key] = isIndex(nextKey) ? [] : {};
634
- }
635
- current = current[key];
636
- }
637
- const lastKey = resolvedPath[resolvedPath.length - 1];
638
- current[lastKey] = value;
639
- return obj;
640
- }
641
-
642
- // src/compat/array/zipObjectDeep.ts
643
- function zipObjectDeep(keys, values) {
644
- const result = {};
645
- const zipped = zip(keys, values);
646
- for (let i = 0; i < zipped.length; i++) {
647
- const [key, value] = zipped[i];
648
- if (key != null) {
649
- set(result, key, value);
650
- }
651
- }
652
- return result;
653
- }
654
-
655
583
  // src/array/zipWith.ts
656
584
  function zipWith(arr1, ...rest) {
657
585
  const arrs = [arr1, ...rest.slice(0, -1)];
@@ -1166,7 +1094,6 @@ function startCase(str) {
1166
1094
  xorWith,
1167
1095
  zip,
1168
1096
  zipObject,
1169
- zipObjectDeep,
1170
1097
  zipWith
1171
1098
  });
1172
1099
  //# sourceMappingURL=index.js.map