# hash-switch

> Switch pattern based on object hash

Latest version **2.2.1** (published 2017-11-17) · Apache-2.0 license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2017-11-17 |
| First published | 2016-06-27 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | @dam |
| Maintainers | dam |
| Keywords | hash, switch, object |

## Links

- npm: https://www.npmjs.com/package/hash-switch
- Repository: https://github.com/kristoferjoseph/hash-switch
- Homepage: https://github.com/kristoferjoseph/hash-switch#readme
- Issues: https://github.com/kristoferjoseph/hash-switch/issues
- npm.io page: https://npm.io/package/hash-switch

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2017-11-17
- 2.2.0 — 2017-11-17
- 2.1.4 — 2017-03-30
- 2.1.3 — 2016-07-19
- 2.1.2 — 2016-06-27
- 2.1.1 — 2016-06-27
- 2.1.0 — 2016-06-27
- 2.0.0 — 2016-06-27
- 1.0.0 — 2016-06-27

## README

# hash-switch
This lib is made to give you the same functionality as a `switch` statement but with a more natural API.

### Compare:
```js
switch(expression) {
  case 'one':
    return 'ONE';
  break;
  case 'two':
    return 'TWO';
  break;
  default:
    return 'DEFAULT';
  break;
}
```

### To:
```js
hs({
  'one':function(){ return 'ONE' },
  'two':function(){ return 'TWO' }
},
function() { return 'DEFAULT' })
```
For me the second example is a much more familiar syntax and meshes with my other JavaScript more naturally.

## Install
`npm i hash-switch --save`

## Usage
```js
var hs = require('hash-switch')({
    'one': function() {return 'ONE'},
    'two': function() {return 'TWO'},
    /* Extra arguments will be passed to the callback function */
    'three': function(four) {return 'THREE' + ' ' + four}
  },
  function(){return 'DEFAULT'}
)

hs('one') //ONE
hs('two') //TWO
/* You can pass an extra argument to the callback function like so */
hs('three', 'FOUR') //THREE FOUR
hs('nope') //DEFAULT
```

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