-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (23 loc) · 749 Bytes
/
index.js
File metadata and controls
27 lines (23 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = {
getKeys: function(obj, root, keys) {
if(typeof obj !== 'object') throw new Error('Item to check must be an object.')
for(let prop in obj) {
let curr = root !== null ? root+'.'+prop : prop
if(typeof obj[prop] === 'object') {
this.getKeys(obj[prop], curr, keys)
}
keys.push(curr)
}
},
hasRequiredProperties: function(obj, keys) {
if(typeof obj !== 'object') throw new Error('Item to check must be an object.')
let objKeys = []
this.getKeys(obj, null, objKeys)
let hasKeys = true
for(let i=0, l=keys.length; i<l; i++) {
let key = keys[i]
hasKeys = hasKeys && objKeys.indexOf(key) !== -1
}
return hasKeys;
}
};