Skip to content

pantoken-root / design/swatches/src / hexToRgb

函数: hexToRgb() ​

hexToRgb(hex): Rgb | undefined

实验性

将 #rgb/#rrggbb/#rrggbbaa 解析为 0–255 通道,或在不是十六进制颜色时解析为 undefined。

参数 ​

hex ​

string

返回值 ​

Rgb | undefined

示例 ​

ts
import { hexToRgb } from "@pantoken/swatches";

hexToRgb("#ff8800"); // { r: 255, g: 136, b: 0 }
hexToRgb("nope"); // undefined