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

comun

v0.2.3

Published

A utility package with some useful functional stuff

Downloads

3

Readme

Common

A utility module for both node.js and the browser.
It is available through npm:

npm install common

Or as minified js file for the browser:

<script src='common.min.js'></script>

This module among other things contains a fork of step that also provides error handling

common.step([
	function(next) { // next is the last argument, except in the last handler
		fs.readFile(__filename, 'utf-8', next);
	},
	function(file) {
		console.log(file);
	}
], function(err) {
	// any error received in a callback will be forwarded here
});

It also contains a shortcut to the EventEmitter prototype and a compatible implementation of this for the browser.

var MyEmitter = common.emitter(function() {
	this.foo = 42;
});

var me = new MyEmitter();

me.emit('foo', me.foo); // emits 'foo',42

There is also a more general method for extending prototypes called extend:

// this prototype is the same as above
var MyEmitter = common.extend(events.EventEmitter, function() {
	this.foo = 42;
});

If you want to use futures you can use the future function to create a future:

var fut = common.future();

fut.get(function(val) {
	console.log(val);
});
setTimeout(function() {
	fut.put(42); // results in the previous .get being called and all future .get's will be called synchroniously
}, 1000)

To do string formatting you can use format:

// you can parse the arguments to a pattern one by one
common.format('define {0} here', 'pattern'); // returns 'define pattern here'

// or as a map or array
common.format('define {foo} here', {foo:'pattern'}); // same as above

There is a log method that just accepts the does the same as format except it prints out the result using console.log if available

To generate a simple weak symbols (often used when generating keys for a map) use gensym

common.gensym() // returns 's0'
common.gensym() // returns 's1'

If you instead of a weak symbol need a strong one use uuid:

common.uuid(); // returns a strong id, ex: ngDl6IdovME9JKvIxgED0FK1kzURxfZaCq48-0

Common can also encode integers into alphanumerical notation using encode:

common.encode(1000); // returns G8

To ensure that a method cannot be called more than once you can use the once function:

var fn = common.once(function() {
	console.log('hello');
});

fn(); // prints hello
fn(); // does nothing

Besides the above common implements two of the utilities mentioned in The Good Parts, memoizer and curry.