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

[FEATURE]: implement number() cast helper function similar to existing string() function #6178

Open
stefreak opened this issue Jun 13, 2024 · 0 comments

Comments

@stefreak
Copy link
Member

stefreak commented Jun 13, 2024

Feature Request

Allow parsing a string as a number

Background / Motivation

When using output from other actions, or command-line parameter they will be presented as string type

An template expression like this: --flag=${var.x * 2} would then result in the error

Invalid template string (--flag=${var.x * 2}) at path ...: Both terms need to be numbers for * operator (got string and number).

What should the user be able to do?

parse strings as numbers using a template helper function; Example --flag=${number(var.x) * 2}

Why do they want to do this? What problem does it solve?

Makes it easier to write glue code

Suggested Implementation(s)

We can add a helper function similar to the existing string() function, that parses the number.

Open question: What should the function do with floating point and integers that are not base 10?

Workaround

It's possible to (ab)use the jsonDecode helper like so: ${string(jsonDecode("2") * 4)}
This expression will resolve to the number 8.

How important is this feature for you/your team?

🌹 It’s a nice to have, but nice things are nice 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant