select-case

1.0.0 • Public • Published

select-case

A better switch case

Installation

npm install select-case --save

Usage

import { select } from "select-case";
let fruit = 'apple'
 
let color = select(fruit, {
    // can be values
    banana: 'yellow',
    // or functions
    apple: () => Math.random() > 0.5 ? 'red' : 'green',
    // default case
    default: 'red'
})

Other libs

Most other libs curried or put the cases first and the selector second. I put the selector up front and the cases afterward to try and preserve the switch/case look & feel.

Dependencies

None

Dev Dependencies

None

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i select-case

Weekly Downloads

14

Version

1.0.0

License

MIT

Unpacked Size

4.09 kB

Total Files

6

Last publish

Collaborators

  • wmhilton