# common

> A utility package with some useful functional stuff

Latest version **0.2.5** (published 2013-08-21) · 0 weekly downloads

## Install

```sh
npm install common
pnpm add common
yarn add common
bun add common
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2013-08-21 |
| First published | 2011-06-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | Ge.tt |
| Maintainers | mafintosh, ianjorgensen |

## Links

- npm: https://www.npmjs.com/package/common
- Repository: https://github.com/gett/common
- Issues: https://github.com/gett/common/issues
- npm.io page: https://npm.io/package/common

## Recent versions

- 0.2.5 (latest) — 2013-08-21
- 0.2.4 — 2013-08-15
- 0.2.3 — 2013-05-23
- 0.2.1 — 2011-08-31
- 0.2.0 — 2011-08-31
- 0.1.4 — 2011-08-06
- 0.1.3 — 2011-08-03
- 0.1.2 — 2011-07-23
- 0.1.1 — 2011-06-22
- 0.1.0 — 2011-06-18

## 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](https://github.com/creationix/step) that also provides error handling

``` js
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.

``` js
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`:

``` js
// 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:

``` js
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`:

``` js
// 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`

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

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

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

Common can also encode integers into alphanumerical notation using `encode`:

``` js
common.encode(1000); // returns G8
```

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

``` js
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`.

---
_Source: https://npm.io/package/common · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
