Skip to content

y-golde/string-to-color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

String To Color

String to color is a package that offeres pretty colors and gradients from string.

npm i @y-golde/string-to-color

What makes to color 'pretty'?

From my experience colors that are too dark look to much alike (same for colors that are too bright), so I've limited the generated rgb values to 50-200 (by correcting for values over or under the allowed range).

The gradient is generated from the compiled color + its complementary color.

Usage

importing

The package currently offers 4 functions

import { strToColorObject, strToHex, strToRGBString, strToGradient } from '@y-golde/string-to-color';

strToColorObject

this function accepts a string and returns an object with r,g and b values (numbers)

const toObject = strToColorObject('example'); // Object {r: 78, g: 163, b: 183}

strToHex

this function accepts a string and returns the color as a hex (string)

const toObject = strToHex('example'); // "#4eb7a3"

strToRGBString

this function accepts a string and returns the color as a rgb string (for css uses)

const toObject = strToRGBString('example'); // "rgb(78,163,183)"

strToGradient

this function accepts a string and returns the color as a linear gradient to its complementary (for css background)

const toObject = strToGradient('example'); // "linear-gradient(45deg, rgba(78 , 163, 183), rgba(183, 78, 98))"

About

a tiny library that converts string to color

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published