es-toolkit 1.14.0-dev.407 → 1.14.0-dev.409

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.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Merges the properties of the source object into the target object.
3
+ *
4
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
5
+ * If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged.
6
+ * If a property in the source object is undefined, it will not overwrite a defined property in the target object.
7
+ *
8
+ * @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
9
+ * @param {S} source - The source object whose properties will be merged into the target object.
10
+ * @returns {T & S} The updated target object with properties from the source object merged in.
11
+ *
12
+ * @template T - Type of the target object.
13
+ * @template S - Type of the source object.
14
+ *
15
+ * @example
16
+ * const target = { a: 1, b: { x: 1, y: 2 } };
17
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
18
+ *
19
+ * const result = merge(target, source);
20
+ * console.log(result);
21
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
22
+ *
23
+ * @example
24
+ * const target = { a: [1, 2], b: { x: 1 } };
25
+ * const source = { a: [3], b: { y: 2 } };
26
+ *
27
+ * const result = merge(target, source);
28
+ * console.log(result);
29
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
30
+ *
31
+ * @example
32
+ * const target = { a: null };
33
+ * const source = { a: [1, 2, 3] };
34
+ *
35
+ * const result = merge(target, source);
36
+ * console.log(result);
37
+ * // Output: { a: [1, 2, 3] }
38
+ */
39
+ declare function merge<T, S>(target: T, source: S): T & S;
40
+
41
+ export { merge };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Merges the properties of the source object into the target object.
3
+ *
4
+ * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
5
+ * If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged.
6
+ * If a property in the source object is undefined, it will not overwrite a defined property in the target object.
7
+ *
8
+ * @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
9
+ * @param {S} source - The source object whose properties will be merged into the target object.
10
+ * @returns {T & S} The updated target object with properties from the source object merged in.
11
+ *
12
+ * @template T - Type of the target object.
13
+ * @template S - Type of the source object.
14
+ *
15
+ * @example
16
+ * const target = { a: 1, b: { x: 1, y: 2 } };
17
+ * const source = { b: { y: 3, z: 4 }, c: 5 };
18
+ *
19
+ * const result = merge(target, source);
20
+ * console.log(result);
21
+ * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
22
+ *
23
+ * @example
24
+ * const target = { a: [1, 2], b: { x: 1 } };
25
+ * const source = { a: [3], b: { y: 2 } };
26
+ *
27
+ * const result = merge(target, source);
28
+ * console.log(result);
29
+ * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
30
+ *
31
+ * @example
32
+ * const target = { a: null };
33
+ * const source = { a: [1, 2, 3] };
34
+ *
35
+ * const result = merge(target, source);
36
+ * console.log(result);
37
+ * // Output: { a: [1, 2, 3] }
38
+ */
39
+ declare function merge<T, S>(target: T, source: S): T & S;
40
+
41
+ export { merge };
@@ -0,0 +1,22 @@
1
+ import { isObjectLike } from '../compat/predicate/isObjectLike.mjs';
2
+
3
+ function merge(target, source) {
4
+ const sourceKeys = Object.keys(source);
5
+ for (let i = 0; i < sourceKeys.length; i++) {
6
+ const key = sourceKeys[i];
7
+ const sourceValue = source[key];
8
+ const targetValue = target[key];
9
+ if (Array.isArray(sourceValue)) {
10
+ target[key] = merge(targetValue ?? [], sourceValue);
11
+ }
12
+ else if (isObjectLike(targetValue) && isObjectLike(sourceValue)) {
13
+ target[key] = merge(targetValue ?? {}, sourceValue);
14
+ }
15
+ else if (targetValue === undefined || sourceValue !== undefined) {
16
+ target[key] = sourceValue;
17
+ }
18
+ }
19
+ return target;
20
+ }
21
+
22
+ export { merge };
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const isSymbol = require('../_chunk/isSymbol-CyBIcg.js');
5
+ const isSymbol = require('../_chunk/isSymbol-CxBVKi.js');
6
6
  const isTypedArray = require('../_chunk/isTypedArray-BBEkFl.js');
7
7
 
8
8
  function isBoolean(x) {
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.14.0-dev.407+5d34b166",
4
+ "version": "1.14.0-dev.409+bb94b88e",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {