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

fsmjs

v0.2.1

Published

State machines are back

Downloads

1,957

Readme

fsmjs

State machines are back, the async way!

$ npm install fsmjs

By example

var fsmjs = require('../lib/fsmjs');

var tim = fsmjs({

	idle: {

		// when 'go' or 'start' or 'g' are pushed, we move to 'running' and start
		// an interval that emits a 'tick' event every 100ms.
		'(go|start|g)': function(cb) {
			process.stdout.write('starting engines...\n');
			tim.state = 'running'; 
			tim._timer = tim.interval('tick', 100);
			cb();
		},

		// strings are target states (and emitted events)
		exit: 'end',
		e: 'error',

		// any other event in this state shows this error
		'.*': function(cb, e) {
			console.log('error: i cant understand what you mean by "' + e + '"');
			cb();
		},
	},

	running: {

		// animate clock every tick
		tick: function(cb) {
			var clock = [ '|', '/', '-', '\\' ];
			process.stdout.write('(' + clock[tim._i] + ")");
			for (var i = 0; i < 50; ++i) process.stdout.write(' ');
			process.stdout.write('\r');
			tim._i = (tim._i + 1) % clock.length;
			cb();
		},

		// cannot exit from this state
		exit: 'error',

		// when 'no' or 'stop' or 'x' are pushed, move to 'stopping' and start
		// a 2sec timeout that emits 'elapsed' when elapsed (surpise!)
		'(no|stop|x)': function(cb) { 
			process.stdout.write('stopping...\n');
			tim.state = 'stopping';
			tim.timeout('stopped', 5000);

			cb();
		},

		$exit: function(cb) {
			// take some time before changing state.
			console.log('our running times are over.. give me 2 more seconds.');
			setTimeout(cb, 2000);
		},

	},

	stopping: {

		// called when the stopping timer elapses. clears the 
		// interval and changes state to 'idle'
		stopped: function(cb) {
			process.stdout.write('\nall done.\n');
			clearInterval(tim._timer);
			tim.state = 'idle';
			cb();
		},

		// a tick during stop operation, show dots
		tick: function(cb) {
			process.stdout.write(".");
			cb();
		},

		exit: 'error',

	},

	error: function(cb, state) {
		console.log('An error occured in state', state);
		tim.state = state;
		cb();
	},

	_timer: null, // timer object to allow clearing the interval
	_i: 0, // animated clock
});

tim.on('end', function() {
	process.exit();
});

tim.on('error', function() {
	console.log('on-error');
});

tim.on('idle.start', function() {
	console.log("try 'go' the next time...");
});

var i = require('../lib/debugger')(tim, { verbose: false });

More examples under examples/.