es-toolkit 1.37.2-dev.1271 → 1.37.2-dev.1273

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.
@@ -176,6 +176,7 @@ export { property } from './object/property.mjs';
176
176
  export { propertyOf } from './object/propertyOf.mjs';
177
177
  export { result } from './object/result.mjs';
178
178
  export { set } from './object/set.mjs';
179
+ export { setWith } from './object/setWith.mjs';
179
180
  export { toDefaulted } from './object/toDefaulted.mjs';
180
181
  export { toPairs } from './object/toPairs.mjs';
181
182
  export { toPairsIn } from './object/toPairsIn.mjs';
@@ -176,6 +176,7 @@ export { property } from './object/property.js';
176
176
  export { propertyOf } from './object/propertyOf.js';
177
177
  export { result } from './object/result.js';
178
178
  export { set } from './object/set.js';
179
+ export { setWith } from './object/setWith.js';
179
180
  export { toDefaulted } from './object/toDefaulted.js';
180
181
  export { toPairs } from './object/toPairs.js';
181
182
  export { toPairsIn } from './object/toPairsIn.js';
@@ -176,6 +176,7 @@ export { property } from './object/property.mjs';
176
176
  export { propertyOf } from './object/propertyOf.mjs';
177
177
  export { result } from './object/result.mjs';
178
178
  export { set } from './object/set.mjs';
179
+ export { setWith } from './object/setWith.mjs';
179
180
  export { toDefaulted } from './object/toDefaulted.mjs';
180
181
  export { toPairs } from './object/toPairs.mjs';
181
182
  export { toPairsIn } from './object/toPairsIn.mjs';
@@ -176,6 +176,7 @@ export { property } from './object/property.mjs';
176
176
  export { propertyOf } from './object/propertyOf.mjs';
177
177
  export { result } from './object/result.mjs';
178
178
  export { set } from './object/set.mjs';
179
+ export { setWith } from './object/setWith.mjs';
179
180
  export { toDefaulted } from './object/toDefaulted.mjs';
180
181
  export { toPairs } from './object/toPairs.mjs';
181
182
  export { toPairsIn } from './object/toPairsIn.mjs';
@@ -176,6 +176,7 @@ export { property } from './object/property.js';
176
176
  export { propertyOf } from './object/propertyOf.js';
177
177
  export { result } from './object/result.js';
178
178
  export { set } from './object/set.js';
179
+ export { setWith } from './object/setWith.js';
179
180
  export { toDefaulted } from './object/toDefaulted.js';
180
181
  export { toPairs } from './object/toPairs.js';
181
182
  export { toPairsIn } from './object/toPairsIn.js';
@@ -3689,6 +3689,17 @@ function result(object, path, defaultValue) {
3689
3689
  return object;
3690
3690
  }
3691
3691
 
3692
+ function setWith(obj, path, value, customizer) {
3693
+ let customizerFn;
3694
+ if (typeof customizer === 'function') {
3695
+ customizerFn = customizer;
3696
+ }
3697
+ else {
3698
+ customizerFn = () => undefined;
3699
+ }
3700
+ return updateWith(obj, path, () => value, customizerFn);
3701
+ }
3702
+
3692
3703
  function toDefaulted(object, ...sources) {
3693
3704
  const cloned = cloneDeep(object);
3694
3705
  return defaults(cloned, ...sources);
@@ -4643,6 +4654,7 @@ const compat = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4643
4654
  sample,
4644
4655
  sampleSize,
4645
4656
  set,
4657
+ setWith,
4646
4658
  shuffle,
4647
4659
  size,
4648
4660
  slice,
@@ -4944,6 +4956,7 @@ exports.round = round;
4944
4956
  exports.sample = sample;
4945
4957
  exports.sampleSize = sampleSize;
4946
4958
  exports.set = set;
4959
+ exports.setWith = setWith;
4947
4960
  exports.shuffle = shuffle;
4948
4961
  exports.size = size;
4949
4962
  exports.slice = slice;
@@ -176,6 +176,7 @@ export { property } from './object/property.mjs';
176
176
  export { propertyOf } from './object/propertyOf.mjs';
177
177
  export { result } from './object/result.mjs';
178
178
  export { set } from './object/set.mjs';
179
+ export { setWith } from './object/setWith.mjs';
179
180
  export { toDefaulted } from './object/toDefaulted.mjs';
180
181
  export { toPairs } from './object/toPairs.mjs';
181
182
  export { toPairsIn } from './object/toPairsIn.mjs';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Sets the value at the specified path of the given object using a customizer function.
3
+ * If any part of the path does not exist, it will be created based on the customizer's result.
4
+ *
5
+ * The customizer is invoked to produce the objects of the path. If the customizer returns
6
+ * a value, that value is used for the current path segment. If the customizer returns
7
+ * `undefined`, the method will create an appropriate object based on the path - an array
8
+ * if the next path segment is a valid array index, or an object otherwise.
9
+ *
10
+ * @template T - The type of the object.
11
+ * @param {T} obj - The object to modify.
12
+ * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to set.
13
+ * @param {unknown} value - The value to set.
14
+ * @param {(value: unknown) => unknown} [customizer] - The function to customize assigned values.
15
+ * @returns {T} - The modified object.
16
+ *
17
+ * @example
18
+ * // Set a value with a customizer that creates arrays for numeric path segments
19
+ * const object = {};
20
+ * setWith(object, '[0][1]', 'a', (value) => Array.isArray(value) ? value : []);
21
+ * // => { '0': ['a'] }
22
+ */
23
+ declare function setWith<T extends object | null | undefined>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown, customizer?: (value: unknown) => unknown): T;
24
+
25
+ export { setWith };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Sets the value at the specified path of the given object using a customizer function.
3
+ * If any part of the path does not exist, it will be created based on the customizer's result.
4
+ *
5
+ * The customizer is invoked to produce the objects of the path. If the customizer returns
6
+ * a value, that value is used for the current path segment. If the customizer returns
7
+ * `undefined`, the method will create an appropriate object based on the path - an array
8
+ * if the next path segment is a valid array index, or an object otherwise.
9
+ *
10
+ * @template T - The type of the object.
11
+ * @param {T} obj - The object to modify.
12
+ * @param {PropertyKey | readonly PropertyKey[]} path - The path of the property to set.
13
+ * @param {unknown} value - The value to set.
14
+ * @param {(value: unknown) => unknown} [customizer] - The function to customize assigned values.
15
+ * @returns {T} - The modified object.
16
+ *
17
+ * @example
18
+ * // Set a value with a customizer that creates arrays for numeric path segments
19
+ * const object = {};
20
+ * setWith(object, '[0][1]', 'a', (value) => Array.isArray(value) ? value : []);
21
+ * // => { '0': ['a'] }
22
+ */
23
+ declare function setWith<T extends object | null | undefined>(obj: T, path: PropertyKey | readonly PropertyKey[], value: unknown, customizer?: (value: unknown) => unknown): T;
24
+
25
+ export { setWith };
@@ -0,0 +1,14 @@
1
+ import { updateWith } from './updateWith.mjs';
2
+
3
+ function setWith(obj, path, value, customizer) {
4
+ let customizerFn;
5
+ if (typeof customizer === 'function') {
6
+ customizerFn = customizer;
7
+ }
8
+ else {
9
+ customizerFn = () => undefined;
10
+ }
11
+ return updateWith(obj, path, () => value, customizerFn);
12
+ }
13
+
14
+ export { setWith };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.37.2-dev.1271+04776a4b",
4
+ "version": "1.37.2-dev.1273+cdc77fe5",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {