Skip to content
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

feat(util): expose calc() expression API #2749

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

kumilingus
Copy link
Contributor

@kumilingus kumilingus commented Aug 31, 2024

Description

Add isCalcExpression, evalCalcExpression and evalCalcFormula functions to utilities.

Documentation

isCalcExpression()

isCalcExpression(value: any) => boolean

Check if the given value is a calc() expression.
e.g. "calc(w + 100)" is true and "not a formula" is false.

evalCalcExpression()

evalCalcExpression(expression: string, rect: g.PlainRect) => string;

Evaluate all calc() formulas in the given expression.
e.g. "translate(calc(w + 10), 0)" in a rect 100x100 will produce a string '"translate(110, 0)"'.

evalCalcFormula()

evalCalcFormula(formula: string, rect: g.PlainRect) => number;

Evaluate the given calc() formula.
e.g w + 10 in context of a rectangle 100x100 will produce a number 110.

@Geliogabalus Geliogabalus merged commit f842946 into clientIO:master Sep 2, 2024
3 checks passed
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.

2 participants