代码拉取完成,页面将自动刷新
import _HSLToRGB from './_HSLToRGB'
import toHex from './toHex'
import { REG_RGB, REG_HEX, REG_HSL } from './utils/enum'
/**
* 返回将指定颜色(颜色英文名称、16 进制或者 HSL 色值)转化成 RGB 色值
* ========================================================================
* @method toRGB
* @since 0.4.0
* @param {String} color
* @return {String|Boolean}
*/
const toRGB = (color) => {
let matches = []
let hex
let rgb
let r
let g
let b
if (!color) {
return false
}
if (REG_RGB.test(color)) {
return color
}
if (REG_HSL.test(color)) {
matches = REG_HSL.exec(color)
rgb = _HSLToRGB(
parseInt(matches[1], 10),
parseInt(matches[2], 10),
parseInt(matches[3], 10)
)
r = rgb[0]
g = rgb[1]
b = rgb[2]
} else {
/* istanbul ignore else */
if (!REG_RGB.test(color)) {
hex = toHex(color)
}
matches = REG_HEX.exec(hex)
r = parseInt(matches[1], 16)
g = parseInt(matches[2], 16)
b = parseInt(matches[3], 16)
}
return 'rgb(' + [r, g, b].join(', ') + ')'
}
export default toRGB
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。