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

fingi-cmd

v0.2.1

Published

Fingi command protocol parser and serializer.

Downloads

2

Readme

FINGI-CMD

Install with

$ npm i fingi-cmd --save

USAGE

The package exports the Command class, a parse method and a Stream which is a Duplex stream that works on Command instances.

COMMAND class

Create by invoking the constructor with new and passing the desired command properties.

var Command = require('fingi-cmd').Command;
var cmd = new Command({ action: 'HELLO' });

Properties include:

  • nonce - (number) The nonce counter.
  • source - (string array) The command source (or origin.)
  • action - (string) The action to carry out.
  • args - (string array) Arguments

Check with the official Fingi protocol description for more information.

When you already have a Command instance, these 2 methods may be of interest:

cmd.sign(secret)

Signs the entire command line using the HMAC-SHA1 algorithm and append the resulting signature digest as the last argument.

cmd.toString()

Returns correct protocol represenation of the command as a string ready to be sent onto the wire.

STREAM

The exported Stream is an instance of node core's Duplex object-mode stream which automatically parses incoming data into Command instances and then allow send()-ing out commands to the wire.

var CmdStream = require('fingi-cmd').Stream;
var commands = new CmdStream();

Receiving commands

To receive commands, pipe your raw incoming stream into the CmdStream and listen for the command event. The chunker module is also recommended to ensure that the stream always receives a full line.

process.stdin.pipe(commands);
commands.on('command', function(cmd) {
  console.log('receive:', cmd.action());
});

Or when using with chunker:

var chunker = new (require('chunker'))({ matcher: '\r\n' });
process.stdin.pipe(chunker).pipe(commands);

// commands.on('command')... as usual

Sending commands

Send commands by using the send() method, passing in the Command instance to send.

commands.pipe(process.stdout);

// send PINGs every second.
setInterval(function() {
  commands.send(new Command({ action: 'PING' }));
}, 1000);

PARSE

Optionally, you may have a string representation that you would like to parse by yourself. You can do this by using the exported parse() function:

var parse = require('fingi-cmd').parse;

var input = '1000 server-name 9.9.99 | HELLO device\r\n';
var cmd = parse(input);

console.log(cmd.source[0]); // prints "server-name"

LICENSE

MIT. See the LICENSE file for the full license text.