tagged-switch
v0.0.2
Published
Library to experiment using template literals for creating a case-matching statement which returns the respective values.
Downloads
4
Maintainers
Readme
tagged-switch
Library to experiment using template literals for creating a switch
/case
expression returning the respective value.
Installation
npm install --save tagged-switch
yarn add tagged-switch
Usage
The library can be used to create case-matching statements which returns the respective value:
import taggedSwitch from 'tagged-switch';
const currencySymbolToName = taggedSwitch`
${'€'} -> ${'Euro'}
${'$'} -> ${'Dollar'}
${'£'} -> ${'Pound'}
_ -> ${'Unknown'}
`;
console.log(currencySymbolToName('€')); // Euro
TODO
- input validation
- support of ES5
License
Licensed under GNU General Public License v3.0. See LICENSE.