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

noflo-calc

v0.0.1

Published

Components for the NoFlo flow-based programming environment to evaluate mathematical expressions on JavaScript objects

Downloads

35

Readme

noflo-calc

Mathematical expression evaluation components for NoFlo. These components are essentially NoFlo wrappers around the superb MathJS library. You can ask these components to evaluate arbitrarily complex mathematical expressions.

Components

  1. SimpleExpressionCalculator has an IN in port that accepts text data and an OUT port that sends a JavaScript object with the answer. This might be a simple number or an array of numbers, depending on the expression you give. Read the MathJS documentation for more information.
  2. ObjectVariablesExpressionCalculator is intended to be used for complex calculations using object values in the calculation. You configure this object with a mathematical expression and a list of variables that can be looked up from data messages. When a message arrives on this component's data port, the variables are looked up and substituted into the calculation. You can configure this object to either send on calculation answers or to enrich the data message with the calculation answer and send it on to the out port.

Examples

Please take a look at the examples for these components on Github. If you would like to run these examples, please be sure to install the dev dependencies for this NPM package after you download it. The examples require access to the strings, core and filesystem components which I have listed as dev dependencies, since they are only required for the examples.

Message Enrichment

Here is an example of enriching a data message with the result of a calculation. In the diagram below, I have attempted to describe 1 message arriving on the config port and 1 on the data port, resulting in one message being sent on the out port. I have colour coded the matching JSON entities in the input and output messages to show how they are related.

The CONFIG message sets the mathematical expression to be evaluated. You can use variables in the expression whose values may change depending on the data message. In this example, the variable named a is highlighted in red. When a data message arrives, the value for a will be looked up in the data message at the body.weight location in the data message. Just as the variable b highlighted in blue will be looked up in the data message at the body.height location. You can use a broad range of JavaScript syntax to look up values in data messages, including array references.

The answer for each calculation in this example will be added to the data message by assigning the answer to the body.bmi location and then sending the data message to the OUT port. The calculation will be performed for each message that arrives on the DATA port allowing you to enrich each message and send it on.

If you prefer not to enrich a message but only to receive the answer of a calculation, set the CONFIG message's output.action value to answer only. You can also ask for the answer to be put at the start or end of an array in the data message by setting the output.action value to one of add to array start or add to array end.

diagram

Group Behaviour Cascade

When either component in this library receives a BEGINGROUP or ENDGROUP event, it will pass those group messages on to the OUT and ERROR ports. This should support you processing data groups through your entire flow when you use these components.