This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Review for changes to specification for Unified NumberFormat #8
Closed
Changes from 9 commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
e0ee374
Adding more background and sections to README file
sffc a71c246
Adding section to spec for unit resolution.
sffc 58fcc3e
Adding definitions.
sffc cc2ed3d
Refactoring pattern resolution into its own function that is dependen…
sffc 065139c
Adding measure unit fields and adding abstraction for plural form.
sffc d298c40
Adding plumbing for notation setting; the setting itself is not yet u…
sffc 362d876
Removing redundant infinity ILD String line.
sffc 1ba0d4d
Adding some more information about measure units and notation to README
sffc bb309a7
Adding even more to the README and adding 'narrowSymbol' value to the…
sffc 1e6d964
Responding to @littledan review feedback part 1
sffc d392578
Replying to second round of readme comments.
sffc 89e58d3
Fixing up sec-intl.numberformat-internal-slots with new schema for cu…
sffc ec6a6b7
Replying to spec review comments. Changing references to 'tuple' to …
sffc cf7fc70
Adding business logic for [[SignDisplay]].
sffc 9f8bf32
Adding support for [[Notation]].
sffc bbc793e
Adding reference locales-currencies-tz.html
sffc cfe11cf
Adding definition for IsWellFormedUnitIdentifier
sffc f705c62
Adding link to CLDR #11271
sffc 71769d8
Adding reference to tc39/ecma402#244
sffc 066985a
Rename currencySignDisplay to currencySign
sffc e1f913e
Adding link to TC39 Slides
sffc 7ad6fa8
Fix handling of -0 in spec.
sffc f85c7d8
Generalizing 0 check to encompass -0
sffc 9e2ba29
Changing == to =
sffc c860f79
Fix some typos.
Ms2ger 968c412
Fix mistakes in PartitionNumberPattern().
Ms2ger 1adb1a2
Adding rendered version of numberformat_proposed.html
sffc b73b5df
Merge pull request #14 from Ms2ger/typos
sffc 09de884
Merge pull request #15 from Ms2ger/PartitionNumberPattern
sffc 8d04e26
Re-generating out.html given latest PRs
sffc bc60035
Moving minimumIntegerDigits resolution to FormatNumberToString, allow…
sffc 64356c9
Minor changes related to #2.
sffc d53db9b
Changing name of currencySignDisplay to currencySign. Fixes #6
sffc 925b7ee
Adding special logic for compact notation rounding. Fixes #9
sffc 8afe5dd
Changing field names in accordance with #10. Closes #10
sffc f470b48
Adding explicit list of unit identifiers to spec. Fixes #11
sffc d89c7f7
Migrating build process to npm
sffc cdd7957
Adding diff version for Section 6 changes.
sffc c311507
Moving section 6 and section 11 into subdirectories.
sffc 3c2502e
Adding Section 6 diff. Moving files around. Fixing index.html links.
sffc 3ae2496
Updating sffc -> tc39-transfer links in README.md
sffc e4e0591
Bringing numberformat_current.html in sync with upstream.
sffc 92fbb28
Replying to littledan feedback.
sffc fc7e0d6
Re-generating output html files.
sffc 7e3383a
Changing base 10 logarithm language as discussed. Fixes #20
sffc 2eb124c
Fixing -0 condition. Closes #13
sffc 48f19c9
Splitting long [[LocaleData]] patterns paragraph into four.
sffc 7606464
Updating section 6 with new "core unit identifier" syntax.
sffc 7b94926
Removing word "realm" from SetNumberFormatUnitOptions description.
sffc 94bc4cd
Requested changes to "Properties of Intl.NumberFormat Instances"
sffc f4460b4
Removing [[UnitType]] and removing "measure" from internal field names.
sffc 7bb021d
Re-rendering output HTML.
sffc 2a170a0
Changing camelCase strings to kebab-case. Fixes #22
sffc 02550de
Updates to README file.
sffc abf8368
Adding link to Stage 3 proposal slides.
sffc 36500be
Restoring order of SetNumberFormatDigitOptions property reads. Fixes #27
sffc 1ca951e
Change order of Table 2
FrankYFTang 25fdb96
Merge pull request #30 from FrankYFTang/table2Order
sffc 83e54a5
Changing order in 'Properties of Intl.NumberFormat Instances' to be c…
sffc 4d166b1
Fix link
FrankYFTang 6d5fe54
Address #31, #32, #33, #36
FrankYFTang 4b4a859
Merge pull request #35 from FrankYFTang/patch-1
sffc d27db74
Merge pull request #37 from FrankYFTang/order
sffc 47c3beb
Adding -0 to table in README. Fixes #23
sffc 9026ded
Allow only simple units to be numerators and denominators. Fixes #24.
sffc 81e27b6
Adding table for accounting format. Fixes #34
sffc f97fc72
Fixing another instance of core unit identifier.
sffc e0f9853
Updating spec to use subset of units described in #39.
sffc 578a384
Update README.md
sffc bd9cf5e
Merge pull request #42 from tc39/units-list
sffc ed9a3a0
Merge pull request #43 from tc39/sffc-patch-1
sffc 7a2f99e
Adding volume units and vehicle mileage context.
sffc 277970b
Change example unit to a supported unit
sffc 868e07c
Change unit example to common speed quantity.
sffc be943f4
Add currency sign to accounting example
sffc e774c6e
Merge pull request #52 from tc39/sffc-patch-2
sffc e9fc3c9
Updating unit identifier syntax in README example.
sffc 52ee8f9
Merge pull request #51 from tc39/sffc-patch-1
sffc bd37d0a
Change all kebab case to camel case in numberformat Section 11.
sffc 2142fce
Removing consumption units in Section 6.
sffc 9f77626
Update unit.xml link.
sffc 1673abe
Fix casing in README.
sffc 924908e
Merge pull request #54 from tc39/camelcase
sffc d2a15f5
Removing spec text that entangles style: "unit" with style: "percent".
sffc 85e39f8
Merge pull request #48 from tc39/volume
sffc c8b026f
Fix Record casing.
sffc af8cb80
Changing list to table for IsSanctionedSimpleUnitIdentifier.
sffc 436ed16
Merge pull request #55 from tc39/sffc-patch-1
sffc 578c1d9
Compact rounding for small numbers should retain 2 significant digits.
sffc 2350509
Merge pull request #59 from tc39/compact
sffc cb56ac2
Merge pull request #57 from tc39/percent
sffc 6c68f78
Merge pull request #58 from tc39/cleanup
sffc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,3 +40,6 @@ jspm_packages | |
yarn.lock | ||
package-lock.json | ||
npm-shrinkwrap.json | ||
|
||
|
||
out.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,127 @@ | ||
Intl.NumberFormat Unified API Proposal | ||
====================================== | ||
|
||
## Motivation | ||
## Background / Motivation | ||
|
||
There are many requests for adding number-formatting-related features to ECMA 402. A few of them include: | ||
There are many requests for adding number-formatting-related features to ECMA 402. These include: | ||
|
||
- tc39/ecma402#200 | ||
- tc39/ecma402#186 | ||
- tc39/ecma402#164 | ||
- tc39/ecma402#163 | ||
- tc39/ecma402#95 | ||
- tc39/ecma402#91 | ||
- tc39/ecma402#37 | ||
- tc39/ecma402#32 | ||
- [Expose narrow currency symbol](https://github.com/tc39/ecma402/issues/200) -- Section I | ||
- [Add currency accounting format](https://github.com/tc39/ecma402/issues/186) -- Section IV | ||
- [Add scientific notation](https://github.com/tc39/ecma402/issues/164) -- Section III | ||
- [Add option to force sign](https://github.com/tc39/ecma402/issues/163) -- Section IV | ||
- [Add compact decimal notation](https://github.com/tc39/ecma402/issues/37) -- Section III | ||
- [Add measure unit formatting](https://github.com/tc39/ecma402/issues/32) -- Section II | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Rather than complicate `Intl` with more subclasses with heavilly overlapping functionality, this proposal is to restructure the spec of `Intl.NumberFormat` to make it more easilly support additional features in a "unified" way. | ||
These features are important to both end users and to Google. Since most of these features require carrying along large amounts of locale data for proper i18n support, exposing these features via a JavaScript API reduces bandwidth and lowers the barrier to entry for i18n best practices. | ||
|
||
Rather than complicate `Intl` with more constructors with heavilly overlapping functionality, this proposal is to restructure the spec of `Intl.NumberFormat` to make it more easilly support additional features in a "unified" way. | ||
|
||
Additional background: [Unified API for number formatting](https://github.com/tc39/ecma402/issues/215) | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## I. Spec Cleanup | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Certain sections of the spec have been refactored with the following objectives: | ||
|
||
- Fix https://github.com/tc39/ecma402/issues/238 (currency long name has dependency on plural form, and the currency long name pattern has dependency on currencyWidth). | ||
- Move pattern resolution out of the constructor to keep all internal fields of NumberFormat locale-agnostic, making it easier to reason about behavior in the format method. | ||
|
||
In addition, one missing option is added to the existing `currencyDisplay` setting: "narrowSymbol", which uses the CLDR narrow-format symbol. | ||
|
||
## II. Measure Units | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Units of measurement can be formatted as follows: | ||
|
||
```javascript | ||
(9.81).toLocaleString("en-US", { | ||
style: "unit", | ||
unit: "acceleration-meter-per-second-squared", | ||
unitDisplay: "short" | ||
}); | ||
// ==> "9.81 m/s²" | ||
``` | ||
|
||
The syntax was discussed in #3. | ||
|
||
- `style` receives the string value "unit" | ||
- `unit` receives a string measure unit identifier, defined in [UTS #35](http://unicode.org/reports/tr35/tr35-general.html#Unit_Elements). See also the [full list of unit identifiers](https://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml). | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `unitDisplay`, named after the corresponding setting for currencies, `currencyDisplay`, takes either "narrow", "short", or "long". | ||
|
||
## III. Scientific and Compact Notation | ||
|
||
Scientific and compact notation are represented by the new option `notation` and can be formatted as follows: | ||
|
||
```javascript | ||
(987654321).toLocaleString("en-US", { | ||
notation: "scientific" | ||
}); | ||
// ==> 9.877E8 | ||
|
||
(987654321).toLocaleString("en-US", { | ||
notation: "engineering" | ||
}); | ||
// ==> 987.7E6 | ||
|
||
(987654321).toLocaleString("en-US", { | ||
notation: "compact", | ||
compactDisplay: "long" | ||
}); | ||
// ==> 987.7 million | ||
``` | ||
|
||
The syntax was discussed in #5. | ||
|
||
- `notation` takes either "scientific", "engineering", "compact", or "plain" | ||
- `compactDisplay`, used only when `notation` is "compact", takes either "short" or "long" | ||
|
||
Rounding-related settings (min/max integer/fraction digits) are applied after the number is scaled according to the chosen notation. | ||
|
||
Notation styles are allowed to be combined with other options. (ICU supports this.) | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript | ||
(299792458).toLocaleString("en-US", { | ||
notation: "scientific", | ||
minimumFractionDigits: 2, | ||
maximumFractionDigits: 2, | ||
style: "unit", | ||
unit: "speed-meter-per-second" | ||
}); | ||
// ==> 3.00E8 m/s | ||
``` | ||
|
||
## IV. Sign Display | ||
|
||
The sign can be displayed on positive numbers: | ||
|
||
```javascript | ||
(55).toLocaleString("en-US", { | ||
signDisplay: "always" | ||
}); | ||
// ==> +55 | ||
``` | ||
|
||
Currency accounting sign display is also supported via a new option: | ||
|
||
```javascript | ||
(-55).toLocaleString("en-US", { | ||
style: "currency", | ||
currency: "USD", | ||
currencySignDisplay: "accounting" | ||
}); | ||
// ==> ($55.00) | ||
``` | ||
|
||
The syntax was discussed in #6. | ||
|
||
- `signDisplay` takes either "auto", "always", "never", or "except-zero" | ||
- `currencySignDisplay` takes either "standard" or "accounting" | ||
sffc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
As usual, this may be combined with other options. | ||
|
||
```javascript | ||
(0.55).toLocaleString("en-US", { | ||
style: "percent", | ||
signDisplay: "except-zero" | ||
}); | ||
// ==> +55% | ||
``` | ||
|
||
Background: tc39/ecma402#215 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For background, write "ECMA-402 (the JavaScript Intl standard library)" to make this more self-contained.
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.
Done.