All Projects β†’ noeldelgado β†’ Values.js

noeldelgado / Values.js

Licence: mit
πŸ‡ Get the tints and shades of a color

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Values.js

Gradstop
JavaScript micro library to generate gradient color stops πŸ³οΈβ€πŸŒˆ
Stars: ✭ 144 (+48.45%)
Mutual labels:  hex, rgb, hsl, colors
colors-convert
🦚 A simple colors library
Stars: ✭ 15 (-84.54%)
Mutual labels:  hex, colors, hsl, rgb
Farge
🎈Tell the name of hex color
Stars: ✭ 23 (-76.29%)
Mutual labels:  hex, color, hsl, rgb
colorsys.rs
Lib for modifying colors and converting to other spaces
Stars: ✭ 28 (-71.13%)
Mutual labels:  hex, color, hsl, rgb
React Color Extractor
A React component which extracts colors from an image
Stars: ✭ 314 (+223.71%)
Mutual labels:  hex, rgb, hsl, colors
khroma
A collection of functions for manipulating CSS colors, inspired by SASS.
Stars: ✭ 28 (-71.13%)
Mutual labels:  hex, color, hsl, rgb
color
A library of well-tested helper methods for working with colors.
Stars: ✭ 13 (-86.6%)
Mutual labels:  hex, color, hsl, rgb
Culori
A comprehensive color library for JavaScript.
Stars: ✭ 271 (+179.38%)
Mutual labels:  hex, rgb, hsl, color
ColorHelper
No description or website provided.
Stars: ✭ 34 (-64.95%)
Mutual labels:  hex, color, hsl, rgb
Colorhighlight
🎨 Lightweight Color Highlight colorizer for Sublime Text
Stars: ✭ 76 (-21.65%)
Mutual labels:  hex, rgb, hsl, color
Colorpicker
A mininal but complete colorpicker desktop app
Stars: ✭ 766 (+689.69%)
Mutual labels:  hex, rgb, color
Sorted Colors
A tool to sort the named CSS colors in a way that it shows related colors together
Stars: ✭ 167 (+72.16%)
Mutual labels:  rgb, hsl, colors
global-color-picker
start the script and click anywhere to get rgb value at the cursor location
Stars: ✭ 31 (-68.04%)
Mutual labels:  color, colors, rgb
ColorMinePortable
ColorMinePortable
Stars: ✭ 37 (-61.86%)
Mutual labels:  hex, hsl, rgb
colorsys
🎨 Minimalistic color converter for RGB, HSV, HSL, CMYK, HEX and CSS strings
Stars: ✭ 53 (-45.36%)
Mutual labels:  hex, color, rgb
color
Standard representation of colors, encouraging sharing between packages.
Stars: ✭ 23 (-76.29%)
Mutual labels:  color, hsl, rgb
go-rainbow
Golang Helper for beautiful CLI Applications
Stars: ✭ 86 (-11.34%)
Mutual labels:  hex, colors, rgb
hex-to-css-filter
Easy way to generate colors from HEX to CSS Filters
Stars: ✭ 20 (-79.38%)
Mutual labels:  hex, color, rgb
Color.js
Extract colors from an image (0.75 KB) 🎨
Stars: ✭ 42 (-56.7%)
Mutual labels:  rgb, color, colors
ColorPicker
Customizable Color Picker control for WPF
Stars: ✭ 57 (-41.24%)
Mutual labels:  colors, hsl, rgb

values.js

NPM Version Minzipped size License codecov Known Vulnerabilities Dependencies Dev Dependencies Total alerts Language grade: JavaScript

Get tints and shades of a CSS color

The lightness or darkness of a color is called its value. Tints are light values that are made by mixing a color with white, which increases lightness. Shades are dark values that are made by mixing a color with black, which reduces lightness.

https://noeldelgado.github.io/values.js/

Supports

  • <color value>
    • Hexadecimal RGB value: #RGB #RRGGBB
    • #RGBA #RRGGBBAA (4 and 8-digit hexadecimal RGBA notation)
    • RGB/A - CSS Color Module Level 3 and 4 (number, percentage)
    • HSL/A - CSS Color Module Level 3 and 4 (number, deg, rad, turn)
  • <color keyword>
  • transparent
    • Shorthand for transparent black, rgba(0,0,0,0).

Installation

NPM

npm install values.js --save

Or as a <script> tag from a CDN as Values:

Unpkg CDN

<script src="https://unpkg.com/values.js"></script>

jsDelivr CDN

<script src="https://cdn.jsdelivr.net/npm/values.js"></script>

Usage

import Values from 'values.js'
const color = new Values('hsl(204deg 100% 50% / 1)'), { log } = console

log(color.tint(25))
//> { rgb: [64, 179, 255], alpha: 1, type: "tint", weight: 25, ...methods }
log(color.shade(12))
//> { rgb: [0, 135, 224], alpha: 1, type: "shade", weight: 12, ...methods }
log(color.tints(8))
//> (12) [Values...]
log(color.shades(23))
//> (4) [Values...]
log(color.all(20))
//> (11) [Values...]

// instance example for 'red'
Values {
  alpha: 1
  rgb: (3) [255, 0, 0]
  type: "base"
  weight: 0
  get hex: Ζ’(...)
  setColor: Ζ’ setColor(color)
  tint: Ζ’ tint(weight=50)
  tints: Ζ’ tints(weight=10)
  shade: Ζ’ shade(weight=50)
  shades: Ζ’ shades(weight=10)
  all: Ζ’ all(weight=10)
  hexString: Ζ’ hexString()
  rgbString: Ζ’ rgbString()
  getBrightness: Ζ’ getBrightness()
}

See tests for more cases.

API

constructor(color)

Throws if the color is not accepted.

  • @param {string} color β€” a valid CSS color string

setColor(color)

Sets a new base color, returns null if color has not been accepted.

  • @param {string} color - a valid CSS color string
  • @return {Values|null}

tint([weight=50])

Lightens the base color by mixing it with white as specified by weight.

  • @param {number} [weight=50]
  • @return {Values}

shade([weight=50)

Darkens the base color by mixing it with black as specified by weight.

  • @param {number} [weight=50]
  • @return {Values}

tints([weight=10])

Generates the tints of the base color as specified by weight.

  • @param {number} [weight=10]
  • @return {Array<Values>}

shades([percentage=10])

Generates the shades of the base color as specified by weight.

  • @param {number} [weight=10]
  • @return {Array<Values>}

all([weight=10])

Generates the tints and shades of the base color as specified by weight.

  • @param {number} [weight=10]
  • @return {Array<Values>}

hexString()

Returns the color in hexadecimal RGB notation.

  • @returns {string} @example #000000 or #00000080

rgbString()

Returns the color in rgb() functional notation.

  • @returns {string} @example rgb(0, 0, 0) or rgba(0, 0, 0, 0.5)

getBrightness()

Calculates the brightness of the color.

  • @return {number} β€” the base-color brightness.

Dev

npm install 	# install dev-dependencies
npm test		# run the tests
npm run dev 	# watch for changes and run tests

Related

  • shadowlord - Tints and shades generator tool
  • mix-css-color - Mix two CSS colors together in variable proportion. Opacity is included in the calculations.
  • parse-css-color - Parse a CSS color string

License

MIT Β© Noel Delgado

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].