-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathutils.js
More file actions
28 lines (23 loc) · 707 Bytes
/
Copy pathutils.js
File metadata and controls
28 lines (23 loc) · 707 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
28
const traverse = require('traverse')
function hasProperty(obj, prop) {
return obj ? Object.prototype.hasOwnProperty.call(obj, prop) : false
}
function isNumber(value) {
return typeof value === 'number' && !isNaN(value);
}
function isBoolean(value) {
return typeof value === 'boolean' && !isNaN(value);
}
function willUpdate(data) {
var device = this
var changed = false
traverse(data).map(function (x) {
if (this.isLeaf) {
let path = this.path.join(".")
let currVal = eval('device.state.'+path)
if (currVal != x) {changed = true}
}
})
return changed
}
module.exports = { hasProperty, isNumber, willUpdate, isBoolean };