matchly
Pattern matching for JavaScript (and TypeScript)
Usage
Match whatever you need, with wildcards.
With one condition
const branch1 = 'no'const branch2 = 'yes'const defaultBranch = 'maybe' const condition = // no // yes // maybe // maybe
With multiple conditions
const branch1 = values0 + values1const branch2 = values0 * values1const branch3 = values0 / values1const defaultBranch = value const condition = // 3 (branch1) // 6 (branch2) // 2 (branch3) // 6 (branch3) // [1337, 42] (defaultBranch)
Collecting rest
const branch1 = 'branch1: ' + valuesconst branch2 = 'branch2: ' + values const condition = // branch1: a,b,c // branch2: a,d,e