deep-grep
Too many haystacks, not enough needles — or, "when you have a grep, everything looks like a list."
var needles = dg
usage
For grep on simple, flat (non-nested) lists:
dg.in()
dg.in( list, 'value' )
- returnstrue
orfalse
depending upon whetherlist
containsvalue
.
dg.all_in()
dg.all_in( list_a, list_b )
- returns a list of all values inlist_a
that exist inlist_b
.
dg.unique()
dg.unique( list )
- returns all unique values oflist
. Note: flattens.
dg.flatten( )
dg.flatten( nested_list )
- returns a list of all the lists contained innested_list
, concatenated into a single scope.
For doing greppy things on nested lists:
var haystack = 'zebra' 'lion' 'tiger' 'unicorn' 'emperor penguin' 'leprechaun' 'cockerel'; var needles = dg;
For more complex data, options are available to you:
var needles = dg
deprecated methods
dg.sync()
dg.sync( list, expression )
- evaluateslist
, returning a new list of every element that matchesexpression.test
(likeRegExp
).dg.sync( list, func )
- same as above, only executesfunc
for every element of list, returning a new list.
dg.async()
dg.async( list, expression )
- same as withsync()
, above, only returns a promise to the list of matches.dg.async( list, func, callback )
- same assync()
, above, except the callback is called with a promise to the list of matches.