1.3.6 • Published 3 years ago

@meetingmaker/generate-colors v1.3.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Get colors for strings

Use case

To differentiate between UI elements of different categories, we can use colors. For example, a unique color per event type can be used in a Calendar UI to differentiate between different type of events. Sometimes, we may need to show a unique background color for user's avatar when we don't have a profile picture.

Install

npm i -S generate-colors

Usage

Usage are pretty simple. Just import the getColorForString method from the module and call it with a string that uniquely identifies an object (User Account, Event Type). The method returns an array with [R, G, B] values.

import { getColorForString } from "generate-colors"

const color = getColorForString("First Name and Last Name")
// color = [90, 39, 50]

Passing the same string again will result in the same color.

Available Method

/**
 * Generate the color a string
 * @param {string} str String for which we want to get the colors
 * @param {{ contrast: number }} [config={ contrast: 30 }] - Configuration for the color
 * @returns {Array} Array with R,G,B values in sequence
 */
function getColorForString(str, config): [number, number, number]

Visit Playground to see in section.

CLI

This module also exposes a CLI tool to generate colors from command line itself.

npx generate-colors "unique@example.com" --contrast=35

Contribution

Any kind of contribution is most welcome!!

Setup

  1. Fork the repository to your account.
  2. Clone the repository and install dependencies.
git clone git@github.com:<your_username>/generate-colors
cd generate-colors
npm install
  1. The source code exists in /src directory.

Available Scripts

ScriptDescription
testRun all the tests
lintTo run the linter
coverageTo create the test coverage report
devTo start the development with docs website
releaseTo release a new version

Any script can be executed by calling npm run <script_name>.

Licence

MIT

1.3.6

3 years ago

1.3.5

3 years ago