GithubHelp home page GithubHelp logo

zerobias / mezza Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 43 KB

๐ŸŽฏ An object switch-case. Selects the appropriate case from the object with variants

License: MIT License

JavaScript 97.50% Shell 2.50%

mezza's Introduction

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

mezza's People

Contributors

zerobias avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.