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

flowlink

v0.9.8

Published

Flow Expression Language

Downloads

54

Readme

FlowLink

Flow Expression Language (FlowLink)

About

FlowLink is a JavaScript library for use in the Browser and Node.js to parse/compile expressions describing data flows. The expressions are based on sequental flows, parallel flows and groups of nodes. FlowLink is primarily intended to be used for configuring a complex data flow. What the particular nodes represent is up to the caller.

Installation

$ npm install flowlink

Usage

$ cat sample.js
const FlowLink = require("..")

const flowlink = new FlowLink({
    trace: (msg) => console.log(msg)
})

class Node {
    constructor (id, opts, args) {
        this.id    = id
        this.opts  = opts
        this.args  = args
        this.piped = []
    }
    pipe (node) {
        this.piped.push(node)
    }
}

const expr = `
    begin(42, id: \`foo\${sample}bar\`) |
    { foo1("foo"), foo2('bar') } |
    { bar1, bar2 } |
    end,
    sidechain
`

try {
    const ast = flowlink.compile(expr)
    const stream = flowlink.execute(ast, {
        resolveVariable (id) {
            if (id === "sample")
                return "SAMPLE"
            throw new Error(`failed to resolve variable "${id}"`)
        },
        createNode (id, opts, args) {
            return new Node(id, opts, args)
        },
        connectNode (node1, node2) {
            node1.pipe(node2)
        }
    })
}
catch (ex) {
    console.log("ERROR", ex.toString())
}

Expression Language

The following BNF-style grammar shows the supported expression language:

expr             ::= parallel
                   | sequential
                   | node
                   | group
parallel         ::= sequential ("," sequential)+
sequential       ::= node ("|" node)+
node             ::= id ("(" (param ("," param)*)? ")")?
param            ::= array | object | variable | template | string | number | value
group            ::= "{" expr "}"
id               ::= /[a-zA-Z_][a-zA-Z0-9_-]*/
variable         ::= id
array            ::= "[" (param ("," param)*)? "]"
object           ::= "{" (id ":" param ("," id ":" param)*)? "}"
template         ::= "`" ("${" variable "}" / ("\\`"|.))* "`"
string           ::= /"(\\"|.)*"/
                   | /'(\\'|.)*'/
number           ::= /[+-]?/ number-value
number-value     ::= "0b" /[01]+/
                   | "0o" /[0-7]+/
                   | "0x" /[0-9a-fA-F]+/
                   | /[0-9]*\.[0-9]+([eE][+-]?[0-9]+)?/
                   | /[0-9]+/
value            ::= "true" | "false" | "null" | "NaN" | "undefined"

Application Programming Interface (API)

The following TypeScript definition shows the supported Application Programming Interface (API):

declare module "flowlink" {
    type FlowLinkCallbacks<T> = {
        resolveVariable(id: string): string,
        createNode<T>(id: string, opts: { [ id: string ]: any }, args: any[]): T,
        connectNode(node1: T, node2: T): void
    }
    class FlowLink<T> {
        constructor(
            options?: {
                cache?: number,
                trace?: (msg: string) => void
            }
        )
        compile(
            expr: string
        ): any
        execute<T>(
            ast: any,
            callbacks: FlowLinkCallbacks<T>
        ): any
        evaluate<T>(
            expr: string,
            callbacks: FlowLinkCallbacks<T>
        ): any
    }
    export = FlowLink
}

Implementation Notice

Although FlowLink is written in ECMAScript 2023, it is transpiled to older environments and this way runs in really all current (as of 2024) JavaScript environments, of course.

Additionally, there are two transpilation results: first, there is a compressed flowlink.browser.js for Browser environments. Second, there is an uncompressed flowlink.node.js for Node.js environments.

The Browser variant flowlink.browser.js has all external dependencies asty, pegjs-otf, pegjs-util, and cache-lru directly embedded. The Node.js variant flowlink.node.js still requires the external dependencies asty, pegjs-otf, pegjs-util, and cache-lru.

License

Copyright © 2024 Dr. Ralf S. Engelschall (http://engelschall.com/)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.