tagged-switch

0.0.2 • Public • Published

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.

/tagged-switch/

    Package Sidebar

    Install

    npm i tagged-switch

    Weekly Downloads

    1

    Version

    0.0.2

    License

    GPL-3.0

    Unpacked Size

    38.5 kB

    Total Files

    5

    Last publish

    Collaborators

    • christianost