glob-tree.js
Tree with glob iterator. Glob expressions can be used to iterate over matching sub trees. The tree can be modified while iterating over the nodes.
Install with npm
npm install glob-tree
Browser compatibility
To use this module in a browser, download the npm package and then use Browserify to create a standalone version.
Usage
var Node = Node; var n = 'root';n;n;n; var c i = n;while c = inext !== undefined console;
Match expressions
Assuming we have this tree:
var n = 'root';n;n;n;n;n;
You can find nodes with n.iterator(match)
using wildcards:
match | result |
---|---|
'**' |
1, 2, 3, 4 |
'*' |
5 |
'x.**' |
3, 4 |
'x.*' |
3 |
'*.b' |
1, 3 |
'**.c' |
2, 4 |
'x.*.c' |
4 |
Matchers
Node names may contain wildcards as well. Assuming we have this tree:
var n = 'root';n;n;n;n;n;n;
Querying for a node will also include the matchers:
match | result |
---|---|
'a.b' |
1, 2, 5 |
'a.b.c' |
1, 2, 3 |
'a.b.c.d' |
1, 2, 4, 6 |
Node API
Node is derived from live-tree Node and overrides the iterator function:
iterator(match[, options])
: Returns anIterator
for the given match expression with these options:matchers
: whether to include matchers, defaults totrue
onlyMatchers
: whether to only include matchers, defaults tofalse
Iterator is derived from min-iterator.
License
MIT