-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathhelpers.js
47 lines (42 loc) · 1.12 KB
/
helpers.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
willChangeWithParent = function(object, key) {
if (!_.isObject(object)) {
return;
}
var willChange = false;
_.each(_.keys(object), function(modifyingKey) {
if (key && key.indexOf(modifyingKey) === 0) {
willChange = true;
}
});
return willChange;
};
objectHasKey = function(object, key) {
var dotNotation = {};
(function recurse(obj, current) {
for(var key in obj) {
var value = obj[key];
var newKey = (current ? current + "." + key : key); // joined key with dot
if(value && typeof value === "object") {
recurse(value, newKey); // it's a nested object, so do it again
} else {
dotNotation[newKey] = value; // it's not an object, so set the property
}
}
})(object);
var keys = _.keys(dotNotation);
var newKeys = [];
_.each(keys, function(_key) {
var parts = _key.split('.');
var added = [];
_.each(parts, function(part) {
if (!isNaN(part)) {
part = '$';
added.push(part);
} else {
added.push(part);
newKeys.push(added.join('.'));
}
});
});
return _.contains(newKeys, key);
};