# @quenk/match

> Runtime pattern matching for JavaScript.

Latest version **1.3.2** (published 2018-03-18) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @quenk/match
pnpm add @quenk/match
yarn add @quenk/match
bun add @quenk/match
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.3.2 |
| Published | 2018-03-18 |
| First published | 2018-01-03 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lasana Murray |
| Maintainers | metasansana |
| Keywords | pattern-matching, typeScript, javaScript, runtime, functional-programming |

## Links

- npm: https://www.npmjs.com/package/@quenk/match
- Repository: https://github.com/quenktechnologies/match
- Homepage: https://github.com/quenktechnologies/match#README.md
- Issues: https://github.com/quenktechnologies/match/issues
- npm.io page: https://npm.io/package/@quenk/match

## Dependencies (1)

- [@quenk/kindof](https://npm.io/package/@quenk/kindof.md) ^1.2.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.3.2 (latest) — 2018-03-18
- 1.3.1 — 2018-03-18
- 1.3.0 — 2018-03-17
- 1.2.1 — 2018-03-17
- 1.2.0 — 2018-02-10
- 1.1.0 — 2018-01-09
- 1.0.3 — 2018-01-03

## README

Match
=======

Runtime pattern matching for ECMAScript.

## Installation

```sh

  npm install --save @quenk/match

```

## Usage

`match` exports a single function `match` as well as two classes `UnMatchedResult` and `MatchedResult`
(See typescript for interface).

`match` constructs a new `UnMatchedResult` with the value provided, use the `caseOf` to test the shape
of the value or the `orElse` method for the default case.

Complete the pattern matching by calling the `end()` method which will return the final value
(after applying any matching functions).

If none of the matches succeed an error will be thrown.

### Example

```typescript

  import {match} from '@quenk/match';

  class CLA {}
  class CLB {}
  class CLC {}

  // result is 3
  let result = 
    match(new CLC())
      .caseOf(CLA, (v:CLA)=> 1)
      .caseOf(CLB, (v:CLB)=> 2)
      .caseOf(CLC, (v:CLC)=> 3)
      .end();

  // result is 24
  let result = 
    match(12)
      .caseOf(CLA, (v:CLA)=> 1)
      .caseOf(CLB, (v:CLB)=> 2)
      .caseOf(CLC, (v:CLC)=> 3)
      .orElse((n:number)=> n * 2)
      .end();

  // throws an error
  let result =
    match(new Date())
      .caseOf(Array, (n:Array)=> n.length)
      .end();

```

For more information on the pattern matching process see the 
[kindof](https://github.com/quenktechnologies/kindof#description) library.

# License

Apache-2.0 (C) Quenk Technologies Limited.

---
_Source: https://npm.io/package/@quenk/match · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
