UNPKG

@wordpress/components

Version:
33 lines (31 loc) 972 B
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)?$/; /** * Parses a number and unit from a value. * * @param toParse Value to parse * * @return The extracted number and unit. */ export function parseCSSUnitValue(toParse) { const value = toParse.trim(); const matched = value.match(UNITED_VALUE_REGEX); if (!matched) { return [undefined, undefined]; } const [, num, unit] = matched; let numParsed = parseFloat(num); numParsed = Number.isNaN(numParsed) ? undefined : numParsed; return [numParsed, unit]; } /** * Combines a value and a unit into a unit value. * * @param value * @param unit * * @return The unit value. */ export function createCSSUnitValue(value, unit) { return `${value}${unit}`; } //# sourceMappingURL=unit-values.js.map