Socket
Socket
Sign inDemoInstall

hash-value

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    hash-value

Get a consistent value from an array based on a string value.


Version published
Maintainers
1
Install size
5.11 kB
Created

Readme

Source

NPM Version CI codecov

Hash Value

Get a consistent value from an array based on a string value.

Table of Contents

Installation

npm install hash-value --save

Usage

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

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 <Avatar style={{ backgroundColor: bg }}>{name.charAt(0)}</Avatar>;
}

Development

npm install
npm run build

Keywords

FAQs

Last updated on 23 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc