Skip to content

Conversation

@RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Oct 7, 2025

This PR improves the canonicalization of percentage values such that [.1], [.10], [10%] and [10.0%] are all treated as the same value.

Right now we're only focusing on percentages. We can likely do this for all numbers, but I'm a little afraid of places where you can have multiple numbers separated by multiple dots (think SVGs).

Test plan

  1. Added more tests to cover the new cases.
  2. Tested it in a local test project, where you can see the normalization in action.
image

If you have `10.0%` or `10%` they should be the same thing. So we pass
the `10.0` and `10` through `Number` to normalize the value.

We only have to do this for values containing a `.`.
We are only interested in percentages containing a `.`. This way we can
normalize `10.0%` as `10%` by using `Number(value)` and re-attaching the
`%`.

With this, a `10.0%` and `10%` would be considered the same.

The regex in theory could include a leading `[+-]` but that won't have
an effect here, and could be even more confusing when it's being used in
a `calc(…)` expression.
@RobinMalfait RobinMalfait marked this pull request as ready for review October 7, 2025 13:42
@RobinMalfait RobinMalfait requested a review from a team as a code owner October 7, 2025 13:42
@RobinMalfait RobinMalfait enabled auto-merge (squash) October 7, 2025 13:42
@RobinMalfait RobinMalfait merged commit 0c8d881 into main Oct 7, 2025
7 checks passed
@RobinMalfait RobinMalfait deleted the feat/improve-percentage-canonicalization branch October 7, 2025 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants