Members
(static, constant) colorData
传入代表颜色的字符串(包含css合法颜色常量),返回对应的 rgb/rgba/Hex 格式的值
Example
// 传入代表颜色字符串,提取rgb/rgba/hex数值
colorData('darkslategray') => {hex: "#2F4F4F",rgba: "rgb(47,79,79)",_rgb: "47,79,79"}
colorData('#E1FFFF') => {hex: "#E1FFFF",rgba: "rgb(225,255,255)",_rgb: "225,255,255"}
colorData('rgb(72,209,204)') => {rgba: "rgb(72,209,204)", _rgb: "72,209,204", hex: "#48d1cc"}
console.log(colorData('wrongColor')) => null
(static, constant) getRgb
从rgba() 格式颜色重提取rgb数值
Example
// 传入合法的rgba格式字符串,提取rgb数值
getRgb('rgba(221, 160, 221, 0.5)') => '221, 160, 221'
(static, constant) hexToRgb
Hex颜色转rgb格式颜色值
Example
// 传入Hex字符串进行输出
hexToRgb('#614700') => {rgba: "rgb(97,71,0)"}
(static, constant) isHex
判断是否Hex格式颜色值
Example
// 传入rgb / rgba 格式的字符串进行判断
isHex('#ffffff') true
(static, constant) isRgb
判断是否rbg格式颜色值
Example
// 传入rgb / rgba 格式的字符串进行判断
isRgb('rgba(0,0,0,1)') true
isRgb('rgb(0, 0, 0)') true
isRgb('rgb(a, b, c)') false
isRgb('0, 0, 0') false
(static, constant) randomColors
生成不重复一定范围内随机颜色数组
Example
randomColors(10, [147, 39, 39], {r: -8, g: +9, b: -15})
(static, constant) rgbToHex
rgb颜色转Hex格式颜色值
Example
// 传入rgb / rgba 格式的字符串进行输出
rgbToHex('rgba(221,160,221,0.5)') => {hex: "#dda0dd", alpha: 50}