@formatjs/intl-pluralrules 1.4.2 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,47 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.5.2](https://github.com/formatjs/formatjs/compare/@formatjs/intl-pluralrules@1.5.1...@formatjs/intl-pluralrules@1.5.2) (2020-01-27)
7
+
8
+ **Note:** Version bump only for package @formatjs/intl-pluralrules
9
+
10
+
11
+
12
+
13
+
14
+ ## [1.5.1](https://github.com/formatjs/formatjs/compare/@formatjs/intl-pluralrules@1.5.0...@formatjs/intl-pluralrules@1.5.1) (2020-01-22)
15
+
16
+ **Note:** Version bump only for package @formatjs/intl-pluralrules
17
+
18
+
19
+
20
+
21
+
22
+ # [1.5.0](https://github.com/formatjs/formatjs/compare/@formatjs/intl-pluralrules@1.4.3...@formatjs/intl-pluralrules@1.5.0) (2020-01-09)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **@formatjs/intl-pluralrules:** tweak polyfill checks ([8daea9b](https://github.com/formatjs/formatjs/commit/8daea9b615be1b215085174a188e908f60b8a05e))
28
+ * **@formatjs/intl-utils:** fix setNumberFormatDigitOptions ([cb21c1f](https://github.com/formatjs/formatjs/commit/cb21c1f7abcb32040ffc5108c37734e2fd43c117))
29
+
30
+
31
+ ### Features
32
+
33
+ * **@formatjs/intl-pluralrules:** also polyfill env where it doesn’t take in minimumFractionDigits ([7ab043a](https://github.com/formatjs/formatjs/commit/7ab043a58c33b52992ac179d70e195c2026940b0))
34
+
35
+
36
+
37
+
38
+
39
+ ## [1.4.3](https://github.com/formatjs/formatjs/compare/@formatjs/intl-pluralrules@1.4.2...@formatjs/intl-pluralrules@1.4.3) (2020-01-08)
40
+
41
+ **Note:** Version bump only for package @formatjs/intl-pluralrules
42
+
43
+
44
+
45
+
46
+
6
47
  ## [1.4.2](https://github.com/formatjs/formatjs/compare/@formatjs/intl-pluralrules@1.4.1...@formatjs/intl-pluralrules@1.4.2) (2020-01-06)
7
48
 
8
49
 
package/dist/core.js CHANGED
@@ -83,7 +83,7 @@ var PluralRules = /** @class */ (function () {
83
83
  var matcher = intl_utils_1.getOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
84
84
  opt.localeMatcher = matcher;
85
85
  intl_utils_1.setInternalSlot(PluralRules.__INTERNAL_SLOT_MAP__, this, 'type', intl_utils_1.getOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal'));
86
- intl_utils_1.setNumberFormatDigitOptions(PluralRules.__INTERNAL_SLOT_MAP__, this, opts, 0, 3, 'standard');
86
+ intl_utils_1.setNumberFormatDigitOptions(PluralRules.__INTERNAL_SLOT_MAP__, this, opts, 0, 3);
87
87
  var r = intl_utils_1.createResolveLocale(PluralRules.getDefaultLocale)(PluralRules.availableLocales, requestedLocales, opt, PluralRules.relevantExtensionKeys, PluralRules.localeData);
88
88
  intl_utils_1.setInternalSlot(PluralRules.__INTERNAL_SLOT_MAP__, this, 'locale', r.locale);
89
89
  }
@@ -20,6 +20,16 @@
20
20
  }
21
21
  return Object(arg);
22
22
  }
23
+ /**
24
+ * https://tc39.es/ecma262/#sec-tostring
25
+ */
26
+ function toString(o) {
27
+ // Only symbol is irregular...
28
+ if (typeof o === 'symbol') {
29
+ throw TypeError('Cannot convert a Symbol value to a string');
30
+ }
31
+ return String(o);
32
+ }
23
33
  /**
24
34
  * https://tc39.es/ecma402/#sec-getoption
25
35
  * @param opts
@@ -39,10 +49,10 @@
39
49
  value = Boolean(value);
40
50
  }
41
51
  if (type === 'string') {
42
- value = String(value);
52
+ value = toString(value);
43
53
  }
44
54
  if (values !== undefined && !values.filter(function (val) { return val == value; }).length) {
45
- throw new RangeError(value + " in not within " + values);
55
+ throw new RangeError(value + " is not within " + values.join(', '));
46
56
  }
47
57
  return value;
48
58
  }
@@ -104,40 +114,40 @@
104
114
  /**
105
115
  * https://tc39.es/ecma402/#sec-setnfdigitoptions
106
116
  * https://tc39.es/proposal-unified-intl-numberformat/section11/numberformat_diff_out.html#sec-setnfdigitoptions
107
- * @param pl
117
+ * @param intlObj
108
118
  * @param opts
109
119
  * @param mnfdDefault
110
120
  * @param mxfdDefault
111
121
  */
112
- function setNumberFormatDigitOptions(internalSlotMap, pl, opts, mnfdDefault, mxfdDefault, notation) {
122
+ function setNumberFormatDigitOptions(internalSlotMap, intlObj, opts, mnfdDefault, mxfdDefault) {
113
123
  var mnid = getNumberOption(opts, 'minimumIntegerDigits', 1, 21, 1);
114
124
  var mnfd = opts.minimumFractionDigits;
115
125
  var mxfd = opts.maximumFractionDigits;
116
126
  var mnsd = opts.minimumSignificantDigits;
117
127
  var mxsd = opts.maximumSignificantDigits;
118
- setInternalSlot(internalSlotMap, pl, 'minimumIntegerDigits', mnid);
128
+ setInternalSlot(internalSlotMap, intlObj, 'minimumIntegerDigits', mnid);
119
129
  if (mnsd !== undefined || mxsd !== undefined) {
120
- setInternalSlot(internalSlotMap, pl, 'roundingType', 'significantDigits');
130
+ setInternalSlot(internalSlotMap, intlObj, 'roundingType', 'significantDigits');
121
131
  mnsd = defaultNumberOption(mnsd, 1, 21, 1);
122
132
  mxsd = defaultNumberOption(mxsd, mnsd, 21, 21);
123
- setInternalSlot(internalSlotMap, pl, 'minimumSignificantDigits', mnsd);
124
- setInternalSlot(internalSlotMap, pl, 'maximumSignificantDigits', mxsd);
133
+ setInternalSlot(internalSlotMap, intlObj, 'minimumSignificantDigits', mnsd);
134
+ setInternalSlot(internalSlotMap, intlObj, 'maximumSignificantDigits', mxsd);
125
135
  }
126
136
  else if (mnfd !== undefined || mxfd !== undefined) {
127
- setInternalSlot(internalSlotMap, pl, 'roundingType', 'fractionDigits');
137
+ setInternalSlot(internalSlotMap, intlObj, 'roundingType', 'fractionDigits');
128
138
  mnfd = defaultNumberOption(mnfd, 0, 20, mnfdDefault);
129
139
  var mxfdActualDefault = Math.max(mnfd, mxfdDefault);
130
140
  mxfd = defaultNumberOption(mxfd, mnfd, 20, mxfdActualDefault);
131
- setInternalSlot(internalSlotMap, pl, 'minimumFractionDigits', mnfd);
132
- setInternalSlot(internalSlotMap, pl, 'maximumFractionDigits', mxfd);
141
+ setInternalSlot(internalSlotMap, intlObj, 'minimumFractionDigits', mnfd);
142
+ setInternalSlot(internalSlotMap, intlObj, 'maximumFractionDigits', mxfd);
133
143
  }
134
- else if (notation === 'compact') {
135
- setInternalSlot(internalSlotMap, pl, 'roundingType', 'compactRounding');
144
+ else if (getInternalSlot(internalSlotMap, intlObj, 'notation') === 'compact') {
145
+ setInternalSlot(internalSlotMap, intlObj, 'roundingType', 'compactRounding');
136
146
  }
137
147
  else {
138
- setInternalSlot(internalSlotMap, pl, 'roundingType', 'fractionDigits');
139
- setInternalSlot(internalSlotMap, pl, 'minimumFractionDigits', mnfdDefault);
140
- setInternalSlot(internalSlotMap, pl, 'maximumFractionDigits', mxfdDefault);
148
+ setInternalSlot(internalSlotMap, intlObj, 'roundingType', 'fractionDigits');
149
+ setInternalSlot(internalSlotMap, intlObj, 'minimumFractionDigits', mnfdDefault);
150
+ setInternalSlot(internalSlotMap, intlObj, 'maximumFractionDigits', mxfdDefault);
141
151
  }
142
152
  }
143
153
 
@@ -500,7 +510,7 @@
500
510
  const matcher = getOption(opts, 'localeMatcher', 'string', ['best fit', 'lookup'], 'best fit');
501
511
  opt.localeMatcher = matcher;
502
512
  setInternalSlot(PluralRules.__INTERNAL_SLOT_MAP__, this, 'type', getOption(opts, 'type', 'string', ['cardinal', 'ordinal'], 'cardinal'));
503
- setNumberFormatDigitOptions(PluralRules.__INTERNAL_SLOT_MAP__, this, opts, 0, 3, 'standard');
513
+ setNumberFormatDigitOptions(PluralRules.__INTERNAL_SLOT_MAP__, this, opts, 0, 3);
504
514
  const r = createResolveLocale(PluralRules.getDefaultLocale)(PluralRules.availableLocales, requestedLocales, opt, PluralRules.relevantExtensionKeys, PluralRules.localeData);
505
515
  setInternalSlot(PluralRules.__INTERNAL_SLOT_MAP__, this, 'locale', r.locale);
506
516
  }
@@ -603,7 +613,10 @@
603
613
  // Meta fixes for test262
604
614
  }
605
615
 
606
- if (typeof Intl.PluralRules === 'undefined') {
616
+ if (typeof Intl.PluralRules === 'undefined' ||
617
+ (!Intl.PluralRules.polyfilled &&
618
+ new Intl.PluralRules('en', { minimumFractionDigits: 2 }).select(1) ===
619
+ 'one')) {
607
620
  Object.defineProperty(Intl, 'PluralRules', {
608
621
  value: PluralRules,
609
622
  writable: true,