# ts-condition-handler

> Execute the corresponding handler by customized definition in a declarative way.

Latest version **0.1.0** (published 2021-02-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-condition-handler
pnpm add ts-condition-handler
yarn add ts-condition-handler
bun add ts-condition-handler
```

## 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 | 2021-02-20 |
| First published | 2021-02-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | guansunyata |
| Maintainers | guansunyata |

## Links

- npm: https://www.npmjs.com/package/ts-condition-handler
- npm.io page: https://npm.io/package/ts-condition-handler

## Recent versions

- 0.1.0 (latest) — 2021-02-20

## README

# ts-condition-handler

Execute the corresponding handler by customized definition in a declarative way.

## Example

```ts
import { conditionHandler } from 'ts-condition-handler'

function main() {
  try {
    // do something that may throw an error in a specific type
    doSomething()
  } catch (err) {
    conditionHandler(error)
      .on(CustomerNotFound, handleCustomerNotFound)
      .on(CustomerCreditLimitExceeded, handleCustomerCreditLimitExceeded)
      .fallback(handleUnknownError)
  }
}

function doSomething() {
  throw new CustomerNotFound()
}
```

## Test
```
yarn test
```

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