1.0.3 • Published 3 years ago

html-color-tools v1.0.3

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

html-color-tools

Tools for working with HTML colors.

Use

Functions

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

ParamTypeDescription
strStringuser 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

ParamTypeDescription
colorStringhex color
percentNumberpercent 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

ParamTypeDescription
bgColorStringThe color of the background
thresholdNumberBrightness threshold (e..g, 186)
invertBooleanApply 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

ParamTypeDescription
hexStringhex 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)

ParamTypeDescription
hexStringHex color code
alphaBooleanInclude 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

ParamTypeDescription
hex3String3 digit hex color code
addHashBooleanPrepends # 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.

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

5 years ago

1.0.0

5 years ago