match-ts
TypeScript icon, indicating that this package has built-in type declarations

0.9.1 • Public • Published

match-ts

match-ts is a cute pattern matcher that you can use when you want your code to be super cool and chained.

Get rid of those nasty if-else blocks and start matching!

examples

import match from 'match-ts';

const greet = (name?: string) =>
  match(name)
    .on(name === 'Carlos', `I'm not saying hi to you >:(`)
    .on(name != null, `hey ${name} how are you :)`)
    .otherwise('hey there friend');

const greetWithFunctionInputs = (name?: string) =>
  match(name)
    .on(n => n === 'Carlos', `I'm not saying hi to you >:(`)
    .on(
      n => n != null,
      n => `hey ${n} how are you :)`
    )
    .otherwise(n => 'hey there friend');

greet('Carlos'); // "I'm not saying hi to you >:("
greetWithFunctionInputs('David'); // "hey David how are you :)"

Never break a beautiful chain for some lame imperative logic ever again!

Readme

Keywords

none

Package Sidebar

Install

npm i match-ts

Weekly Downloads

2

Version

0.9.1

License

MIT

Unpacked Size

11.9 kB

Total Files

13

Last publish

Collaborators

  • andres-valdes