# @eatsjobs/ts-pattern-match

> Simple pattern matching

Latest version **0.1.0** (published 2023-06-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @eatsjobs/ts-pattern-match
pnpm add @eatsjobs/ts-pattern-match
yarn add @eatsjobs/ts-pattern-match
bun add @eatsjobs/ts-pattern-match
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2023-06-13 |
| First published | 2023-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 18 |
| Dependencies | 0 |
| Unpacked size | 11.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | @eatsjobs Pasquale Mangialavori |
| Maintainers | eatsjobs |

## Links

- npm: https://www.npmjs.com/package/@eatsjobs/ts-pattern-match
- Repository: https://github.com/eatsjobs/ts-pattern-match
- Homepage: https://github.com/eatsjobs/ts-pattern-match#readme
- Issues: https://github.com/eatsjobs/ts-pattern-match/issues
- npm.io page: https://npm.io/package/@eatsjobs/ts-pattern-match

## Recent versions

- 0.1.0 (latest) — 2023-06-13

## README

# Simple Pattern Matching

For complex logic sometime switch is not enough. There's a pattern matching proposal but it's not ready yet.
https://github.com/tc39/proposal-pattern-matching

## Getting Started

```sh
npm i @eatsjobs/ts-pattern-matching
```

## Usage

```typescript
  import type { Predicate, Handler } from "@eatsjobs/ts-pattern-matching";
  import match from "@eatsjobs/ts-pattern-matching";

  type Input = { a: boolean };
  const predicate: Predicate<Input> = (input) => {
    return input.a
  };

  const handler: Handler<string> = (input: Input) => {
    return "this will executed if predicate returns true"
  };

  
  const string = match<Input, string>({ a: true })
    .when(predicate, handler)
    .when(..., ...)
    .otherwise(() => "default string") // default handler
    .run();

```

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