@ditojs/utils 1.5.5 → 1.9.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/utils",
3
- "version": "1.5.5",
3
+ "version": "1.9.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js Utility Functions – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/utils",
@@ -27,5 +27,5 @@
27
27
  "dependencies": {
28
28
  "punycode": "^2.1.1"
29
29
  },
30
- "gitHead": "157b519f3f3552fb25b67adf7e0fd402485ac4c9"
30
+ "gitHead": "034973580c50fc7d8bb4ad07ec4c91782eb329a5"
31
31
  }
@@ -3,7 +3,7 @@ import { clone } from './clone.js'
3
3
 
4
4
  export function merge(target, ...sources) {
5
5
  const _merge = (target, source, cloneTarget) => {
6
- if (target && source && (
6
+ if (target && source && target !== source && (
7
7
  isArray(target) && isArray(source) ||
8
8
  isPlainObject(target) && isPlainObject(source)
9
9
  )) {
@@ -11,10 +11,7 @@ export function merge(target, ...sources) {
11
11
  ? clone(target)
12
12
  : target
13
13
  for (const key of Object.keys(source)) {
14
- const value = _merge(target[key], source[key], true)
15
- if (value !== undefined || !(key in result)) {
16
- result[key] = value
17
- }
14
+ result[key] = _merge(target[key], source[key], true)
18
15
  }
19
16
  return result
20
17
  }
@@ -80,21 +80,20 @@ describe('merge()', () => {
80
80
  expect(actual2.a).toStrictEqual([[4, 5, 3]])
81
81
  })
82
82
 
83
- it('should not overwrite existing values with `undefined` in objects', () => {
83
+ it('should overwrite existing values with `undefined` in objects', () => {
84
84
  const actual = merge({ a: 1 }, { a: undefined, b: undefined })
85
- expect(actual).toStrictEqual({ a: 1, b: undefined })
85
+ expect(actual).toStrictEqual({ a: undefined, b: undefined })
86
86
  })
87
87
 
88
- it('should not overwrite existing values with `undefined` in arrays', () => {
88
+ it('should overwrite existing values with `undefined` in arrays', () => {
89
89
  const array1 = [1]
90
90
  array1[2] = 3
91
91
  const actual1 = merge([4, 5, 6], array1)
92
- const expected1 = [1, 5, 3]
93
- expect(actual1).toStrictEqual(expected1)
92
+ expect(actual1).toStrictEqual([1, 5, 3])
94
93
 
95
94
  const array2 = [1, undefined, 3]
96
95
  const actual2 = merge([4, 5, 6], array2)
97
- expect(actual2).toStrictEqual(expected1)
96
+ expect(actual2).toStrictEqual([1, undefined, 3])
98
97
  })
99
98
 
100
99
  it('should merge regexps', () => {