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

1.1.6 • Public • Published

ts-match

A small matching library for TypeScript. The API is a single function defined as:

function match<T, R>(input: T, defaultCase: IDefaultCase<R>, ...cases: ICase<T, R>[]): R

Example:

const s: Foo = new C(5, `test string`);
const result = match<Foo, number>(s,
    _(-42),
    when(A, s => s.a),
    when(B, s => s.b),
    when(C, s => s.c),
);

Readme

Keywords

none

Package Sidebar

Install

npm i ts-match

Weekly Downloads

5

Version

1.1.6

License

ISC

Unpacked Size

3.75 kB

Total Files

7

Last publish

Collaborators

  • whymarrh