FluentFlow
FluentFlow is a filter language with a simple API which lets you define 'followed by'-relations in a flow of JavaScript objects. You can either use FluentFlow from the command line or as a JavaScript library.
Library
Installation
$ npm install --save fluentflow
Usage
const ff = ;const $ = ffRuleBuilderconst _ = ; /** * Log all numbers greater than 9000. */const ffm = ff; _;
Sandbox (Matchbox)
FluentFlow supports evaluating string rules in an isolated environment:
const _ = ;const ffm = ;_;
new Matchbox()
will raise an exception if the chain contains syntax-errors.ffm()
will run the chain inside a vm2-instance.- runtime exceptions will be reported via the
ffm()
callback:ffm(obj, (err) => { console.log(err) } );
Command Line
Installation
$ sudo npm install -g fluentflow
Usage
Usage: fluentflow.js [OPTIONS] rulesFile
rulesFile : path to the rules file
OPTIONS:
-j JSONPath : JSONPath expression
-t : test if rules are valid
-h : print this help
Getting started
Configure rules.js:
/** * Check if somebody forked this repository after submitting an issue. * Reverse order because the github api displays events in this order. */ ;
Run FluentFlow:
$ curl -s https://api.github.com/repos/Enteee/FluentFlow/events | fluentflow rules.js -j '*'
Note: -j '*'
splits an array into objects.
Testing
$ npm test
API
ffm
Matching core. Built using the JavaScript API using a Matcher or from a String in a Matchbox.
Parameters
obj
Object next Object to matchcb
errorFirstCallback? callback after matching finishes
Matcher
Generates the matcher (ffm) for the given Rule(s).
Parameters
rule
...Rule Rule(s) to match against.
Examples
const _ = ;const ff = ;const $ = ffRuleBuilder;const ffm = ff;// match some objects_; // prints [42, 9000]
Returns ffm a new matcher
Matchbox
Generates the isolated matcher (ffm) for the given Rule(s).
Parameters
Examples
const _ = ;const ffm = ;// match some objects_; // prints [42, 9000]
Callback Types
checkerCallback
Checks if an Object matches.
Type: Function
Parameters
o
Object the object to checkp
Object the previous objectc
Object the matching contextpc
Object the matching context from the previous statematch
match match callback, true if matches false otherwiseforget
forget forget callback, forget all states including objects passed as arguments
thenCallback
Called each time a sequence of Objects matches a Rule in a ffm
Type: Function
Parameters
objs
Array the matched objectsnext
next end of callback. Continue matching next objectforget
forget forget objects.
errorFirstCallback
Standard node.js callback type.
Type: Function
Parameters
Helper Classes
Rule
Parameters
setThen
Parameters
then
thenCallback match callback
RuleBuilder
Builds Rule.
Parameters
checker
checkerCallback first checker
Examples
const rule = ; // prints [42, 9000]
Returns RuleBuilder continue
followedBy
Add a new checker.
Parameters
checker
checkerCallback next checker
Returns RuleBuilder continue
then
Finishes and builds the chain.
Parameters
then
thenCallback? run if rule matches
Returns Rule finish
next
Signal the end of a thenCallback.
forget
Signal the intent to forget an object. Must be called before next.
Parameters
obj
...Object the object(s) to forget
match
Signal the result of a matching operation.
Parameters
matched
Boolean? true if matched, false otherwise. Default if omitted: false.