Skip to content

Commit

Permalink
perf: optimize isValidCSSUnit (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Apr 8, 2024
1 parent 64270d8 commit 8dd8b3a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/format-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,9 @@ export function stringInputToObject(color: string): any {
* (see `matchers` above for definition).
*/
export function isValidCSSUnit(color: string | number): boolean {
return Boolean(matchers.CSS_UNIT.exec(String(color)));
if (typeof color === 'number') {
return !Number.isNaN(color);
}

return matchers.CSS_UNIT.test(color);
}

0 comments on commit 8dd8b3a

Please sign in to comment.