https://github.com/justinlettau/hash-value
Get a consistent value from an array based on a string value.
https://github.com/justinlettau/hash-value
avatar color consistent hash permanent string
Last synced: about 1 year ago
JSON representation
Get a consistent value from an array based on a string value.
- Host: GitHub
- URL: https://github.com/justinlettau/hash-value
- Owner: justinlettau
- License: mit
- Created: 2019-04-22T03:38:26.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-07-25T03:29:41.000Z (almost 2 years ago)
- Last Synced: 2024-10-11T01:12:00.878Z (over 1 year ago)
- Topics: avatar, color, consistent, hash, permanent, string
- Language: TypeScript
- Size: 175 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://badge.fury.io/js/hash-value)
[](https://github.com/justinlettau/hash-value/actions)
[](https://codecov.io/gh/justinlettau/hash-value)
# Hash Value
Get a consistent value from an array based on a string value.
# Table of Contents
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Material UI Avatar](#material-ui-avatar)
- [Development](#development)
# Installation
```bash
npm install hash-value --save
```
# Usage
```js
import hashValue from 'hash-value';
// colors from https://www.materialui.co/flatuicolors
const colors = [
'#1abc9c', // Turquoise
'#2ecc71', // Emerald
'#3498db', // Peterriver
'#9b59b6', // Amethyst
'#34495e', // Wetasphalt
'#f1c40f', // Sunflower
'#e67e22', // Carrot
'#e74c3c', // Alizarin
];
hashValue('Luke Skywalker', colors);
// => #3498db
```
# Example
## Material UI Avatar
```js
import Avatar from '@material-ui/core/Avatar';
import {
blue,
green,
orange,
purple,
red,
teal,
} from '@material-ui/core/colors';
import hashValue from 'hash-value';
const colors = [
blue[500],
green[500],
orange[500],
purple[500],
red[500],
teal[500],
];
function ColorAvatar(props) {
const { name } = props;
const bg = hashValue(name, colors);
return {name.charAt(0)};
}
```
# Development
```
npm install
npm run build
```