# hashpick

> Pick an item from an array based on the hash of a value

Latest version **4.0.1** (published 2022-10-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install hashpick
pnpm add hashpick
yarn add hashpick
bun add hashpick
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2022-10-21 |
| First published | 2018-08-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Roman Decker |
| Maintainers | the_roman_empire |

## Links

- npm: https://www.npmjs.com/package/hashpick
- Repository: https://github.com/DeX3/hashpick
- Issues: https://github.com/DeX3/hashpick/issues
- npm.io page: https://npm.io/package/hashpick

## Dependencies (1)

- [rimraf](https://npm.io/package/rimraf.md) ^3.0.2

## Recent versions

- 4.0.1 (latest) — 2022-10-21
- 4.0.0 — 2022-08-09
- 3.0.1 — 2019-07-05
- 3.0.0 — 2018-12-28
- 2.0.0 — 2018-12-21
- 1.0.3 — 2018-12-17
- 1.0.2 — 2018-12-11
- 1.0.1 — 2018-08-09
- 1.0.0 — 2018-08-09

## README

hashpick
========

Pick an item from an array based on the hash of a value. Useful if you want to consistently map data
that's not known beforehand to a discrete set of target values.

In short, this module enables you to do something like this:

``` javascript
const chalk = require('chalk');
const pickColor = require('hashpick').default([
    chalk.red,
    chalk.green,
    chalk.yellow,
    chalk.blue,
    chalk.magenta,
    chalk.cyan,
    chalk.gray,
]);

const colorize = (str) => {
    const color = pickColor(str);
    return chalk.bold(color(str));
};

console.log(colorize('config'), 'Loaded cache');
console.log(colorize('db'), 'Connected to database');
console.log(colorize('server'), 'Server listening on port 1234');
console.log(colorize('db'), 'Database connection lost');
console.log(colorize('db'), 'Reconnecting to database');
console.log(colorize('server'), 'GET / 200');
```

![Output](https://cdn.rawgit.com/DeX3/hashpick/267e79d4/docs/output.png)

## Installation

``` shell
npm install --save hashpick
# or
yarn add hashpick
```

## Usage

Use the exported function to create a new picker-function based on an array of choices:

``` shell
const hashpick = require('hashpick').default;
const pickNumber = hashpick(['one', 'two', 'three']);

pickNumber('any value'); // -> 'three'
```


## API

### `hashpick(choices: T[]): (string) => T`

Creates a new picker that will consistently pick the same value from `choices` based on its input.

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