Skip to content

Commit

Permalink
Refactor length function to utilize a pre-compiled RegExp (#12251)
Browse files Browse the repository at this point in the history
* Refactor length function to utilize a pre-compiled RegExp

* Update dataTypes.js
  • Loading branch information
marco-carvalho committed Oct 20, 2023
1 parent 4e1a26a commit bcfb38d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/util/dataTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,9 @@ let lengthUnits = [
'cqmax',
]
let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
let lengthRegExp = new RegExp(`^[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`)
export function length(value) {
return (
value === '0' ||
new RegExp(`^[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`).test(value) ||
isCSSFunction(value)
)
return value === '0' || lengthRegExp.test(value) || isCSSFunction(value)
}

let lineWidths = new Set(['thin', 'medium', 'thick'])
Expand Down

0 comments on commit bcfb38d

Please sign in to comment.