0.0.2 • Published 6 years ago

tagged-switch v0.0.2

Weekly downloads
4
License
GPL-3.0
Repository
github
Last release
6 years ago

tagged-switch

npm npm

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.