theprogrammablemind_4wp 7.5.8-beta.67 → 7.5.8-beta.68

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/package.json +2 -1
  2. package/src/project.js +22 -0
package/package.json CHANGED
@@ -46,6 +46,7 @@
46
46
  "src/digraph.js",
47
47
  "src/digraph_internal.js",
48
48
  "src/generators.js",
49
+ "src/project.js",
49
50
  "src/semantics.js"
50
51
  ],
51
52
  "author": "dev@thinktelligence.com",
@@ -63,6 +64,6 @@
63
64
  "json-stable-stringify": "^1.0.1",
64
65
  "node-fetch": "^2.6.1"
65
66
  },
66
- "version": "7.5.8-beta.67",
67
+ "version": "7.5.8-beta.68",
67
68
  "license": "ISC"
68
69
  }
package/src/project.js ADDED
@@ -0,0 +1,22 @@
1
+
2
+ const project = (object, filter) => {
3
+ let projection = {}
4
+ if (Array.isArray(filter)) {
5
+ if (Array.isArray(object)) {
6
+ return object.map( element => project(element, filter) )
7
+ } else {
8
+ for (const property of filter) {
9
+ projection[property] = object[property]
10
+ }
11
+ }
12
+ } else if (typeof filter == 'object') {
13
+ for (const property of Object.keys(filter)) {
14
+ projection[property] = project(object[property], filter[property])
15
+ }
16
+ }
17
+ return projection
18
+ }
19
+
20
+ module.exports = { project }
21
+
22
+