npm.io
1.0.3 • Published 5 years ago

html-color-tools

Licence
MIT
Version
1.0.3
Deps
0
Size
10 kB
Vulns
0
Weekly
0

html-color-tools

Tools for working with HTML colors.

Use

Functions

isValidHexColorCode(str)Boolean

Determine if given input is a valid hex color code

lightenDarkenColor(color, percent)String

Programmatically lighten or darken a color

from http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color

contrastingColor(bgColor, threshold, invert)String

Determines if a foreground color should be black or white depending on the given contrasting background color

colorBrightness(hex)Number

Determines the brightness level of a color

from https://www.w3.org/TR/AERT#color-contrast

hexToRGB(hex, alpha)Object

Convert a hex color to RGB

hex3ToHex6(hex3, addHash)String

Converts a 3 digit hex color (e.g., #FFF) and returns its 6 digit equivlent (e.g., #FFFFFF)

isValidHexColorCode(str) ⇒ Boolean

Determine if given input is a valid hex color code

Kind: global function Returns: Boolean - if input is a valid hex color code

Param Type Description
str String user input

lightenDarkenColor(color, percent) ⇒ String

Programmatically lighten or darken a color

from http://stackoverflow.com/questions/5560248/programmatically-lighten-or-darken-a-hex-color

Kind: global function Returns: String - lightened or darkened color

Param Type Description
color String hex color
percent Number percent to lighten or darken by.

contrastingColor(bgColor, threshold, invert) ⇒ String

Determines if a foreground color should be black or white depending on the given contrasting background color

Kind: global function Returns: String - #000000 or #FFFFFF

Param Type Description
bgColor String The color of the background
threshold Number Brightness threshold (e..g, 186)
invert Boolean Apply the change if the color's brightness is below the threshold instead of above

colorBrightness(hex) ⇒ Number

Determines the brightness level of a color

from https://www.w3.org/TR/AERT#color-contrast

Kind: global function Returns: Number - brightness value

Param Type Description
hex String hex color code

hexToRGB(hex, alpha) ⇒ Object

Convert a hex color to RGB

Kind: global function Returns: Object - An object with r, g, and b values (optionally a if alpha is true)

Param Type Description
hex String Hex color code
alpha Boolean Include alpha

hex3ToHex6(hex3, addHash) ⇒ String

Converts a 3 digit hex color (e.g., #FFF) and returns its 6 digit equivlent (e.g., #FFFFFF)

Kind: global function Returns: String - 6 digit hex color code

Param Type Description
hex3 String 3 digit hex color code
addHash Boolean Prepends # to the output

License

The MIT License (MIT)

Copyright (c) 2019 Eric Lewin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.