es-toolkit 1.10.1-dev.240 → 1.10.1-dev.242

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.
@@ -41,7 +41,6 @@ export { xorBy } from '../array/xorBy.js';
41
41
  export { xorWith } from '../array/xorWith.js';
42
42
  export { zip } from '../array/zip.js';
43
43
  export { zipObject } from '../array/zipObject.js';
44
- export { z as zipObjectDeep } from '../zipObjectDeep-eeZxUsAU.js';
45
44
  export { zipWith } from '../array/zipWith.js';
46
45
  export { without } from '../array/without.js';
47
46
  export { head } from '../array/head.js';
@@ -109,6 +108,42 @@ export { capitalize } from '../string/capitalize.js';
109
108
  */
110
109
  declare function chunk<T>(arr: readonly T[], size?: number): T[][];
111
110
 
111
+ /**
112
+ * Creates a deeply nested object given arrays of paths and values.
113
+ *
114
+ * This function takes two arrays: one containing arrays of property paths, and the other containing corresponding values.
115
+ * 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.
116
+ * Paths can be dot-separated strings or arrays of property names.
117
+ *
118
+ * If the `keys` array is longer than the `values` array, the remaining keys will have `undefined` as their values.
119
+ *
120
+ * @template V - The type of elements in the array.
121
+ * @param {string[] | string[][]} keys - An array of property paths, each path can be a dot-separated string or an array of property names.
122
+ * @param {V[]} values - An array of values corresponding to the property paths.
123
+ * @returns {object} A new object composed of the given property paths and values.
124
+ *
125
+ * @example
126
+ * const paths = ['a.b.c', 'd.e.f'];
127
+ * const values = [1, 2];
128
+ * const result = zipObjectDeep(paths, values);
129
+ * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }
130
+ *
131
+ * @example
132
+ * const paths = [['a', 'b', 'c'], ['d', 'e', 'f']];
133
+ * const values = [1, 2];
134
+ * const result = zipObjectDeep(paths, values);
135
+ * // result will be { a: { b: { c: 1 } }, d: { e: { f: 2 } } }
136
+ *
137
+ * @example
138
+ * const paths = ['a.b[0].c', 'a.b[1].d'];
139
+ * const values = [1, 2];
140
+ * const result = zipObjectDeep(paths, values);
141
+ * // result will be { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
142
+ */
143
+ declare function zipObjectDeep<P extends string | number | symbol, V>(keys: P[], values: V[]): {
144
+ [K in P]: V;
145
+ };
146
+
112
147
  /**
113
148
  * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
114
149
  *
@@ -138,4 +173,4 @@ declare function chunk<T>(arr: readonly T[], size?: number): T[][];
138
173
  */
139
174
  declare function set<T>(obj: object, path: PropertyKey | readonly PropertyKey[], value: unknown): T;
140
175
 
141
- export { chunk, set };
176
+ export { chunk, set, zipObjectDeep };
@@ -582,77 +582,6 @@ function zipObject(keys, values) {
582
582
  return result;
583
583
  }
584
584
 
585
- // src/compat/_internal/isIndex.ts
586
- var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
587
- function isIndex(value) {
588
- switch (typeof value) {
589
- case "number": {
590
- return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;
591
- }
592
- case "symbol": {
593
- return false;
594
- }
595
- case "string": {
596
- return IS_UNSIGNED_INTEGER.test(value);
597
- }
598
- }
599
- }
600
-
601
- // src/compat/_internal/toPath.ts
602
- var ESCAPE_REGEXP = /\\(\\)?/g;
603
- var PROPERTY_REGEXP = RegExp(
604
- // Match anything that isn't a dot or bracket.
605
- `[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,
606
- "g"
607
- );
608
- function toPath(deepKey) {
609
- const result = [];
610
- if (deepKey[0] === ".") {
611
- result.push("");
612
- }
613
- let match;
614
- while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
615
- let [key, expr, quote, substr] = match;
616
- if (quote) {
617
- key = substr.replace(ESCAPE_REGEXP, "$1");
618
- } else if (expr) {
619
- key = expr.trim();
620
- }
621
- result.push(key);
622
- }
623
- return result;
624
- }
625
-
626
- // src/compat/object/set.ts
627
- function set(obj, path, value) {
628
- const resolvedPath = Array.isArray(path) ? path : typeof path === "string" ? toPath(path) : [path];
629
- let current = obj;
630
- for (let i = 0; i < resolvedPath.length - 1; i++) {
631
- const key = resolvedPath[i];
632
- const nextKey = resolvedPath[i + 1];
633
- if (current[key] == null) {
634
- current[key] = isIndex(nextKey) ? [] : {};
635
- }
636
- current = current[key];
637
- }
638
- const lastKey = resolvedPath[resolvedPath.length - 1];
639
- current[lastKey] = value;
640
- return obj;
641
- }
642
-
643
- // src/compat/array/zipObjectDeep.ts
644
- function zipObjectDeep(keys, values) {
645
- const result = {};
646
- const zipped = zip(keys, values);
647
- for (let i = 0; i < zipped.length; i++) {
648
- const [key, value] = zipped[i];
649
- if (key != null) {
650
- set(result, key, value);
651
- }
652
- }
653
- return result;
654
- }
655
-
656
585
  // src/array/zipWith.ts
657
586
  function zipWith(arr1, ...rest) {
658
587
  const arrs = [arr1, ...rest.slice(0, -1)];
@@ -1090,6 +1019,77 @@ function chunk2(arr, size = 1) {
1090
1019
  }
1091
1020
  return chunk(arr, size);
1092
1021
  }
1022
+
1023
+ // src/compat/_internal/isIndex.ts
1024
+ var IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
1025
+ function isIndex(value) {
1026
+ switch (typeof value) {
1027
+ case "number": {
1028
+ return Number.isInteger(value) && value >= 0 && value < Number.MAX_SAFE_INTEGER;
1029
+ }
1030
+ case "symbol": {
1031
+ return false;
1032
+ }
1033
+ case "string": {
1034
+ return IS_UNSIGNED_INTEGER.test(value);
1035
+ }
1036
+ }
1037
+ }
1038
+
1039
+ // src/compat/_internal/toPath.ts
1040
+ var ESCAPE_REGEXP = /\\(\\)?/g;
1041
+ var PROPERTY_REGEXP = RegExp(
1042
+ // Match anything that isn't a dot or bracket.
1043
+ `[^.[\\]]+|\\[(?:([^"'][^[]*)|(["'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))`,
1044
+ "g"
1045
+ );
1046
+ function toPath(deepKey) {
1047
+ const result = [];
1048
+ if (deepKey[0] === ".") {
1049
+ result.push("");
1050
+ }
1051
+ let match;
1052
+ while ((match = PROPERTY_REGEXP.exec(deepKey)) !== null) {
1053
+ let [key, expr, quote, substr] = match;
1054
+ if (quote) {
1055
+ key = substr.replace(ESCAPE_REGEXP, "$1");
1056
+ } else if (expr) {
1057
+ key = expr.trim();
1058
+ }
1059
+ result.push(key);
1060
+ }
1061
+ return result;
1062
+ }
1063
+
1064
+ // src/compat/object/set.ts
1065
+ function set(obj, path, value) {
1066
+ const resolvedPath = Array.isArray(path) ? path : typeof path === "string" ? toPath(path) : [path];
1067
+ let current = obj;
1068
+ for (let i = 0; i < resolvedPath.length - 1; i++) {
1069
+ const key = resolvedPath[i];
1070
+ const nextKey = resolvedPath[i + 1];
1071
+ if (current[key] == null) {
1072
+ current[key] = isIndex(nextKey) ? [] : {};
1073
+ }
1074
+ current = current[key];
1075
+ }
1076
+ const lastKey = resolvedPath[resolvedPath.length - 1];
1077
+ current[lastKey] = value;
1078
+ return obj;
1079
+ }
1080
+
1081
+ // src/compat/array/zipObjectDeep.ts
1082
+ function zipObjectDeep(keys, values) {
1083
+ const result = {};
1084
+ const zipped = zip(keys, values);
1085
+ for (let i = 0; i < zipped.length; i++) {
1086
+ const [key, value] = zipped[i];
1087
+ if (key != null) {
1088
+ set(result, key, value);
1089
+ }
1090
+ }
1091
+ return result;
1092
+ }
1093
1093
  // Annotate the CommonJS export names for ESM import in node:
1094
1094
  0 && (module.exports = {
1095
1095
  AbortError,