ffm

Matching core. Built using the JavaScript API using a Matcher or from a String in a Matchbox.

ffm(obj: Object, cb: errorFirstCallback?)
Parameters
obj (Object) next Object to match
cb (errorFirstCallback?) callback after matching finishes

Matcher

Generates the matcher (ffm) for the given Rule(s).

Matcher(rule: ...Rule): ffm
Parameters
rule (...Rule) Rule(s) to match against.
Returns
ffm: a new matcher
Example
const _ = require('lodash');
const ff = require('fluentflow');
const $ = ff.RuleBuilder;
const ffm = ff.Matcher(
 $(
    (o, p, c, pc, match, f) => match(o == 42)
  ).followedBy(
    (o, p, c, pc, match, f) => match(o == 9000)
  ).then(
    (objs, next) => next(
      console.log(objs)
    )
  )
);
// match some objects
_.range(9001).forEach((obj) => ffm(obj)); // prints [42, 9000]

Matchbox

Generates the isolated matcher (ffm) for the given Rule(s).

Matchbox(rulesRaw: string, vmoptions: Object?): ffm
Parameters
rulesRaw (string) a string of rules
vmoptions (Object?) options to vm2
Returns
ffm: an isolated ffm
Example
const _ = require('lodash');
const ffm = require('fluentflow').Matchbox(`
 [
   $(
     (o, p, c, pc, match, forget) => match(o == 42)
   ).followedBy(
     (o, p, c, pc, match, forget) => match(o == 9000)
   ).then(
     (objs, next) => next(
       console.log(objs)
     )
   )
 ]
`);
// match some objects
_.range(9001).forEach((obj) => ffm(obj)); // prints [42, 9000]

Callback Types

Static Members
checkerCallback(o, p, c, pc, match, forget)
thenCallback(objs, next, forget)
errorFirstCallback(Error, data)

Helper Classes

Static Members
new Rule(check, next)
new RuleBuilder(checker)

next

Signal the end of a thenCallback.

next()

forget

Signal the intent to forget an object. Must be called before next.

forget(obj: ...Object)
Parameters
obj (...Object) the object(s) to forget

match

Signal the result of a matching operation.

match(matched: Boolean?)
Parameters
matched (Boolean?) true if matched, false otherwise. Default if omitted: false.