3.0.0 • Published 8 years ago

match-default v3.0.0

Weekly downloads
6
License
MIT
Repository
-
Last release
8 years ago

match-default

Pass in a string, and object contain functions that could possibly match string + a default function denoted with the _ key. Made because I think this looks really nice with redux, semi inspired by the pattern matching implementation in Rust.

use

npm i --save match-default

import match from 'match-default';
const data = match({
	a: () => 'nice',
	b: () => 'cool',
	string: () => 'woo',
	_: () => ''
}, 'string');

Currying

The function can also be curried by passing in a single argument of an object. A function will be returned expecting a single argument of a string to match against the provided object.

import match from 'match-default';
const matcher = match({cool: () => 'wow', _: () => {}});
const myMatch = matcher('cool');
console.log(myMatch) //myMatch === 'wow'
3.0.0

8 years ago

2.0.0

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago