# switch-expression

> A simple function providing similar functionality to a switch statement using method chaining with a single composable expression.

Latest version **0.0.11** (published 2021-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install switch-expression
pnpm add switch-expression
yarn add switch-expression
bun add switch-expression
```

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2021-08-05 |
| First published | 2021-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | scrabblisk |

## Links

- npm: https://www.npmjs.com/package/switch-expression
- Repository: https://github.com/scrabblisk/switch-expression
- Issues: https://github.com/scrabblisk/switch-expression/issues
- npm.io page: https://npm.io/package/switch-expression

## Recent versions

- 0.0.11 (latest) — 2021-08-05
- 0.0.10 — 2021-08-04
- 0.0.9 — 2021-08-01
- 0.0.8 — 2021-08-01
- 0.0.7 — 2021-07-28
- 0.0.6 — 2021-07-28
- 0.0.5 — 2021-07-28
- 0.0.4 — 2021-07-27
- 0.0.3 — 2021-07-27
- 0.0.2 — 2021-07-27
- 0.0.1 — 2021-07-27

## README

# Switch Expression

A simple function providing similar functionality to a switch statement using method chaining with a single composable expression.

## Usage

```typescript
import { Swtich } from "switch-expression";
// or if using commonjs:
// const { Switch } = require("switch-expression")

// returns "Hello World"
Switch<string, string>("hello")
  .case(0, () => "case 0")
  .case("test", () => "case test")
  .case("hello", () => "Hello World!")
  .default(() => "Found no match");

// When no match is found the default case is returned:
//   "Found no match"
Switch<string | number, React.ReactNode>("hEll0")
  .case(0, () => "case 0")
  .case("test", () => <p>case test</p>)
  .case("hello", () => "Hello World!")
  .default(() => "Found no match");

// returns <p>case test</p>
Switch<string | number, React.ReactNode>("test")
  .case(0, () => <p>case 0</p>)
  .case("test", () => <p>case test</p>)
  .case("hello", () => <p>Hello World!</p>)
  .run();

// When no match is found the run method will return null
Switch<string | number, React.ReactNode>("hEll0")
  .case(0, () => <p>case 0</p>)
  .case("test", () => <p>case test</p>)
  .case("hello", () => <p>Hello World!</p>)
  .run();
```

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