npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fluentflow

v0.4.2

Published

FluentFlow is a filter language which lets you easily define 'followed by'-relations in a flow of JavaScript objects

Downloads

6

Readme

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.

npm version Travis Coverage Status js-semistandard-style #FluentFlow

Library

Installation

$ npm install --save fluentflow 

Usage

const ff = require('fluentflow');
const $ = ff.RuleBuilder
const _ = require('lodash');

/**
 * Log all numbers greater than 9000.
 */
const ffm = ff.Matcher(
  $(
    // Start matching after 9000
    (o, p, c, pc, match) => match(o === 9000)
  ).followedBy(
    // Is the next object (o) greater than the previous (p)?
    (o, p, c, pc, match) => match(o > p.get(0))
  ).then(
    (objs, next) => next(console.log(objs))
  )
);

_.range(9002).forEach((obj) => ffm(obj));

Sandbox (Matchbox)

FluentFlow supports evaluating string rules in an isolated environment:

const _ = require('lodash');
const ffm = require('fluentflow').Matchbox(`
[
  $(
    // Start matching after 9000
    (o, p, c, pc, match) => match(o === 9000)
  ).followedBy(
    // Is the next object (o) greater than the previous (p)?
    (o, p, c, pc, match) => match(o > p.get(0))
  ).then(
    (objs, next) => next(console.log(objs))
  )
]`);
_.range(9002).forEach((obj) => ffm(obj));
  • 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.
   */
  $(
    (o, p, c, pc, match) => {
      match(o.get('type') === 'ForkEvent');
    }
  ).followedBy(
    (o, p, c, pc, match) => match(
        o.get('type') === 'IssuesEvent' &&
        o.get('actor').get('login') === p.get(0).get('actor').get('login')
    )
  ).then((objs, next) => next(
    console.log('User: ' +
      objs.get(1).get('actor').get('login') +
      ' forked after writing issue: ' +
      objs.get(0).get('id')
    )
  ))
];

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

Documentation on github-pages

ffm

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

Parameters

Matcher

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

Parameters

  • rule ...Rule Rule(s) to match against.

Examples

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]

Returns ffm a new matcher

Matchbox

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

Parameters

Examples

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]

Returns ffm an isolated ffm

Callback Types

checkerCallback

Checks if an Object matches.

Type: Function

Parameters
  • o Object the object to check
  • p Object the previous object
  • c Object the matching context
  • pc Object the matching context from the previous state
  • match match match callback, true if matches false otherwise
  • forget 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 objects
  • next next end of callback. Continue matching next object
  • forget forget forget objects.

errorFirstCallback

Standard node.js callback type.

Type: Function

Parameters

Helper Classes

Rule

Parameters
setThen
Parameters

RuleBuilder

Builds Rule.

Parameters
Examples
const rule = require('fluentflow').RuleBuilder(
 (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)
 )
); // prints [42, 9000]

Returns RuleBuilder continue

followedBy

Add a new checker.

Parameters

Returns RuleBuilder continue

then

Finishes and builds the chain.

Parameters

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.