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 Request] comparison and "default" to value #384

Open
QAnders opened this issue Apr 5, 2022 · 1 comment
Open

[Feature Request] comparison and "default" to value #384

QAnders opened this issue Apr 5, 2022 · 1 comment

Comments

@QAnders
Copy link

QAnders commented Apr 5, 2022

Love the module and I want to start with a huge Thank you for your efforts!

I'd love two addons in functionality, the first being to "default" to .value if omitted, meaning if I do this it would compare c1.value === c2.value:

var c1 = currency(2.52).subtract(.01);
var c2 = currency(2.50).add(.01);
c1=== c2; // => true

Another one we frequently use is various comparisons that becomes a bit long and "messy" sometimes because of the .value and that we have to "prepare" the currency objects.
(I am aware of the babel add-on but we'd like to keep our dependency stack as small as possible).

Ideally, I'd like to see something like:

if (currency(1.24).gt(1.23) && currency(1.23).lt(1.24)) {  // Maybe something like `.gteq()` (greater than or equal) and `.lteq()` as well...?
  console.log('1.24 is greater than 1.23 and 1.23 is less than 1.24);
}

if (currency(1.23).eq(1.23)) {
  console.log('1.23 equals 1.23);
}

if (currency(1.24).neq(1.23)) {
  console.log('1.24 does not equal 1.23);
}

Just some thoughts... Love the module either way!!! 🥇

@scurker
Copy link
Owner

scurker commented Apr 11, 2022

@QAnders Thanks for your feedback!

I would normally suggest the babel plugin to do what you're doing, but it looks like you've already looked into that. I've considered trying to utilize some other javascript features to do what you're suggesting but I haven't decided if it would be backwards compatible breaking. This is something I'd like to investigate to see if its possible to natively allow for value comparisons without adding too much size to the library.

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

2 participants