Pamach
Function to match against stuff.
Inspired by:
Load the thing:
const match = ;
Pass some args and spec obj:
const drink = 'coke'; const myDrink = { return 'Pssshhh...'; } { return 'I like this harvest from summer 1901...'; } { return 'After a long day...' } { return 'H20'; }; console; // -> 'Pssshhh...'
Multiple arguments:
const firstComponent = 'coke';const secondComponent = 'vodka'; const cocktail = { return 'Much better together'; } { return 'Are you sure this is a good idea?'; } { return 'H20'; } ; console; // -> 'Much better together'
Accepts anything that implements .toString
:
const person = firstName: 'Steve' lastName: 'Jobs' { return ` ` }; const collegue = { return firstName: 'Jonny' lastName: 'Ive' } { return firstName: 'Dana' lastName: 'Scully' }; console; // -> { firstName: 'Jonny', lastName: 'Ive' }
API:
match([args])
-> Function
Takes any number of args and returns new matcher
function
matcher(spec)
-> Any
that takes spec
object to map args
separated by ', '
(coma + space) as
key to corresponding function, so value returned by this function becomes the
return value of matcher
.
If no key found for given set of args
, matcher
tries to find default key in
the spec
object and call its value.
If no default
key found, undefined
is returned.
License - MIT