@chayns/colors
Version:
JavaScript utility functions for the calculation of colors for chayns
26 lines (20 loc) • 534 B
JavaScript
import { HEX_REGEX, SHORT_HEX_REGEX } from '../../utils/constants';
import { isString } from '../../utils/is';
export default function normalizeHexString(hex) {
if (!isString(hex)) {
return null;
}
var matches = hex.match(HEX_REGEX);
if (matches) {
return "#".concat(matches[1]);
}
matches = hex.match(SHORT_HEX_REGEX);
if (matches) {
return "#".concat(matches[1]).concat(matches[1]);
}
if (hex === 'gray') {
return '#808080';
}
return null;
}
//# sourceMappingURL=normalizeHexString.js.map