Skip to content

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

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open

Conversation

jessealama
Copy link
Collaborator

No description provided.

jessealama and others added 10 commits June 18, 2025 18:13
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>
jessealama and others added 14 commits July 2, 2025 19:21
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>
Copy link
Member

@eemeli eemeli left a 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.

jessealama and others added 6 commits July 4, 2025 10:17
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.
@jessealama jessealama requested a review from eemeli July 10, 2025 08:40
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.
Copy link
Member

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_))).
Copy link
Member

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.

Comment on lines +300 to +302
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.
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants