es-toolkit 1.10.1-dev.230 → 1.10.1-dev.231

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,4 +1,5 @@
1
1
  import "../chunk-NKLIE2OI.mjs";
2
+ import "../chunk-ARZ5BDR6.mjs";
2
3
  import "../chunk-XT74R35S.mjs";
3
4
  import {
4
5
  camelCase
@@ -35,11 +36,13 @@ import {
35
36
  import {
36
37
  isUndefined
37
38
  } from "../chunk-VH2PV426.mjs";
38
- import "../chunk-ARZ5BDR6.mjs";
39
39
  import {
40
40
  delay
41
41
  } from "../chunk-O64NE2P4.mjs";
42
- import "../chunk-OSOLEQLZ.mjs";
42
+ import "../chunk-54TK5BIS.mjs";
43
+ import {
44
+ set
45
+ } from "../chunk-GL7PPRA4.mjs";
43
46
  import {
44
47
  clone
45
48
  } from "../chunk-U4JGKZ56.mjs";
@@ -332,6 +335,7 @@ export {
332
335
  round,
333
336
  sample,
334
337
  sampleSize,
338
+ set,
335
339
  shuffle,
336
340
  snakeCase,
337
341
  startCase,
@@ -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"],"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"]}
package/dist/index.d.mts CHANGED
@@ -71,6 +71,7 @@ export { pick } from './object/pick.mjs';
71
71
  export { pickBy } from './object/pickBy.mjs';
72
72
  export { invert } from './object/invert.mjs';
73
73
  export { clone } from './object/clone.mjs';
74
+ export { set } from './object/set.mjs';
74
75
  export { isEqual } from './predicate/isEqual.mjs';
75
76
  export { isNil } from './predicate/isNil.mjs';
76
77
  export { isNotNil } from './predicate/isNotNil.mjs';
package/dist/index.d.ts CHANGED
@@ -71,6 +71,7 @@ export { pick } from './object/pick.js';
71
71
  export { pickBy } from './object/pickBy.js';
72
72
  export { invert } from './object/invert.js';
73
73
  export { clone } from './object/clone.js';
74
+ export { set } from './object/set.js';
74
75
  export { isEqual } from './predicate/isEqual.js';
75
76
  export { isNil } from './predicate/isNil.js';
76
77
  export { isNotNil } from './predicate/isNotNil.js';
package/dist/index.js CHANGED
@@ -92,6 +92,7 @@ __export(src_exports, {
92
92
  round: () => round,
93
93
  sample: () => sample,
94
94
  sampleSize: () => sampleSize,
95
+ set: () => set,
95
96
  shuffle: () => shuffle,
96
97
  snakeCase: () => snakeCase,
97
98
  startCase: () => startCase,
@@ -881,6 +882,27 @@ function isPrimitive(value) {
881
882
  return value == null || typeof value !== "object" && typeof value !== "function";
882
883
  }
883
884
 
885
+ // src/object/set.ts
886
+ function set(obj, path, value) {
887
+ if (obj instanceof Map || obj instanceof Set) {
888
+ throw new TypeError("Set or Map is not supported");
889
+ }
890
+ const keys = Array.isArray(path) ? path : String(path).replace(/\[|\]/g, (match) => {
891
+ return match === "[" ? "." : "";
892
+ }).split(".");
893
+ let pointer = obj;
894
+ for (let i = 0; i < keys.length - 1; i++) {
895
+ const key = keys[i];
896
+ const nextKey = keys[i + 1];
897
+ if (pointer[key] == null || typeof pointer[key] !== "object") {
898
+ pointer[key] = /^\d+$/.test(nextKey) ? [] : {};
899
+ }
900
+ pointer = pointer[key];
901
+ }
902
+ pointer[keys[keys.length - 1]] = value;
903
+ return obj;
904
+ }
905
+
884
906
  // src/predicate/isEqual.ts
885
907
  function isEqual(a, b) {
886
908
  if (Object.is(a, b)) {
@@ -1068,6 +1090,7 @@ function startCase(str) {
1068
1090
  round,
1069
1091
  sample,
1070
1092
  sampleSize,
1093
+ set,
1071
1094
  shuffle,
1072
1095
  snakeCase,
1073
1096
  startCase,