theprogrammablemind_4wp 9.3.0-beta.50 → 9.3.0-beta.52

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/project.js +22 -2
package/package.json CHANGED
@@ -69,6 +69,6 @@
69
69
  "sort-json": "^2.0.0",
70
70
  "uuid": "^8.3.2"
71
71
  },
72
- "version": "9.3.0-beta.50",
72
+ "version": "9.3.0-beta.52",
73
73
  "license": "UNLICENSED"
74
74
  }
package/src/project.js CHANGED
@@ -1,3 +1,19 @@
1
+ function isObject(value) {
2
+ return typeof value === "object" && value !== null;
3
+ }
4
+
5
+ const merge = (value1, value2) => {
6
+ if (Array.isArray(value1) && Array.isArray(value2)) {
7
+ const merged = []
8
+ for (let i = 0; i < value1.length; ++i) {
9
+ merged.push(merge(value1[i], value2[i]))
10
+ }
11
+ return merged
12
+ }
13
+ if (isObject(value1) && isObject(value2)) {
14
+ return Object.assign({}, value1, value2)
15
+ }
16
+ }
1
17
 
2
18
  const project = (object, filter) => {
3
19
  if (!object) {
@@ -12,7 +28,11 @@ const project = (object, filter) => {
12
28
  if (value === null || value === undefined) {
13
29
  return
14
30
  }
15
- projection[property] = value
31
+ if (projection[property]) {
32
+ projection[property] = merge(value, projection[property])
33
+ } else {
34
+ projection[property] = value
35
+ }
16
36
  }
17
37
  if (Array.isArray(filter)) {
18
38
  if (Array.isArray(object)) {
@@ -81,4 +101,4 @@ const project = (object, filter) => {
81
101
  return projection
82
102
  }
83
103
 
84
- module.exports = { project }
104
+ module.exports = { project, merge }