npm.io
0.3.2 • Published 4 years ago

pattern-matched

Licence
MIT
Version
0.3.2
Deps
0
Size
22 kB
Vulns
0
Weekly
0
Stars
1

Pattern Match

A pattern matching library that supports primitives, objects and arrays.

const value = 1;
match(value)
  .when(0, () => 1) // Similar to if (value === 0) return 1;
  .when(1, 2) // This is also valid
  .when(2, (matched) => console.log(matched)) // Access the matched value, this would log 2
  .else(); // Runs the match, infers result type to be 1, 2 or undefined. Can also be passed a default value.