Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/aaronshaf/match-map
- Owner: aaronshaf
- License: mit
- Created: 2017-10-10T19:38:50.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-10-10T20:35:42.000Z (about 7 years ago)
- Last Synced: 2024-11-24T17:14:05.879Z (about 1 month ago)
- Topics: javascript, map, match
- Language: JavaScript
- Homepage: https://scrimba.com/c/czLZPUr
- Size: 27.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 :(']
]))
```