0.2.2 • Published 7 years ago

mezza v0.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Mezza 🎯

An object switch-case. Selects the appropriate case from the object with variants. Core part of mezzanine

npm install --save mezza

NPM version Unix Build Status Windows Build Status Coveralls Status Dependency Status

Usage

import choose from 'mezza'

function findUsers(username) {
  /* Some function that returns a list of users */
}

const cases = {
  Some: value => Array.isArray(value) && value.length > 1,
  One : value => Array.isArray(value) && value.length === 1,
  None: value => Array.isArray(value) && value.length === 0
}

const actions = {
  Some: list => 'Find ' + list.length + ' users',
  One : list => 'Find one user: ' + list[0],
  None: () => 'Nothing found',
  _   : () => 'Oops, something going wrong!' //Optional default case
}



function printUsers(username) {
  const found = findUsers(username)
  const resultText = choose(cases, actions, found)
  return resultText
}

Method is curried by default

const printText = choose(cases, actions)

printText(['username']) // => Found one user: username
printText({}) // => 'Oops, something going wrong!'

Try this example in browser

Edit Mezza example

License

The project is released under the Mit License

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.2.0-rc1

7 years ago

0.1.0

7 years ago