-
Notifications
You must be signed in to change notification settings - Fork 5
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
Extends API to support compareTo aliases (===, >, >=, etc...) #73
Comments
I liked the idea of extending the API. We can certainly add them.
Since this library is ported from Java, diverging from it too much will cause confusion. Let me think what we can do about |
Hi! I also think the JS community is already very familiar with the difference between Another point I would like to add: If operator overloading is added to Javascript one day, this will allow the following notations: Big("2.0") == 2 // true
Big("2.0") == Big("2.00") // true
Big("2.0") >= 2 // true
Big("2.0") === 2 // false
Big("2.0") === Big("2.00") // false
Big("2.00") === Big("2.00") // true It won't happen soon though as the proposal will take some time before even being considered for stage 2 (the maintainer seems to be taking a break from TC39). -- and Decimal will be released by then. I also added a new suggestion to the list of alternatives names: equivalent (equiv) which I think represent the |
I think we can add I am not sure with the name though. I think |
First of all, I would like to come back on my previous comment.
As most linter recommend Anyway, first of all, I really like your point on autocompletion and definitely share your point of view on having a method names with clear intentions. Of all the propositions listed so far, I think
Concerning I have a few other names to suggest very similar to
|
I just received another proposal for the naming to mitigate the breaking change on |
Is your feature request related to a problem? Please describe.
Relying on
compareTo
is quite verbose and not very comfortable to read or use in my humble opinion.I think this library will greatly benefit by adding aliases for each comparaison operators.
Describe the solution you'd like
Ideally, I would like to extends the API to support
gt
,gte
,lt
,lte
as aliases ofcompareTo
(for reference: bignumber, big)I would also like to make
equals
less strict by making it an alias for=== 0
and rename the current method tostrictEquals
when scale matterIf the intention is to keep the API closely related to the JAVA implementation, it is also perfectly fine to find a different alternative for the
===
alias. (ex:sameAs
,similar
,equivalent
,eq
, etc...)I'm also considering adding
notEquals
to the listDescribe alternatives you've considered
Create a new
Compare
utilsI'm currently using this util in my own projects to avoid extending the
bigdecimal.js
classThe text was updated successfully, but these errors were encountered: