Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

allow simple arithmetic in slider input field #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jakobhellermann
Copy link

implements a simple form of modrinth/code#720

2023-12-29.00-32-54.mp4

This only allows simple math in the form of 50+2, no multiple operators, parenthesis, or "8gb + 10mb" symbols, but I wanted to open this PR first to check if there's even interest in merging this.


ChatGPT suggested this alternative implementation which would implement parenthesis etc. nicely but I don't know if that's worth the use of the dubious eval function.

let sanitizedExpression = expression.replace(/[^0-9+\-*/().]/g, ''); // Sanitize input
let result = eval(sanitizedExpression); // Use eval on sanitized input

@Prospector
Copy link
Member

I would definitely not use eval, that sounds like a really bad idea.

Copy link
Member

@Prospector Prospector left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a really cool feature though!

@Minenash
Copy link

Minenash commented Dec 29, 2023

I think this is nice for when trying to do it in gigs, but don't want to do the math. And it would be nice to have just general gb mb terms in general (ik this isn't in the PR yet)

Though, I think the main problem with the idea is discverability

@Prospector
Copy link
Member

Discoverability isn't really a concern with shortcut features like this, they're things people can use if they learn about them and if they dont, it's no big deal because they can still do the math themselves and type the number in.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants