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

node-red-contrib-counter

v0.1.6

Published

A Node-RED node to create a counter with messages.

Downloads

1,409

Readme

node-red-contrib-counter

GitHub version NPM version Dependencies Status

A Node-RED node to create a counter with messages.


Table of Contents


Install

Run the following command in your Node-RED user directory - typically ~/.node-red:

npm install node-red-contrib-counter

Usage

By default the counter will be incremented for every inbound message and append the current count to msg.count.

Configuration

  • Initial Count: The initial count can be set in the configuration. By default it will be zero at start.
  • Default Step: Default amount that will be incremented or decremented on every incoming message.
  • Lower Limit: Optional limitation of the lower count limit. Will add countLowerLimitReached to msg if reached.
  • Upper Limit: Optional limitation of the upper count limit. Will add countUpperLimitReached to msg if reached.
  • Mode: Determine if count value should be incremented or decremented on every incoming message.
  • Outputs: Selects the output format of the counter. For more info read below.

Output

There are two output options for the counter value:

  • single: The actual count will be appended to msg.count of the original msg.
  • split: The node will become two outputs, first will return the count as msg.payload and possible limitation info, the second returns the untouched original msg.

Control

It's possible to control the counter with incoming msg properties:

  • msg.increment: counter will be incremented by the given value.
  • msg.decrement: counter will be decremented by the given value.
  • msg.reset: resets the counter to it's initial count, or to the given value, when it's a number.

Example Flows

Simple example showing how to use the counter and it's output.

example1.png

[{"id":"25b6280d.1ecf6","type":"inject","z":"327d23e5.bb5924","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":160,"wires":[["8a41c1.6006b64"]]},{"id":"285e0e19.b9680a","type":"inject","z":"327d23e5.bb5924","name":"increment","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":120,"wires":[["ce8d952f.18666"]]},{"id":"fda0a334.bc9588","type":"inject","z":"327d23e5.bb5924","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":370,"y":200,"wires":[["17cce981.975686"]]},{"id":"ce8d952f.18666","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.increment = 2;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":120,"wires":[["ac65bf94.6e609"]]},{"id":"17cce981.975686","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.reset = true;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":200,"wires":[["ac65bf94.6e609"]]},{"id":"8a41c1.6006b64","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":160,"wires":[["ac65bf94.6e609"]]},{"id":"ac65bf94.6e609","type":"counter","z":"327d23e5.bb5924","name":"","init":"0","step":1,"lower":null,"upper":null,"mode":"increment","outputs":"1","x":740,"y":140,"wires":[["988afc3c.a08f98"]]},{"id":"370626a8.22216a","type":"inject","z":"327d23e5.bb5924","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":470,"y":80,"wires":[["ac65bf94.6e609"]]},{"id":"988afc3c.a08f98","type":"debug","z":"327d23e5.bb5924","name":"message","active":true,"console":"false","complete":"true","x":900,"y":140,"wires":[]}]

example2.png

[{"id":"4f41c5a1.85426c","type":"inject","z":"327d23e5.bb5924","name":"decrement","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":380,"wires":[["e9085587.2d19c"]]},{"id":"afb267a8.63739","type":"inject","z":"327d23e5.bb5924","name":"increment","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":380,"y":340,"wires":[["4a35e3c7.3dbd0c"]]},{"id":"f066adf1.21ba","type":"inject","z":"327d23e5.bb5924","name":"reset","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":370,"y":420,"wires":[["523f8e05.d5537"]]},{"id":"4a35e3c7.3dbd0c","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.increment = 3;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":340,"wires":[["f33ad4bd.777a5"]]},{"id":"523f8e05.d5537","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.reset = 10;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":420,"wires":[["f33ad4bd.777a5"]]},{"id":"e9085587.2d19c","type":"function","z":"327d23e5.bb5924","name":"msg object","func":"msg.decrement = 1;\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":380,"wires":[["f33ad4bd.777a5"]]},{"id":"9b40b088.73732","type":"debug","z":"327d23e5.bb5924","name":"count","active":true,"console":"false","complete":"payload","x":890,"y":340,"wires":[]},{"id":"f33ad4bd.777a5","type":"counter","z":"327d23e5.bb5924","name":"","init":"100","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"2","x":740,"y":360,"wires":[["9b40b088.73732"],["876cc69d.d4b438"]]},{"id":"99b73d63.9fdb","type":"inject","z":"327d23e5.bb5924","name":"normal msg without control parameter","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":470,"y":300,"wires":[["f33ad4bd.777a5"]]},{"id":"876cc69d.d4b438","type":"debug","z":"327d23e5.bb5924","name":"message","active":false,"console":"false","complete":"true","x":900,"y":380,"wires":[]}]

Bugs / Feature request

Please report bugs and feel free to ask for new features directly on GitHub.

License

This project is licensed under Apache 2.0 license.

Donation

You like to support me?
You appreciate my work?
You use it in commercial projects?

Feel free to make a little donation! :wink: