Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Review for changes to specification for Unified NumberFormat #8

Closed
wants to merge 92 commits into from
Closed
Show file tree
Hide file tree
Changes from 41 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 Jun 12, 2018
a71c246
Adding section to spec for unit resolution.
sffc Jun 12, 2018
58fcc3e
Adding definitions.
sffc Jun 12, 2018
cc2ed3d
Refactoring pattern resolution into its own function that is dependen…
sffc Jun 13, 2018
065139c
Adding measure unit fields and adding abstraction for plural form.
sffc Jun 13, 2018
d298c40
Adding plumbing for notation setting; the setting itself is not yet u…
sffc Jun 13, 2018
362d876
Removing redundant infinity ILD String line.
sffc Jun 13, 2018
1ba0d4d
Adding some more information about measure units and notation to README
sffc Jun 14, 2018
bb309a7
Adding even more to the README and adding 'narrowSymbol' value to the…
sffc Jun 16, 2018
1e6d964
Responding to @littledan review feedback part 1
sffc Jul 12, 2018
d392578
Replying to second round of readme comments.
sffc Jul 17, 2018
89e58d3
Fixing up sec-intl.numberformat-internal-slots with new schema for cu…
sffc Jul 17, 2018
ec6a6b7
Replying to spec review comments. Changing references to 'tuple' to …
sffc Jul 17, 2018
cf7fc70
Adding business logic for [[SignDisplay]].
sffc Jul 17, 2018
9f8bf32
Adding support for [[Notation]].
sffc Jul 17, 2018
bbc793e
Adding reference locales-currencies-tz.html
sffc Jul 17, 2018
cfe11cf
Adding definition for IsWellFormedUnitIdentifier
sffc Jul 17, 2018
f705c62
Adding link to CLDR #11271
sffc Jul 17, 2018
71769d8
Adding reference to tc39/ecma402#244
sffc Jul 18, 2018
066985a
Rename currencySignDisplay to currencySign
sffc Jul 24, 2018
e1f913e
Adding link to TC39 Slides
sffc Jul 24, 2018
7ad6fa8
Fix handling of -0 in spec.
sffc Jul 30, 2018
f85c7d8
Generalizing 0 check to encompass -0
sffc Jul 30, 2018
9e2ba29
Changing == to =
sffc Jul 30, 2018
c860f79
Fix some typos.
Ms2ger Aug 31, 2018
968c412
Fix mistakes in PartitionNumberPattern().
Ms2ger Aug 31, 2018
1adb1a2
Adding rendered version of numberformat_proposed.html
sffc Sep 5, 2018
b73b5df
Merge pull request #14 from Ms2ger/typos
sffc Oct 24, 2018
09de884
Merge pull request #15 from Ms2ger/PartitionNumberPattern
sffc Oct 24, 2018
8d04e26
Re-generating out.html given latest PRs
sffc Oct 24, 2018
bc60035
Moving minimumIntegerDigits resolution to FormatNumberToString, allow…
sffc Oct 24, 2018
64356c9
Minor changes related to #2.
sffc Oct 24, 2018
d53db9b
Changing name of currencySignDisplay to currencySign. Fixes #6
sffc Oct 24, 2018
925b7ee
Adding special logic for compact notation rounding. Fixes #9
sffc Oct 24, 2018
8afe5dd
Changing field names in accordance with #10. Closes #10
sffc Oct 24, 2018
f470b48
Adding explicit list of unit identifiers to spec. Fixes #11
sffc Oct 24, 2018
d89c7f7
Migrating build process to npm
sffc Oct 24, 2018
cdd7957
Adding diff version for Section 6 changes.
sffc Oct 30, 2018
c311507
Moving section 6 and section 11 into subdirectories.
sffc Oct 30, 2018
3c2502e
Adding Section 6 diff. Moving files around. Fixing index.html links.
sffc Oct 30, 2018
3ae2496
Updating sffc -> tc39-transfer links in README.md
sffc Oct 30, 2018
e4e0591
Bringing numberformat_current.html in sync with upstream.
sffc Nov 2, 2018
92fbb28
Replying to littledan feedback.
sffc Nov 2, 2018
fc7e0d6
Re-generating output html files.
sffc Nov 2, 2018
7e3383a
Changing base 10 logarithm language as discussed. Fixes #20
sffc Nov 2, 2018
2eb124c
Fixing -0 condition. Closes #13
sffc Nov 2, 2018
48f19c9
Splitting long [[LocaleData]] patterns paragraph into four.
sffc Nov 15, 2018
7606464
Updating section 6 with new "core unit identifier" syntax.
sffc Nov 15, 2018
7b94926
Removing word "realm" from SetNumberFormatUnitOptions description.
sffc Nov 15, 2018
94bc4cd
Requested changes to "Properties of Intl.NumberFormat Instances"
sffc Nov 15, 2018
f4460b4
Removing [[UnitType]] and removing "measure" from internal field names.
sffc Nov 15, 2018
7bb021d
Re-rendering output HTML.
sffc Nov 15, 2018
2a170a0
Changing camelCase strings to kebab-case. Fixes #22
sffc Nov 27, 2018
02550de
Updates to README file.
sffc Nov 27, 2018
abf8368
Adding link to Stage 3 proposal slides.
sffc Nov 27, 2018
36500be
Restoring order of SetNumberFormatDigitOptions property reads. Fixes #27
sffc Nov 29, 2018
1ca951e
Change order of Table 2
FrankYFTang Dec 11, 2018
25fdb96
Merge pull request #30 from FrankYFTang/table2Order
sffc Dec 12, 2018
83e54a5
Changing order in 'Properties of Intl.NumberFormat Instances' to be c…
sffc Dec 12, 2018
4d166b1
Fix link
FrankYFTang Jan 12, 2019
6d5fe54
Address #31, #32, #33, #36
FrankYFTang Jan 13, 2019
4b4a859
Merge pull request #35 from FrankYFTang/patch-1
sffc Jan 14, 2019
d27db74
Merge pull request #37 from FrankYFTang/order
sffc Feb 27, 2019
47c3beb
Adding -0 to table in README. Fixes #23
sffc Feb 27, 2019
9026ded
Allow only simple units to be numerators and denominators. Fixes #24.
sffc Feb 27, 2019
81e27b6
Adding table for accounting format. Fixes #34
sffc Feb 27, 2019
f97fc72
Fixing another instance of core unit identifier.
sffc Feb 27, 2019
e0f9853
Updating spec to use subset of units described in #39.
sffc May 10, 2019
578a384
Update README.md
sffc May 14, 2019
bd9cf5e
Merge pull request #42 from tc39/units-list
sffc May 14, 2019
ed9a3a0
Merge pull request #43 from tc39/sffc-patch-1
sffc May 17, 2019
7a2f99e
Adding volume units and vehicle mileage context.
sffc Jul 8, 2019
277970b
Change example unit to a supported unit
sffc Jul 10, 2019
868e07c
Change unit example to common speed quantity.
sffc Jul 11, 2019
be943f4
Add currency sign to accounting example
sffc Jul 11, 2019
e774c6e
Merge pull request #52 from tc39/sffc-patch-2
sffc Jul 12, 2019
e9fc3c9
Updating unit identifier syntax in README example.
sffc Jul 12, 2019
52ee8f9
Merge pull request #51 from tc39/sffc-patch-1
sffc Jul 15, 2019
bd37d0a
Change all kebab case to camel case in numberformat Section 11.
sffc Jul 15, 2019
2142fce
Removing consumption units in Section 6.
sffc Jul 15, 2019
9f77626
Update unit.xml link.
sffc Jul 15, 2019
1673abe
Fix casing in README.
sffc Jul 15, 2019
924908e
Merge pull request #54 from tc39/camelcase
sffc Jul 15, 2019
d2a15f5
Removing spec text that entangles style: "unit" with style: "percent".
sffc Jul 15, 2019
85e39f8
Merge pull request #48 from tc39/volume
sffc Jul 15, 2019
c8b026f
Fix Record casing.
sffc Jul 15, 2019
af8cb80
Changing list to table for IsSanctionedSimpleUnitIdentifier.
sffc Jul 15, 2019
436ed16
Merge pull request #55 from tc39/sffc-patch-1
sffc Jul 16, 2019
578c1d9
Compact rounding for small numbers should retain 2 significant digits.
sffc Jul 16, 2019
2350509
Merge pull request #59 from tc39/compact
sffc Jul 16, 2019
cb56ac2
Merge pull request #57 from tc39/percent
sffc Jul 16, 2019
6c68f78
Merge pull request #58 from tc39/cleanup
sffc Jul 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ jspm_packages
yarn.lock
package-lock.json
npm-shrinkwrap.json


