UNPKG

@wordpress/components

Version:
25 lines (24 loc) • 958 B
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); // 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]; } exports.parseCSSUnitValue = parseCSSUnitValue; //# sourceMappingURL=unit-values.cjs.map