-
Notifications
You must be signed in to change notification settings - Fork 3
First go at spec text for Amount #28
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Jordan Harband <ljharb@gmail.com>
We embrace the idea that numbers -- as strings -- are understood as unlimited. Later, we may put down some limitations, probably coming from ECMA 402.
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Also, watch out for NaN and infinity.
Specifying fraction digits can be done with `with`.
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
Also, add some checks for fraction and significant digits.
Unless `significantDigits` or `fractionDigits` is set, we don't need to round. Let's just keep the unrounded mathematical value, and round only if necessary.
Co-authored-by: Jordan Harband <ljharb@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments, only looking at the diff since my last review.
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
Unit should be non-empty and contain only alphanumeric characters, and currency should have exactly three uppercase ASCII characters.
1. If _currency_ is a String, set _O_.[[Currency]] to toUppercase(StringToCodePoints(_unit_)). | ||
1. If _unit_ is a String, then | ||
1. If _unit_ is *""*, throw a *RangeError* exception. | ||
1. If _unit_ contains a non-ASCII-alphanumeric character, throw a *RangeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think "non-ASCII-alphanumeric character" is defined anywhere. I guess it might be fine as a temproray expression for now, but this will need to be replaced with something more rigorous at some point, like a syntax-directed operation.
1. If _unit_ is a String, then | ||
1. If _unit_ is *""*, throw a *RangeError* exception. | ||
1. If _unit_ contains a non-ASCII-alphanumeric character, throw a *RangeError* exception. | ||
1. Set _O_.[[Unit]] to CodePointsToString(toLowercase(StringToCodePoints(_unit_))). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The toLowercase()
usage probably needs a similar Unicode reference as in https://tc39.es/ecma262/#sec-string.prototype.tolowercase. Or could we make this an actual call to String.prototype.toLowerCase()
?
Same applies to currency a few lines below.
1. If the string length of _currency_ is not 3, throw a *RangeError* exception. | ||
1. Let _uppercased_ be CodePointsToString(toUppercase(StringToCodePoints(_currency_))). | ||
1. If _currency_ is not string equal to _uppercased_, throw a *RangeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also calling out for a syntax-directed operation, but as above, that could be added later.
1. If ℝ(_significantDigits_) < 1, throw a *RangeError* exception. | ||
1. If ℝ(_fractionDigits_) is not an integer, throw a *RangeError* exception. | ||
1. If ℝ(_fractionDigits_) < 0, throw a *RangeError* exception. | ||
1. If _currency_ is not *undefined* and _unit_ is not *undefined*, throw a *RangeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to throw if either currency or unit is defined, and O.[[Currency]] or O.[[Unit]] is defined.
They also need to be validated as in the constructor, so it's probably best to define an abstract operation like GetAmountOptions that's used by both the constructor and with()
to parse the options.
intl.emu
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Intl changes should presume keep-trailing-zeros as its baseline. With that, PluralRules should need no changes, but ToIntlMathematicalValue() will need work.
It'll also be necessary to change how/when errors are thrown for missing currency
and unit
values, as that'll no longer be happening in the constructor but during formatting.
Co-authored-by: Eemeli Aro <eemeli@gmail.com>
No description provided.