Skip to content

Strict checkAndEvaluateMath #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Strict checkAndEvaluateMath #359

wants to merge 7 commits into from

Conversation

floscr
Copy link

@floscr floscr commented Jun 2, 2025

Adds a strict version of checkAndEvaluateMath which is being evaluated by https://github.com/tokens-studio/unit-Calculator/

This will allow users to specify stricter rules on which units they want to mix, in the case of Penpot only rem and px units are allowed as units and to mix with a predefined conversion value.

Besides doing proper unit parsing, it also gets rid of a bunch of wrapped regexes around expr-eval-fork that try to do things like group splitting, removing and putting back of units, etc. Instead a proper parser will be used to evaluate expressions.

There are a bunch of functions in expr-eval that we might want to restore, I've added an example with roundTo here:

export const defaultCalcConfig = {

strict math can be enabled by setting mathOptions in the platform config.

Copy link

changeset-bot bot commented Jun 2, 2025

⚠️ No Changeset found

Latest commit: 6861644

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@floscr floscr force-pushed the strict-math branch 3 times, most recently from 31aa9c0 to bb617ba Compare June 10, 2025 13:56
@floscr floscr marked this pull request as ready for review June 10, 2025 14:47
@floscr floscr requested a review from jorenbroekema June 10, 2025 14: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.

1 participant