Intro
There is two functions to browse object/json structure orderedly : depthFirst and breadthFirst.
While browsing, it allow you to select properties that match through test function(s).
deep.depthFirst(obj, test, opt)
Returns
- if(!options.first) : return an array of nodes descriptors (empty if no match).
- if(options.first) : a single node descriptor or null if no match.
(for full options descritions see options.)
var a = {
b:{
c:{
d:true
}
},
e:"hello",
f:{
d:true
}
};
var r = deep.depthFirst(a, function(v){
return v.d === true;
});
deep.log(deep.utils.nodes.paths(r));
deep.breadthFirst(root, testFunction, opt)
Returns
- if(!options.first) : return an array of nodes descriptors (empty if no match).
- if(options.first) : a single node descriptor or null if no match.
(for full options descritions see options.)
var a = {
b:{
c:{
d:true
}
},
e:"hello",
f:{
d:true
}
};
var r = deep.breadthFirst(a, function(v){
return v.d === true;
});
deep.log(deep.utils.nodes.paths(r));
options
Remarque Options are the same for both traversal methods.
options.first
Boolean, default false.
If true, stop traversal at first match, and return the matched node (null if no match).
options.inArray
String, optional. The name of the array where do the check.
options.hierarchy
Boolean, default false.
If true, return the 'hierarchy' of matched node. Work only if options.first == false.
options.returnStack
Boolean, default false.
Principally for deepjs internal use. The two traversal methods are non recusrive and could return the current stack that methods use to do the traversal.
The aim is to be able to restart traversal from the same place after stop.
If true, in place of _deep_query_node_(s), return the stack used by derecursified method.
Work only if options.first == true.