@zag-js/color-picker
Version:
Core logic for the color-picker widget implemented as a state machine
15 lines (14 loc) • 302 B
JavaScript
// src/utils/is-valid-hex.ts
var HEX_REGEX = /^[0-9a-fA-F]{3,8}$/;
function isValidHex(value) {
return HEX_REGEX.test(value);
}
function prefixHex(value) {
if (value.startsWith("#")) return value;
if (isValidHex(value)) return `#${value}`;
return value;
}
export {
isValidHex,
prefixHex
};