@wordpress/components
Version:
UI components for WordPress.
20 lines (19 loc) • 815 B
JavaScript
// packages/components/src/utils/unit-values.ts
const UNITED_VALUE_REGEX = /^([\d.\-+]*)\s*(fr|cm|mm|Q|in|pc|pt|px|em|ex|ch|rem|lh|vw|vh|vmin|vmax|%|cap|ic|rlh|vi|vb|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx|svw|lvw|dvw|svh|lvh|dvh|svi|lvi|dvi|svb|lvb|dvb|svmin|lvmin|dvmin|svmax|lvmax|dvmax|cqw|cqh|cqi|cqb|cqmin|cqmax)?$/;
/**
* Parses a number and unit from a value.
*
* @param toParse Value to parse
*
* @return The extracted number and unit.
*/
function parseCSSUnitValue(toParse) {
const matched = toParse.trim().match(UNITED_VALUE_REGEX);
if (!matched) return [void 0, void 0];
const [, num, unit] = matched;
let numParsed = parseFloat(num);
numParsed = Number.isNaN(numParsed) ? void 0 : numParsed;
return [numParsed, unit];
}
export { parseCSSUnitValue };
//# sourceMappingURL=unit-values.mjs.map