out.html
161 changes: 149 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,156 @@
Intl.NumberFormat Unified API Proposal
======================================

## Motivation
[TC39 Stage 2 Proposal](https://docs.google.com/presentation/d/1_1D15PWniTlbLu1BOU9aDf5H87Ecq85i0CuLl5KA4DE/edit?usp=sharing)

There are many requests for adding number-formatting-related features to ECMA 402. A few of them include:
[View Spec](https://tc39-transfer.github.io/proposal-unified-intl-numberformat/)

- tc39/ecma402#200
- tc39/ecma402#186
- tc39/ecma402#164
- tc39/ecma402#163
- tc39/ecma402#95
- tc39/ecma402#91
- tc39/ecma402#37
- tc39/ecma402#32
## Background / Motivation

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.
There are many requests for adding number-formatting-related features to ECMA-402 (the JavaScript Intl standard library). These include:

- [Expose narrow currency symbol](https://github.com/tc39/ecma402/issues/200) -- Section I
- [Clarification on behavior of SetNumberFormatDigitOptions](https://github.com/tc39/ecma402/issues/244) -- Section I
- [Add measure unit formatting](https://github.com/tc39/ecma402/issues/32) -- Section II
- [Add compact decimal notation](https://github.com/tc39/ecma402/issues/37) -- Section III
- [Add scientific notation](https://github.com/tc39/ecma402/issues/164) -- Section III
- [Add currency accounting format](https://github.com/tc39/ecma402/issues/186) -- Section IV
- [Add option to force sign](https://github.com/tc39/ecma402/issues/163) -- Section IV

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: [prior discussion](https://github.com/tc39/ecma402/issues/215)

## 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.
- Fix https://github.com/tc39-transfer/proposal-unified-intl-numberformat/issues/2, to allow minimumIntegerDigits to control integer digit count when significant digits are used.

In addition, one missing option is added to the existing `currencyDisplay` setting: "narrowSymbol", which uses the CLDR narrow-format symbol:

```javascript
(100).toLocaleString("en-CA", {
style: "currency",
currency: "USD",
currencyDisplay: "narrowSymbol"
});
// ==> "$100" (rather than "US$100")
```

## II. Units

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 measurement unit identifier, defined in [UTS #35, Part 2, Section 6](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).
- Note: currently this is restricted to single units as listed in the CLDR specification. If there is sufficient demand, a future proposal could add ways to combine units, such as compound units. Note that certain compound units, such as "meters per second", are already available as standalone units in CLDR.
- Also relecant [CLDR #11271](https://unicode.org/cldr/trac/ticket/11271) about fleshing out some details on unit identifiers in the spec.
- `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:

```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. In many locales, accounting format means to wrap the number with parentheses instead of
appending a minus sign. For example:

```javascript
(-100).toLocaleString("bn", {
style: "currency",
currency: "EUR",
currencySign: "accounting"
});
// ==> (১০০.০০€)
sffc marked this conversation as resolved.
Show resolved Hide resolved
```

The syntax was discussed in #6:

- `signDisplay`: "auto" (default), "always", "never", "except-zero"
- See examples below.
- `currencySign`: "standard" (default), "accounting"
- "accounting" enables the accounting format on currency values, as shown in the example above. "standard", the default value, disables accounting formats.

Examples of signDisplay choices with Latin digits:

signDisplay | -1 | 0 | 1
----------- | --- | --- | ---
auto | -1 | 0 | 1
always | -1 | +0 | +1
never | 1 | 0 | 1
except-zero | -1 | 0 | +1

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
Loading