@ditojs/utils 1.16.0 → 1.17.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.16.0",
3
+ "version": "1.17.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",
@@ -35,5 +35,5 @@
35
35
  "typescript": "^4.9.3"
36
36
  },
37
37
  "types": "types",
38
- "gitHead": "e7e7ddb88965dbffc29c0968054015a647844803"
38
+ "gitHead": "45d692909e0ed637fdabe4568f971aeed7e84388"
39
39
  }
@@ -7,12 +7,16 @@ export function clone(arg, options) {
7
7
  const {
8
8
  shallow = false,
9
9
  enumerable = true,
10
+ descriptors = false,
11
+ transferables = null,
10
12
  processValue = null
11
13
  } = isFunction(options)
12
14
  ? { processValue: options } // TODO: `callback` deprecated in December 2022.
13
15
  : options || {}
14
16
 
15
- const handleValue = value => shallow ? value : clone(value, options)
17
+ const handleValue = value => shallow || transferables?.includes(value)
18
+ ? value
19
+ : clone(value, options)
16
20
 
17
21
  let copy = arg
18
22
  if (isDate(arg)) {
@@ -37,11 +41,15 @@ export function clone(arg, options) {
37
41
  copy = Object.create(Object.getPrototypeOf(arg))
38
42
  const keys = enumerable ? Object.keys(arg) : Reflect.ownKeys(arg)
39
43
  for (const key of keys) {
40
- const desc = Reflect.getOwnPropertyDescriptor(arg, key)
41
- if (desc.value != null) {
42
- desc.value = handleValue(desc.value)
44
+ if (descriptors || !enumerable) {
45
+ const desc = Reflect.getOwnPropertyDescriptor(arg, key)
46
+ if (desc.value != null) {
47
+ desc.value = handleValue(desc.value)
48
+ }
49
+ Reflect.defineProperty(copy, key, desc)
50
+ } else {
51
+ copy[key] = handleValue(arg[key])
43
52
  }
44
- Reflect.defineProperty(copy, key, desc)
45
53
  }
46
54
  }
47
55
  }