es-toolkit 1.40.0-dev.1639 → 1.40.0-dev.1641

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.
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const isUnsafeProperty = require('../_internal/isUnsafeProperty.js');
6
- const isObjectLike = require('../compat/predicate/isObjectLike.js');
6
+ const isPlainObject = require('../predicate/isPlainObject.js');
7
7
 
8
8
  function mergeWith(target, source, merge) {
9
9
  const sourceKeys = Object.keys(source);
@@ -19,10 +19,20 @@ function mergeWith(target, source, merge) {
19
19
  target[key] = merged;
20
20
  }
21
21
  else if (Array.isArray(sourceValue)) {
22
- target[key] = mergeWith(targetValue ?? [], sourceValue, merge);
22
+ if (Array.isArray(targetValue)) {
23
+ target[key] = mergeWith(targetValue ?? [], sourceValue, merge);
24
+ }
25
+ else {
26
+ target[key] = mergeWith([], sourceValue, merge);
27
+ }
23
28
  }
24
- else if (isObjectLike.isObjectLike(targetValue) && isObjectLike.isObjectLike(sourceValue)) {
25
- target[key] = mergeWith(targetValue ?? {}, sourceValue, merge);
29
+ else if (isPlainObject.isPlainObject(sourceValue)) {
30
+ if (isPlainObject.isPlainObject(targetValue)) {
31
+ target[key] = mergeWith(targetValue, sourceValue, merge);
32
+ }
33
+ else {
34
+ target[key] = mergeWith({}, sourceValue, merge);
35
+ }
26
36
  }
27
37
  else if (targetValue === undefined || sourceValue !== undefined) {
28
38
  target[key] = sourceValue;
@@ -1,5 +1,5 @@
1
1
  import { isUnsafeProperty } from '../_internal/isUnsafeProperty.mjs';
2
- import { isObjectLike } from '../compat/predicate/isObjectLike.mjs';
2
+ import { isPlainObject } from '../predicate/isPlainObject.mjs';
3
3
 
4
4
  function mergeWith(target, source, merge) {
5
5
  const sourceKeys = Object.keys(source);
@@ -15,10 +15,20 @@ function mergeWith(target, source, merge) {
15
15
  target[key] = merged;
16
16
  }
17
17
  else if (Array.isArray(sourceValue)) {
18
- target[key] = mergeWith(targetValue ?? [], sourceValue, merge);
18
+ if (Array.isArray(targetValue)) {
19
+ target[key] = mergeWith(targetValue ?? [], sourceValue, merge);
20
+ }
21
+ else {
22
+ target[key] = mergeWith([], sourceValue, merge);
23
+ }
19
24
  }
20
- else if (isObjectLike(targetValue) && isObjectLike(sourceValue)) {
21
- target[key] = mergeWith(targetValue ?? {}, sourceValue, merge);
25
+ else if (isPlainObject(sourceValue)) {
26
+ if (isPlainObject(targetValue)) {
27
+ target[key] = mergeWith(targetValue, sourceValue, merge);
28
+ }
29
+ else {
30
+ target[key] = mergeWith({}, sourceValue, merge);
31
+ }
22
32
  }
23
33
  else if (targetValue === undefined || sourceValue !== undefined) {
24
34
  target[key] = sourceValue;
@@ -2,11 +2,29 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const cloneDeep = require('./cloneDeep.js');
6
- const merge = require('./merge.js');
5
+ const clone = require('./clone.js');
6
+ const mergeWith = require('./mergeWith.js');
7
+ const isPlainObject = require('../predicate/isPlainObject.js');
7
8
 
8
9
  function toMerged(target, source) {
9
- return merge.merge(cloneDeep.cloneDeep(target), source);
10
+ return mergeWith.mergeWith(clone.clone(target), source, function mergeRecursively(targetValue, sourceValue) {
11
+ if (Array.isArray(sourceValue)) {
12
+ if (Array.isArray(targetValue)) {
13
+ return mergeWith.mergeWith(clone.clone(targetValue), sourceValue, mergeRecursively);
14
+ }
15
+ else {
16
+ return mergeWith.mergeWith([], sourceValue, mergeRecursively);
17
+ }
18
+ }
19
+ else if (isPlainObject.isPlainObject(sourceValue)) {
20
+ if (isPlainObject.isPlainObject(targetValue)) {
21
+ return mergeWith.mergeWith(clone.clone(targetValue), sourceValue, mergeRecursively);
22
+ }
23
+ else {
24
+ return mergeWith.mergeWith({}, sourceValue, mergeRecursively);
25
+ }
26
+ }
27
+ });
10
28
  }
11
29
 
12
30
  exports.toMerged = toMerged;
@@ -1,8 +1,26 @@
1
- import { cloneDeep } from './cloneDeep.mjs';
2
- import { merge } from './merge.mjs';
1
+ import { clone } from './clone.mjs';
2
+ import { mergeWith } from './mergeWith.mjs';
3
+ import { isPlainObject } from '../predicate/isPlainObject.mjs';
3
4
 
4
5
  function toMerged(target, source) {
5
- return merge(cloneDeep(target), source);
6
+ return mergeWith(clone(target), source, function mergeRecursively(targetValue, sourceValue) {
7
+ if (Array.isArray(sourceValue)) {
8
+ if (Array.isArray(targetValue)) {
9
+ return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
10
+ }
11
+ else {
12
+ return mergeWith([], sourceValue, mergeRecursively);
13
+ }
14
+ }
15
+ else if (isPlainObject(sourceValue)) {
16
+ if (isPlainObject(targetValue)) {
17
+ return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
18
+ }
19
+ else {
20
+ return mergeWith({}, sourceValue, mergeRecursively);
21
+ }
22
+ }
23
+ });
6
24
  }
7
25
 
8
26
  export { toMerged };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
- "version": "1.40.0-dev.1639+ede4e39a",
3
+ "version": "1.40.0-dev.1641+3f1c68e8",
4
4
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
5
5
  "homepage": "https://es-toolkit.dev",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",