Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/maximilian-krauss/fluent-switch
- Owner: maximilian-krauss
- Created: 2018-12-12T11:59:30.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-28T05:36:29.000Z (over 1 year ago)
- Last Synced: 2024-04-24T16:19:30.545Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 669 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
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()
```