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

dflow

v0.43.1

Published

is a minimal Dataflow programming engine

Downloads

245

Readme

Dflow

is a minimal Dataflow programming engine

How it works

A node represents a block of code: it can have inputs and outputs.

An edge connects an input to an output.

A graph represents a program. It can contain nodes and edges. Nodes are executed, sorted by their connections.

Features

  • Implemented in TypeScript, available both on Node and Deno.
  • Expressive and simple API.
  • A graph can be saved as a JSON file. It can be then loaded and executed.
  • It is easy to create nodes: just extend DflowNode class, define its inputs and outputs and the run() function.
  • Minimal internal type system: it is possible to connect an output of type T to an input of type U, if and only if U includes T.
  • It is possible to define functions represented by nodes and edges.

NOTA BENE: it is supposed that you implement your own nodes, for example node addition could be implemented using bigint or some floating point library, according to your needs. However an example nodes catalog with basic JavaScript features can be imported from dflow/nodes.

Installation

Node

With npm do

npm install dflow

Deno

Dflow lives in Deno land!

Module is published here: https://deno.land/x/dflow

Dflow engine is implemented in a single dflow.ts file, you can use an import like

import { Dflow } from "https://deno.land/x/[email protected]/dflow.ts";

Using an import map

Create an import_map.json file like this.

{
  "imports": {
    "dflow/": "https://deno.land/x/dflow/"
  }
}

Then you can import for example the following.

import { Dflow } from "dflow/dflow.ts";
import { nodesCatalog } from "dflow/examples/nodes/index.ts";

const dflow = new Dflow({ nodesCatalog });

// ... load or create a graph

await dflow.run()

With deno you can then launch your script like this

deno run --importmap=import_map.json path/to/my/script.ts

You may want to point to a specific version, for instance version 0.42, change your import map accordingly

{
  "imports": {
-    "dflow": "https://deno.land/x/dflow/dflow.ts"
+    "dflow": "https://deno.land/x/[email protected]/dflow.ts"
  }
}

Usage

This is a graph that will compute sin(π / 2) = 1 and print the result.

   ----------------
  | number = π / 2 |
   ----------------
   |
   |
   ---------
  | mathSin |
   ---------
    \
     \
     ------------
    | consoleLog |
     ------------

You can run the following code with any of the following:

  • launching command deno run https://raw.githubusercontent.com/fibo/dflow/main/examples/usage.js
  • cloning this repo and launching npm run example:usage.

You should see a number 1 printed on output.

import { Dflow } from "dflow";
import { nodesCatalog } from "dflow/nodes";

function rungraph() {
  // use builtin nodes
  const dflow = new Dflow({ nodesCatalog });
  const catalog = dflow.nodesCatalog;

  // create nodes
  const numNode = dflow.newNode({
    kind: catalog.data.kind,
    // set numNode output to π / 2
    outputs: [{ data: Math.PI / 2 }],
  });
  const sinNode = dflow.newNode({
    kind: catalog.mathSin.kind,
  });
  const consoleLogNode = dflow.newNode({
    kind: catalog.consoleLog.kind,
  });

  // connect numNode to sinNode and sinNode to consoleLog
  dflow.connect(numNode).to(sinNode);
  dflow.connect(sinNode).to(consoleLogNode);

  // run graph
  dflow.run();
}

rungraph();

A graph can be executed asynchronously with await dflow.run(): see custom nodes example.

Available examples are listed here.

License

MIT