package
A better switch case
npm install select-caseGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
4.0 kB
Includes dependencies.
A better switch case
npm install select-case --saveimport { 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'
})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.
None
None
MIT