Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/maximilian-krauss/fluent-switch

Everything is better if its fluent
https://github.com/maximilian-krauss/fluent-switch

Last synced: 6 days ago
JSON representation

Everything is better if its fluent

Awesome Lists containing this project

README

        

# FluentSwitch

[![Build Status](https://travis-ci.org/maximilian-krauss/fluent-switch.svg?branch=master)](https://travis-ci.org/maximilian-krauss/fluent-switch)

Better way to do switching.

## Installation

```bash
npm i fluent-switch
```

## Usage

### No fallback

```js
FluentSwitch
.createFrom(error)
.case(e => e instanceof TimeoutError, e => log.error('timeout', e))
.case(e => e instanceof ConnectionError, () => e => log.error('connection', e))
.execute()
```

### With fallback

```js
FluentSwitch
.createFrom(error)
.case(e => e instanceof TimeoutError, e => log.error('timeout', e))
.case(e => e instanceof ConnectionError, () => e => log.error('connection', e))
.else(e => log.error('Unknown error', e))
.execute()
```