flow like the river

This commit is contained in:
root 2025-11-07 00:06:12 +01:00
commit 013fe673f3
42435 changed files with 5764238 additions and 0 deletions

View file

@ -0,0 +1,28 @@
// @flow
const cssRegex = /^([+-]?(?:\d+|\d*\.\d+))([a-z]*|%)$/
/**
* Returns a given CSS value minus its unit of measure.
*
* @example
* // Styles as object usage
* const styles = {
* '--dimension': stripUnit('100px')
* }
*
* // styled-components usage
* const div = styled.div`
* --dimension: ${stripUnit('100px')};
* `
*
* // CSS in JS Output
*
* element {
* '--dimension': 100
* }
*/
export default function stripUnit(value: string | number): string | number {
if (typeof value !== 'string') return value
const matchedValue = value.match(cssRegex)
return matchedValue ? parseFloat(value) : value
}