Tools for working with HTML colors.
- 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
- 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)
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 |
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. |
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 |
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 |
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 |
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 |
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.