Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/aaronshaf/match-map

Match against the keys in a map
https://github.com/aaronshaf/match-map

javascript map match

Last synced: 25 days ago
JSON representation

Match against the keys in a map

Awesome Lists containing this project

README

        

## Installation

```
yarn add match-map
```

Or:

```
npm install match-map --save
```

## Usage

```javascript
import matchMap from 'match-map'
```

Or:

```javascript
const matchMap = require('match-map')
```

Then:

```javascript
const Processing = Symbol()
const Successful = Symbol()
const Error = Symbol()

const state = Successful
const statusMessage = matchMap(state)([
[Loading, 'Your task is processing'],
[Successful, 'Your task was successful!'],
[Error, 'There was an error with your task :(']
])
```

Alternatively:

```javascript
const statusMessage = matchMap(state)(new Map([
[Loading, 'Your task is processing'],
[Successful, 'Your task was successful!'],
[Error, 'There was an error with your task :(']
]))
```