JSPM

  • Created
  • Published
  • Downloads 1737845
  • Score
    100M100P100Q198345F
  • License MIT

Typescript pattern matching library

Package Exports

  • ts-pattern

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-pattern) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Typescript Pattern

A complete pattern matching library for typescript.

import { match, __, when, not } from 'pattern';

match({ type: 'hello' })
  .with(__, () => 'ok')
  .with(__.string, () => 'ok')
  .with(
    when((x) => true),
    () => 'ok'
  )
  .with(not('hello'), () => 'ok')
  .with(not(__.string), () => 'ok')
  .with(not(when((x) => true)), () => 'ok')
  .with({ type: __ }, () => 'ok')
  .with({ type: __.string }, () => 'ok')
  .with({ type: when((x) => true) }, () => 'ok')
  .with({ type: not('hello') }, () => 'ok')
  .with({ type: not(__.string) }, () => 'ok')
  .with({ type: not(when((x) => true)) }, () => 'ok');