Members
(static, constant) COLOR_MODELS
gets an array of color models.
Example
import {COLOR_MODELS} from "@daybrush/utils";
console.log(COLOR_MODELS); // ["rgb", "rgba", "hsl", "hsla"];
(static, constant) HSL
get string "hsl"
Example
import {HSL} from "@daybrush/utils";
console.log(HSL); // "hsl"
(static, constant) HSLA
get string "hsla"
Example
import {HSLA} from "@daybrush/utils";
console.log(HSLA); // "hsla"
(static, constant) RGB
get string "rgb"
Example
import {RGB} from "@daybrush/utils";
console.log(RGB); // "rgb"
(static, constant) RGBA
get string "rgba"
Example
import {RGBA} from "@daybrush/utils";
console.log(RGBA); // "rgba"
Methods
(static) cutHex(hex)
Remove the # from the hex color.
Name | Type | Description |
---|---|---|
hex |
string | hex color |
Example
import {cutHex} from "@daybrush/utils";
console.log(cutHex("#000000")) // "000000"
Returns:
hex color
(static) hexToRGBA(hex) → {[number, number, number, number]}
convert hex color to rgb color.
Name | Type | Description |
---|---|---|
hex |
string | hex color |
Example
import {hexToRGBA} from "@daybrush/utils";
console.log(hexToRGBA("#00000005"));
// [0, 0, 0, 1]
console.log(hexToRGBA("#201045"));
// [32, 16, 69, 1]
Returns:
rgb color
- Type
- [number, number, number, number]
(static) hslToRGBA(hsl) → {[number, number, number, number]}
convert hsl color to rgba color.
Name | Type | Description |
---|---|---|
hsl |
readonly [number, number, number, number?] | hsl color(hue: 0 ~ 360, saturation: 0 ~ 1, lightness: 0 ~ 1, alpha: 0 ~ 1) |
Example
import {hslToRGBA} from "@daybrush/utils";
console.log(hslToRGBA([150, 0.5, 0.4]));
// [51, 153, 102, 1]
Returns:
rgba color
- Type
- [number, number, number, number]
(static) stringToRGBA(color) → {[number, number, number, number]}
convert string to rgba color.
Name | Type | Description |
---|---|---|
color |
string | 3-hex(#000), 4-hex(#0000) 6-hex(#000000), 8-hex(#00000000) or RGB(A), or HSL(A) |
Example
import {stringToRGBA} from "@daybrush/utils";
console.log(stringToRGBA("#000000")); // [0, 0, 0, 1]
console.log(stringToRGBA("rgb(100, 100, 100)")); // [100, 100, 100, 1]
console.log(stringToRGBA("hsl(150, 0.5, 0.4)")); // [51, 153, 102, 1]
Returns:
rgba color
- Type
- [number, number, number, number]
(static) toFullHex(hex) → {string}
convert 3(or 4)-digit hex color to 6(or 8)-digit hex color.
Name | Type | Description |
---|---|---|
hex |
string | 3(or 4)-digit hex color |
Example
import {toFullHex} from "@daybrush/utils";
console.log(toFullHex("#123")); // "#112233"
console.log(toFullHex("#123a")); // "#112233aa"
Returns:
6(or 8)-digit hex color
- Type
- string