@formatjs/intl-pluralrules 6.2.4 → 6.3.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.
Files changed (241) hide show
  1. package/index.d.ts +113 -65
  2. package/index.js +965 -64
  3. package/index.js.map +1 -0
  4. package/locale-data/af.js +15 -0
  5. package/locale-data/ak.js +15 -0
  6. package/locale-data/am.js +16 -0
  7. package/locale-data/an.js +15 -0
  8. package/locale-data/ar.js +23 -0
  9. package/locale-data/ars.js +23 -0
  10. package/locale-data/as.js +24 -0
  11. package/locale-data/asa.js +15 -0
  12. package/locale-data/ast.js +16 -0
  13. package/locale-data/az.js +22 -0
  14. package/locale-data/bal.js +17 -0
  15. package/locale-data/be.js +21 -0
  16. package/locale-data/bem.js +15 -0
  17. package/locale-data/bez.js +15 -0
  18. package/locale-data/bg.js +15 -0
  19. package/locale-data/bho.js +15 -0
  20. package/locale-data/bm.js +4 -0
  21. package/locale-data/bn.js +24 -0
  22. package/locale-data/bo.js +4 -0
  23. package/locale-data/br.js +21 -0
  24. package/locale-data/brx.js +15 -0
  25. package/locale-data/bs.js +19 -0
  26. package/locale-data/ca.js +26 -0
  27. package/locale-data/ce.js +15 -0
  28. package/locale-data/ceb.js +17 -0
  29. package/locale-data/cgg.js +15 -0
  30. package/locale-data/chr.js +15 -0
  31. package/locale-data/ckb.js +15 -0
  32. package/locale-data/cs.js +20 -0
  33. package/locale-data/cy.js +33 -0
  34. package/locale-data/da.js +18 -0
  35. package/locale-data/de.js +16 -0
  36. package/locale-data/doi.js +16 -0
  37. package/locale-data/dsb.js +21 -0
  38. package/locale-data/dv.js +15 -0
  39. package/locale-data/dz.js +4 -0
  40. package/locale-data/ee.js +15 -0
  41. package/locale-data/el.js +15 -0
  42. package/locale-data/en.js +23 -0
  43. package/locale-data/eo.js +15 -0
  44. package/locale-data/es.js +20 -0
  45. package/locale-data/et.js +16 -0
  46. package/locale-data/eu.js +15 -0
  47. package/locale-data/fa.js +16 -0
  48. package/locale-data/ff.js +15 -0
  49. package/locale-data/fi.js +16 -0
  50. package/locale-data/fil.js +20 -0
  51. package/locale-data/fo.js +15 -0
  52. package/locale-data/fr.js +22 -0
  53. package/locale-data/fur.js +15 -0
  54. package/locale-data/fy.js +16 -0
  55. package/locale-data/ga.js +23 -0
  56. package/locale-data/gd.js +25 -0
  57. package/locale-data/gl.js +16 -0
  58. package/locale-data/gsw.js +15 -0
  59. package/locale-data/gu.js +24 -0
  60. package/locale-data/guw.js +15 -0
  61. package/locale-data/gv.js +22 -0
  62. package/locale-data/ha.js +15 -0
  63. package/locale-data/haw.js +15 -0
  64. package/locale-data/he.js +18 -0
  65. package/locale-data/hi.js +24 -0
  66. package/locale-data/hnj.js +4 -0
  67. package/locale-data/hr.js +19 -0
  68. package/locale-data/hsb.js +21 -0
  69. package/locale-data/hu.js +17 -0
  70. package/locale-data/hy.js +18 -0
  71. package/locale-data/ia.js +16 -0
  72. package/locale-data/id.js +4 -0
  73. package/locale-data/ig.js +4 -0
  74. package/locale-data/ii.js +4 -0
  75. package/locale-data/io.js +16 -0
  76. package/locale-data/is.js +17 -0
  77. package/locale-data/it.js +22 -0
  78. package/locale-data/iu.js +17 -0
  79. package/locale-data/ja.js +4 -0
  80. package/locale-data/jbo.js +4 -0
  81. package/locale-data/jgo.js +15 -0
  82. package/locale-data/jmc.js +15 -0
  83. package/locale-data/jv.js +4 -0
  84. package/locale-data/jw.js +4 -0
  85. package/locale-data/ka.js +20 -0
  86. package/locale-data/kab.js +15 -0
  87. package/locale-data/kaj.js +15 -0
  88. package/locale-data/kcg.js +15 -0
  89. package/locale-data/kde.js +4 -0
  90. package/locale-data/kea.js +4 -0
  91. package/locale-data/kk.js +17 -0
  92. package/locale-data/kkj.js +15 -0
  93. package/locale-data/kl.js +15 -0
  94. package/locale-data/km.js +4 -0
  95. package/locale-data/kn.js +16 -0
  96. package/locale-data/ko.js +4 -0
  97. package/locale-data/ks.js +15 -0
  98. package/locale-data/ksb.js +15 -0
  99. package/locale-data/ksh.js +17 -0
  100. package/locale-data/ku.js +15 -0
  101. package/locale-data/kw.js +27 -0
  102. package/locale-data/ky.js +15 -0
  103. package/locale-data/lag.js +18 -0
  104. package/locale-data/lb.js +15 -0
  105. package/locale-data/lg.js +15 -0
  106. package/locale-data/lij.js +19 -0
  107. package/locale-data/lkt.js +4 -0
  108. package/locale-data/ln.js +15 -0
  109. package/locale-data/lo.js +15 -0
  110. package/locale-data/lt.js +21 -0
  111. package/locale-data/lv.js +19 -0
  112. package/locale-data/mas.js +15 -0
  113. package/locale-data/mg.js +15 -0
  114. package/locale-data/mgo.js +15 -0
  115. package/locale-data/mk.js +23 -0
  116. package/locale-data/ml.js +15 -0
  117. package/locale-data/mn.js +15 -0
  118. package/locale-data/mo.js +21 -0
  119. package/locale-data/mr.js +21 -0
  120. package/locale-data/ms.js +15 -0
  121. package/locale-data/mt.js +21 -0
  122. package/locale-data/my.js +4 -0
  123. package/locale-data/nah.js +15 -0
  124. package/locale-data/naq.js +17 -0
  125. package/locale-data/nb.js +15 -0
  126. package/locale-data/nd.js +15 -0
  127. package/locale-data/ne.js +17 -0
  128. package/locale-data/nl.js +16 -0
  129. package/locale-data/nn.js +15 -0
  130. package/locale-data/nnh.js +15 -0
  131. package/locale-data/no.js +15 -0
  132. package/locale-data/nqo.js +4 -0
  133. package/locale-data/nr.js +15 -0
  134. package/locale-data/nso.js +15 -0
  135. package/locale-data/ny.js +15 -0
  136. package/locale-data/nyn.js +15 -0
  137. package/locale-data/om.js +15 -0
  138. package/locale-data/or.js +23 -0
  139. package/locale-data/os.js +15 -0
  140. package/locale-data/osa.js +4 -0
  141. package/locale-data/pa.js +15 -0
  142. package/locale-data/pap.js +15 -0
  143. package/locale-data/pcm.js +16 -0
  144. package/locale-data/pl.js +20 -0
  145. package/locale-data/prg.js +19 -0
  146. package/locale-data/ps.js +15 -0
  147. package/locale-data/pt-PT.js +19 -0
  148. package/locale-data/pt.js +19 -0
  149. package/locale-data/rm.js +15 -0
  150. package/locale-data/ro.js +21 -0
  151. package/locale-data/rof.js +15 -0
  152. package/locale-data/ru.js +20 -0
  153. package/locale-data/rwk.js +15 -0
  154. package/locale-data/sah.js +4 -0
  155. package/locale-data/saq.js +15 -0
  156. package/locale-data/sat.js +17 -0
  157. package/locale-data/sc.js +19 -0
  158. package/locale-data/scn.js +22 -0
  159. package/locale-data/sd.js +15 -0
  160. package/locale-data/sdh.js +15 -0
  161. package/locale-data/se.js +17 -0
  162. package/locale-data/seh.js +15 -0
  163. package/locale-data/ses.js +4 -0
  164. package/locale-data/sg.js +4 -0
  165. package/locale-data/sh.js +19 -0
  166. package/locale-data/shi.js +18 -0
  167. package/locale-data/si.js +18 -0
  168. package/locale-data/sk.js +20 -0
  169. package/locale-data/sl.js +20 -0
  170. package/locale-data/sma.js +17 -0
  171. package/locale-data/smi.js +17 -0
  172. package/locale-data/smj.js +17 -0
  173. package/locale-data/smn.js +17 -0
  174. package/locale-data/sms.js +17 -0
  175. package/locale-data/sn.js +15 -0
  176. package/locale-data/so.js +15 -0
  177. package/locale-data/sq.js +19 -0
  178. package/locale-data/sr.js +19 -0
  179. package/locale-data/ss.js +15 -0
  180. package/locale-data/ssy.js +15 -0
  181. package/locale-data/st.js +15 -0
  182. package/locale-data/su.js +4 -0
  183. package/locale-data/sv.js +19 -0
  184. package/locale-data/sw.js +16 -0
  185. package/locale-data/syr.js +15 -0
  186. package/locale-data/ta.js +15 -0
  187. package/locale-data/te.js +15 -0
  188. package/locale-data/teo.js +15 -0
  189. package/locale-data/th.js +4 -0
  190. package/locale-data/ti.js +15 -0
  191. package/locale-data/tig.js +15 -0
  192. package/locale-data/tk.js +17 -0
  193. package/locale-data/tl.js +20 -0
  194. package/locale-data/tn.js +15 -0
  195. package/locale-data/to.js +4 -0
  196. package/locale-data/tpi.js +4 -0
  197. package/locale-data/tr.js +15 -0
  198. package/locale-data/ts.js +15 -0
  199. package/locale-data/tzm.js +15 -0
  200. package/locale-data/ug.js +15 -0
  201. package/locale-data/uk.js +23 -0
  202. package/locale-data/und.js +4 -0
  203. package/locale-data/ur.js +16 -0
  204. package/locale-data/uz.js +15 -0
  205. package/locale-data/ve.js +15 -0
  206. package/locale-data/vi.js +15 -0
  207. package/locale-data/vo.js +15 -0
  208. package/locale-data/vun.js +15 -0
  209. package/locale-data/wa.js +15 -0
  210. package/locale-data/wae.js +15 -0
  211. package/locale-data/wo.js +4 -0
  212. package/locale-data/xh.js +15 -0
  213. package/locale-data/xog.js +15 -0
  214. package/locale-data/yi.js +16 -0
  215. package/locale-data/yo.js +4 -0
  216. package/locale-data/yue.js +4 -0
  217. package/locale-data/zh.js +4 -0
  218. package/locale-data/zu.js +16 -0
  219. package/package.json +5 -6
  220. package/polyfill-force.d.ts +1 -1
  221. package/polyfill-force.js +1130 -1
  222. package/polyfill-force.js.map +1 -0
  223. package/polyfill.d.ts +1 -1
  224. package/polyfill.iife.js +5522 -7581
  225. package/polyfill.js +1359 -2
  226. package/polyfill.js.map +1 -0
  227. package/should-polyfill.d.ts +5 -1
  228. package/should-polyfill.js +227 -8
  229. package/should-polyfill.js.map +1 -0
  230. package/abstract/GetOperands.d.ts +0 -59
  231. package/abstract/GetOperands.js +0 -50
  232. package/abstract/InitializePluralRules.d.ts +0 -8
  233. package/abstract/InitializePluralRules.js +0 -31
  234. package/abstract/ResolvePlural.d.ts +0 -43
  235. package/abstract/ResolvePlural.js +0 -75
  236. package/abstract/ResolvePluralRange.d.ts +0 -23
  237. package/abstract/ResolvePluralRange.js +0 -59
  238. package/get_internal_slots.d.ts +0 -3
  239. package/get_internal_slots.js +0 -10
  240. package/supported-locales.generated.d.ts +0 -1
  241. package/supported-locales.generated.js +0 -217
package/index.js CHANGED
@@ -1,13 +1,936 @@
1
- import { CanonicalizeLocaleList, SupportedLocales, ToIntlMathematicalValue } from "@formatjs/ecma402-abstract";
2
- import "./abstract/GetOperands.js";
3
- import { InitializePluralRules } from "./abstract/InitializePluralRules.js";
4
- import { ResolvePlural } from "./abstract/ResolvePlural.js";
5
- import { ResolvePluralRange } from "./abstract/ResolvePluralRange.js";
6
- import getInternalSlots from "./get_internal_slots.js";
7
- function validateInstance(instance, method) {
8
- if (!(instance instanceof PluralRules)) {
9
- throw new TypeError(`Method Intl.PluralRules.prototype.${method} called on incompatible receiver ${String(instance)}`);
1
+ import { LookupSupportedLocales, ResolveLocale } from "@formatjs/intl-localematcher";
2
+ import Decimal, { Decimal as Decimal$1 } from "@formatjs/bigdecimal";
3
+ //#region packages/ecma402-abstract/CanonicalizeLocaleList.js
4
+ /**
5
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist
6
+ * @param locales
7
+ */
8
+ function CanonicalizeLocaleList(locales) {
9
+ return Intl.getCanonicalLocales(locales);
10
+ }
11
+ //#endregion
12
+ //#region packages/ecma262-abstract/ToObject.js
13
+ /**
14
+ * https://tc39.es/ecma262/#sec-toobject
15
+ */
16
+ function ToObject(arg) {
17
+ if (arg == null) throw new TypeError("undefined/null cannot be converted to object");
18
+ return Object(arg);
19
+ }
20
+ //#endregion
21
+ //#region packages/ecma262-abstract/ToString.js
22
+ /**
23
+ * https://tc39.es/ecma262/#sec-tostring
24
+ */
25
+ function ToString(o) {
26
+ if (typeof o === "symbol") throw TypeError("Cannot convert a Symbol value to a string");
27
+ return String(o);
28
+ }
29
+ //#endregion
30
+ //#region packages/ecma402-abstract/GetOption.js
31
+ /**
32
+ * https://tc39.es/ecma402/#sec-getoption
33
+ * @param opts
34
+ * @param prop
35
+ * @param type
36
+ * @param values
37
+ * @param fallback
38
+ */
39
+ function GetOption(opts, prop, type, values, fallback) {
40
+ if (typeof opts !== "object") throw new TypeError("Options must be an object");
41
+ let value = opts[prop];
42
+ if (value !== void 0) {
43
+ if (type !== "boolean" && type !== "string") throw new TypeError("invalid type");
44
+ if (type === "boolean") value = Boolean(value);
45
+ if (type === "string") value = ToString(value);
46
+ if (values !== void 0 && !values.filter((val) => val == value).length) throw new RangeError(`${value} is not within ${values.join(", ")}`);
47
+ return value;
48
+ }
49
+ return fallback;
50
+ }
51
+ //#endregion
52
+ //#region packages/ecma402-abstract/SupportedLocales.js
53
+ /**
54
+ * https://tc39.es/ecma402/#sec-supportedlocales
55
+ * @param availableLocales
56
+ * @param requestedLocales
57
+ * @param options
58
+ */
59
+ function SupportedLocales(availableLocales, requestedLocales, options) {
60
+ let matcher = "best fit";
61
+ if (options !== void 0) {
62
+ options = ToObject(options);
63
+ matcher = GetOption(options, "localeMatcher", "string", ["lookup", "best fit"], "best fit");
64
+ }
65
+ if (matcher === "best fit") return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
66
+ return LookupSupportedLocales(Array.from(availableLocales), requestedLocales);
67
+ }
68
+ //#endregion
69
+ //#region packages/ecma262-abstract/ToPrimitive.js
70
+ function invariant$2(condition, message, Err = Error) {
71
+ if (!condition) throw new Err(message);
72
+ }
73
+ function IsCallable(fn) {
74
+ return typeof fn === "function";
75
+ }
76
+ function OrdinaryToPrimitive(O, hint) {
77
+ let methodNames;
78
+ if (hint === "string") methodNames = ["toString", "valueOf"];
79
+ else methodNames = ["valueOf", "toString"];
80
+ for (const name of methodNames) {
81
+ const method = O[name];
82
+ if (IsCallable(method)) {
83
+ let result = method.call(O);
84
+ if (typeof result !== "object") return result;
85
+ }
86
+ }
87
+ throw new TypeError("Cannot convert object to primitive value");
88
+ }
89
+ /**
90
+ * https://tc39.es/ecma262/#sec-toprimitive
91
+ */
92
+ function ToPrimitive(input, preferredType) {
93
+ if (typeof input === "object" && input != null) {
94
+ const exoticToPrim = Symbol.toPrimitive in input ? input[Symbol.toPrimitive] : void 0;
95
+ let hint;
96
+ if (exoticToPrim !== void 0) {
97
+ if (preferredType === void 0) hint = "default";
98
+ else if (preferredType === "string") hint = "string";
99
+ else {
100
+ invariant$2(preferredType === "number", "preferredType must be \"string\" or \"number\"");
101
+ hint = "number";
102
+ }
103
+ let result = exoticToPrim.call(input, hint);
104
+ if (typeof result !== "object") return result;
105
+ throw new TypeError("Cannot convert exotic object to primitive.");
106
+ }
107
+ if (preferredType === void 0) preferredType = "number";
108
+ return OrdinaryToPrimitive(input, preferredType);
109
+ }
110
+ return input;
111
+ }
112
+ //#endregion
113
+ //#region packages/ecma402-abstract/ToIntlMathematicalValue.js
114
+ /**
115
+ * https://tc39.es/ecma402/#sec-tointlmathematicalvalue
116
+ * Converts input to a mathematical value, supporting BigInt
117
+ */
118
+ function ToIntlMathematicalValue(input) {
119
+ if (typeof input === "bigint") return new Decimal$1(input.toString());
120
+ let primValue = ToPrimitive(input, "number");
121
+ if (primValue === void 0) return new Decimal$1(NaN);
122
+ if (primValue === true) return new Decimal$1(1);
123
+ if (primValue === false) return new Decimal$1(0);
124
+ if (primValue === null) return new Decimal$1(0);
125
+ try {
126
+ return new Decimal$1(primValue);
127
+ } catch {
128
+ return new Decimal$1(NaN);
129
+ }
130
+ }
131
+ //#endregion
132
+ //#region packages/ecma402-abstract/CoerceOptionsToObject.js
133
+ /**
134
+ * https://tc39.es/ecma402/#sec-coerceoptionstoobject
135
+ * @param options
136
+ * @returns
137
+ */
138
+ function CoerceOptionsToObject(options) {
139
+ if (typeof options === "undefined") return Object.create(null);
140
+ return ToObject(options);
141
+ }
142
+ //#endregion
143
+ //#region packages/ecma402-abstract/DefaultNumberOption.js
144
+ /**
145
+ * https://tc39.es/ecma402/#sec-defaultnumberoption
146
+ * @param val
147
+ * @param min
148
+ * @param max
149
+ * @param fallback
150
+ */
151
+ function DefaultNumberOption(inputVal, min, max, fallback) {
152
+ if (inputVal === void 0) return fallback;
153
+ const val = Number(inputVal);
154
+ if (isNaN(val) || val < min || val > max) throw new RangeError(`${val} is outside of range [${min}, ${max}]`);
155
+ return Math.floor(val);
156
+ }
157
+ //#endregion
158
+ //#region packages/ecma402-abstract/GetNumberOption.js
159
+ /**
160
+ * https://tc39.es/ecma402/#sec-getnumberoption
161
+ * @param options
162
+ * @param property
163
+ * @param min
164
+ * @param max
165
+ * @param fallback
166
+ */
167
+ function GetNumberOption(options, property, minimum, maximum, fallback) {
168
+ const val = options[property];
169
+ return DefaultNumberOption(val, minimum, maximum, fallback);
170
+ }
171
+ //#endregion
172
+ //#region node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js
173
+ function memoize(fn, options) {
174
+ const cache = options && options.cache ? options.cache : cacheDefault;
175
+ const serializer = options && options.serializer ? options.serializer : serializerDefault;
176
+ return (options && options.strategy ? options.strategy : strategyDefault)(fn, {
177
+ cache,
178
+ serializer
179
+ });
180
+ }
181
+ function isPrimitive(value) {
182
+ return value == null || typeof value === "number" || typeof value === "boolean";
183
+ }
184
+ function monadic(fn, cache, serializer, arg) {
185
+ const cacheKey = isPrimitive(arg) ? arg : serializer(arg);
186
+ let computedValue = cache.get(cacheKey);
187
+ if (typeof computedValue === "undefined") {
188
+ computedValue = fn.call(this, arg);
189
+ cache.set(cacheKey, computedValue);
190
+ }
191
+ return computedValue;
192
+ }
193
+ function variadic(fn, cache, serializer) {
194
+ const args = Array.prototype.slice.call(arguments, 3);
195
+ const cacheKey = serializer(args);
196
+ let computedValue = cache.get(cacheKey);
197
+ if (typeof computedValue === "undefined") {
198
+ computedValue = fn.apply(this, args);
199
+ cache.set(cacheKey, computedValue);
200
+ }
201
+ return computedValue;
202
+ }
203
+ function assemble(fn, context, strategy, cache, serialize) {
204
+ return strategy.bind(context, fn, cache, serialize);
205
+ }
206
+ function strategyDefault(fn, options) {
207
+ const strategy = fn.length === 1 ? monadic : variadic;
208
+ return assemble(fn, this, strategy, options.cache.create(), options.serializer);
209
+ }
210
+ function strategyVariadic(fn, options) {
211
+ return assemble(fn, this, variadic, options.cache.create(), options.serializer);
212
+ }
213
+ function strategyMonadic(fn, options) {
214
+ return assemble(fn, this, monadic, options.cache.create(), options.serializer);
215
+ }
216
+ const serializerDefault = function() {
217
+ return JSON.stringify(arguments);
218
+ };
219
+ var ObjectWithoutPrototypeCache = class {
220
+ constructor() {
221
+ this.cache = Object.create(null);
222
+ }
223
+ get(key) {
224
+ return this.cache[key];
225
+ }
226
+ set(key, value) {
227
+ this.cache[key] = value;
10
228
  }
229
+ };
230
+ const cacheDefault = { create: function create() {
231
+ return new ObjectWithoutPrototypeCache();
232
+ } };
233
+ const strategies = {
234
+ variadic: strategyVariadic,
235
+ monadic: strategyMonadic
236
+ };
237
+ //#endregion
238
+ //#region packages/ecma402-abstract/utils.js
239
+ function repeat(s, times) {
240
+ if (typeof s.repeat === "function") return s.repeat(times);
241
+ const arr = Array.from({ length: times });
242
+ for (let i = 0; i < arr.length; i++) arr[i] = s;
243
+ return arr.join("");
244
+ }
245
+ function invariant$1(condition, message, Err = Error) {
246
+ if (!condition) throw new Err(message);
247
+ }
248
+ memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic });
249
+ memoize((...args) => new Intl.PluralRules(...args), { strategy: strategies.variadic });
250
+ memoize((...args) => new Intl.Locale(...args), { strategy: strategies.variadic });
251
+ memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic });
252
+ //#endregion
253
+ //#region packages/ecma402-abstract/NumberFormat/SetNumberFormatDigitOptions.js
254
+ const VALID_ROUNDING_INCREMENTS = new Set([
255
+ 1,
256
+ 2,
257
+ 5,
258
+ 10,
259
+ 20,
260
+ 25,
261
+ 50,
262
+ 100,
263
+ 200,
264
+ 250,
265
+ 500,
266
+ 1e3,
267
+ 2e3,
268
+ 2500,
269
+ 5e3
270
+ ]);
271
+ /**
272
+ * https://tc39.es/ecma402/#sec-setnfdigitoptions
273
+ */
274
+ function SetNumberFormatDigitOptions(internalSlots, opts, mnfdDefault, mxfdDefault, notation) {
275
+ const mnid = GetNumberOption(opts, "minimumIntegerDigits", 1, 21, 1);
276
+ let mnfd = opts.minimumFractionDigits;
277
+ let mxfd = opts.maximumFractionDigits;
278
+ let mnsd = opts.minimumSignificantDigits;
279
+ let mxsd = opts.maximumSignificantDigits;
280
+ internalSlots.minimumIntegerDigits = mnid;
281
+ const roundingIncrement = GetNumberOption(opts, "roundingIncrement", 1, 5e3, 1);
282
+ invariant$1(VALID_ROUNDING_INCREMENTS.has(roundingIncrement), `Invalid rounding increment value: ${roundingIncrement}.
283
+ Valid values are ${Array.from(VALID_ROUNDING_INCREMENTS).join(", ")}.`);
284
+ const roundingMode = GetOption(opts, "roundingMode", "string", [
285
+ "ceil",
286
+ "floor",
287
+ "expand",
288
+ "trunc",
289
+ "halfCeil",
290
+ "halfFloor",
291
+ "halfExpand",
292
+ "halfTrunc",
293
+ "halfEven"
294
+ ], "halfExpand");
295
+ const roundingPriority = GetOption(opts, "roundingPriority", "string", [
296
+ "auto",
297
+ "morePrecision",
298
+ "lessPrecision"
299
+ ], "auto");
300
+ const trailingZeroDisplay = GetOption(opts, "trailingZeroDisplay", "string", ["auto", "stripIfInteger"], "auto");
301
+ if (roundingIncrement !== 1) mxfdDefault = mnfdDefault;
302
+ internalSlots.roundingIncrement = roundingIncrement;
303
+ internalSlots.roundingMode = roundingMode;
304
+ internalSlots.trailingZeroDisplay = trailingZeroDisplay;
305
+ const hasSd = mnsd !== void 0 || mxsd !== void 0;
306
+ const hasFd = mnfd !== void 0 || mxfd !== void 0;
307
+ let needSd = true;
308
+ let needFd = true;
309
+ if (roundingPriority === "auto") {
310
+ needSd = hasSd;
311
+ if (hasSd || !hasFd && notation === "compact") needFd = false;
312
+ }
313
+ if (needSd) if (hasSd) {
314
+ internalSlots.minimumSignificantDigits = DefaultNumberOption(mnsd, 1, 21, 1);
315
+ internalSlots.maximumSignificantDigits = DefaultNumberOption(mxsd, internalSlots.minimumSignificantDigits, 21, 21);
316
+ } else {
317
+ internalSlots.minimumSignificantDigits = 1;
318
+ internalSlots.maximumSignificantDigits = 21;
319
+ }
320
+ if (needFd) if (hasFd) {
321
+ mnfd = DefaultNumberOption(mnfd, 0, 100, void 0);
322
+ mxfd = DefaultNumberOption(mxfd, 0, 100, void 0);
323
+ if (mnfd === void 0) {
324
+ invariant$1(mxfd !== void 0, "maximumFractionDigits must be defined");
325
+ mnfd = Math.min(mnfdDefault, mxfd);
326
+ } else if (mxfd === void 0) mxfd = Math.max(mxfdDefault, mnfd);
327
+ else if (mnfd > mxfd) throw new RangeError(`Invalid range, ${mnfd} > ${mxfd}`);
328
+ internalSlots.minimumFractionDigits = mnfd;
329
+ internalSlots.maximumFractionDigits = mxfd;
330
+ } else {
331
+ internalSlots.minimumFractionDigits = mnfdDefault;
332
+ internalSlots.maximumFractionDigits = mxfdDefault;
333
+ }
334
+ if (!needSd && !needFd) {
335
+ internalSlots.minimumFractionDigits = 0;
336
+ internalSlots.maximumFractionDigits = 0;
337
+ internalSlots.minimumSignificantDigits = 1;
338
+ internalSlots.maximumSignificantDigits = 2;
339
+ internalSlots.roundingType = "morePrecision";
340
+ internalSlots.roundingPriority = "morePrecision";
341
+ } else if (roundingPriority === "morePrecision") {
342
+ internalSlots.roundingType = "morePrecision";
343
+ internalSlots.roundingPriority = "morePrecision";
344
+ } else if (roundingPriority === "lessPrecision") {
345
+ internalSlots.roundingType = "lessPrecision";
346
+ internalSlots.roundingPriority = "lessPrecision";
347
+ } else if (hasSd) {
348
+ internalSlots.roundingType = "significantDigits";
349
+ internalSlots.roundingPriority = "auto";
350
+ } else {
351
+ internalSlots.roundingType = "fractionDigits";
352
+ internalSlots.roundingPriority = "auto";
353
+ }
354
+ if (roundingIncrement !== 1) {
355
+ invariant$1(internalSlots.roundingType === "fractionDigits", "Invalid roundingType", TypeError);
356
+ invariant$1(internalSlots.maximumFractionDigits === internalSlots.minimumFractionDigits, "With roundingIncrement > 1, maximumFractionDigits and minimumFractionDigits must be equal.", RangeError);
357
+ }
358
+ }
359
+ //#endregion
360
+ //#region packages/ecma402-abstract/PluralRules/InitializePluralRules.js
361
+ function InitializePluralRules(pl, locales, options, { availableLocales, relevantExtensionKeys, localeData, getDefaultLocale, getInternalSlots }) {
362
+ const requestedLocales = CanonicalizeLocaleList(locales);
363
+ const opt = Object.create(null);
364
+ const opts = CoerceOptionsToObject(options);
365
+ const internalSlots = getInternalSlots(pl);
366
+ internalSlots.initializedPluralRules = true;
367
+ opt.localeMatcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
368
+ const r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale);
369
+ internalSlots.locale = r.locale;
370
+ internalSlots.type = GetOption(opts, "type", "string", ["cardinal", "ordinal"], "cardinal");
371
+ const notation = GetOption(opts, "notation", "string", ["standard", "compact"], "standard");
372
+ internalSlots.notation = notation;
373
+ if (notation === "compact") {
374
+ internalSlots.compactDisplay = GetOption(opts, "compactDisplay", "string", ["short", "long"], "short");
375
+ if (typeof Intl !== "undefined" && Intl.NumberFormat && Intl.NumberFormat.localeData) internalSlots.dataLocaleData = Intl.NumberFormat.localeData[r.locale];
376
+ }
377
+ SetNumberFormatDigitOptions(internalSlots, opts, 0, 3, "standard");
378
+ return pl;
379
+ }
380
+ //#endregion
381
+ //#region packages/ecma262-abstract/Type.js
382
+ /**
383
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#sec-type
384
+ */
385
+ function Type(x) {
386
+ if (x === null) return "Null";
387
+ if (typeof x === "undefined") return "Undefined";
388
+ if (typeof x === "function" || typeof x === "object") return "Object";
389
+ if (typeof x === "number") return "Number";
390
+ if (typeof x === "boolean") return "Boolean";
391
+ if (typeof x === "string") return "String";
392
+ if (typeof x === "symbol") return "Symbol";
393
+ if (typeof x === "bigint") return "BigInt";
394
+ }
395
+ //#endregion
396
+ //#region packages/ecma402-abstract/NumberFormat/decimal-cache.js
397
+ /**
398
+ * Cached function to compute powers of 10 for Decimal.js operations.
399
+ * This cache significantly reduces overhead in ComputeExponent and ToRawFixed
400
+ * by memoizing expensive Decimal.pow(10, n) calculations.
401
+ *
402
+ * Common exponents (e.g., -20 to 20) are used repeatedly in number formatting,
403
+ * so caching provides substantial performance benefits.
404
+ *
405
+ * @param exponent - Can be a number or Decimal. If Decimal, it will be converted to string for cache key.
406
+ */
407
+ const getPowerOf10 = memoize((exponent) => {
408
+ return Decimal$1.pow(10, exponent);
409
+ });
410
+ //#endregion
411
+ //#region packages/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
412
+ /**
413
+ * The abstract operation ComputeExponentForMagnitude computes an exponent by which to scale a
414
+ * number of the given magnitude (power of ten of the most significant digit) according to the
415
+ * locale and the desired notation (scientific, engineering, or compact).
416
+ */
417
+ function ComputeExponentForMagnitude(internalSlots, magnitude) {
418
+ const { notation, dataLocaleData, numberingSystem } = internalSlots;
419
+ switch (notation) {
420
+ case "standard": return 0;
421
+ case "scientific": return magnitude.toNumber();
422
+ case "engineering": return magnitude.div(3).floor().times(3).toNumber();
423
+ default: {
424
+ invariant$1(notation === "compact", "Invalid notation");
425
+ const { compactDisplay, style, currencyDisplay } = internalSlots;
426
+ let thresholdMap;
427
+ if (style === "currency" && currencyDisplay !== "name") thresholdMap = (dataLocaleData.numbers.currency[numberingSystem] || dataLocaleData.numbers.currency[dataLocaleData.numbers.nu[0]]).short;
428
+ else {
429
+ const decimal = dataLocaleData.numbers.decimal[numberingSystem] || dataLocaleData.numbers.decimal[dataLocaleData.numbers.nu[0]];
430
+ thresholdMap = compactDisplay === "long" ? decimal.long : decimal.short;
431
+ }
432
+ if (!thresholdMap) return 0;
433
+ const num = getPowerOf10(magnitude).toString();
434
+ const thresholds = Object.keys(thresholdMap);
435
+ if (num < thresholds[0]) return 0;
436
+ if (num > thresholds[thresholds.length - 1]) {
437
+ const magnitudeKey = thresholds[thresholds.length - 1];
438
+ if (thresholdMap[magnitudeKey].other === "0") return 0;
439
+ return magnitudeKey.length - thresholdMap[magnitudeKey].other.match(/0+/)[0].length;
440
+ }
441
+ const i = thresholds.indexOf(num);
442
+ if (i === -1) return 0;
443
+ const magnitudeKey = thresholds[i];
444
+ if (thresholdMap[magnitudeKey].other === "0") return 0;
445
+ return magnitudeKey.length - thresholdMap[magnitudeKey].other.match(/0+/)[0].length;
446
+ }
447
+ }
448
+ }
449
+ new Decimal$1(10);
450
+ const ZERO$1 = new Decimal$1(0);
451
+ const NEGATIVE_ZERO = new Decimal$1(-0);
452
+ //#endregion
453
+ //#region packages/ecma402-abstract/NumberFormat/GetUnsignedRoundingMode.js
454
+ const negativeMapping = {
455
+ ceil: "zero",
456
+ floor: "infinity",
457
+ expand: "infinity",
458
+ trunc: "zero",
459
+ halfCeil: "half-zero",
460
+ halfFloor: "half-infinity",
461
+ halfExpand: "half-infinity",
462
+ halfTrunc: "half-zero",
463
+ halfEven: "half-even"
464
+ };
465
+ const positiveMapping = {
466
+ ceil: "infinity",
467
+ floor: "zero",
468
+ expand: "infinity",
469
+ trunc: "zero",
470
+ halfCeil: "half-infinity",
471
+ halfFloor: "half-zero",
472
+ halfExpand: "half-infinity",
473
+ halfTrunc: "half-zero",
474
+ halfEven: "half-even"
475
+ };
476
+ function GetUnsignedRoundingMode(roundingMode, isNegative) {
477
+ if (isNegative) return negativeMapping[roundingMode];
478
+ return positiveMapping[roundingMode];
479
+ }
480
+ //#endregion
481
+ //#region packages/ecma402-abstract/NumberFormat/ApplyUnsignedRoundingMode.js
482
+ function ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode) {
483
+ if (x.eq(r1) || r1.eq(r2)) return r1;
484
+ if (x.eq(r2)) return r2;
485
+ invariant$1(r1.lessThan(x) && x.lessThan(r2), `x should be between r1 and r2 but x=${x}, r1=${r1}, r2=${r2}`);
486
+ if (unsignedRoundingMode === "zero") return r1;
487
+ if (unsignedRoundingMode === "infinity") return r2;
488
+ const d1 = x.minus(r1);
489
+ const d2 = r2.minus(x);
490
+ if (d1.lessThan(d2)) return r1;
491
+ if (d2.lessThan(d1)) return r2;
492
+ invariant$1(d1.eq(d2), "d1 should be equal to d2");
493
+ if (unsignedRoundingMode === "half-zero") return r1;
494
+ if (unsignedRoundingMode === "half-infinity") return r2;
495
+ invariant$1(unsignedRoundingMode === "half-even", "unsignedRoundingMode should be half-even");
496
+ if (r1.div(r2.minus(r1)).mod(2).isZero()) return r1;
497
+ return r2;
498
+ }
499
+ //#endregion
500
+ //#region packages/ecma402-abstract/NumberFormat/ToRawFixed.js
501
+ function ToRawFixedFn(n, f) {
502
+ return n.times(getPowerOf10(-f));
503
+ }
504
+ function findN1R1(x, f, roundingIncrement) {
505
+ const n1 = x.times(getPowerOf10(f)).floor().div(roundingIncrement).floor().times(roundingIncrement);
506
+ return {
507
+ n1,
508
+ r1: ToRawFixedFn(n1, f)
509
+ };
510
+ }
511
+ function findN2R2(x, f, roundingIncrement) {
512
+ const n2 = x.times(getPowerOf10(f)).ceil().div(roundingIncrement).ceil().times(roundingIncrement);
513
+ return {
514
+ n2,
515
+ r2: ToRawFixedFn(n2, f)
516
+ };
517
+ }
518
+ /**
519
+ * https://tc39.es/ecma402/#sec-torawfixed
520
+ * @param x a finite non-negative Number or BigInt
521
+ * @param minFraction an integer between 0 and 20
522
+ * @param maxFraction an integer between 0 and 20
523
+ */
524
+ function ToRawFixed(x, minFraction, maxFraction, roundingIncrement, unsignedRoundingMode) {
525
+ const f = maxFraction;
526
+ const { n1, r1 } = findN1R1(x, f, roundingIncrement);
527
+ const { n2, r2 } = findN2R2(x, f, roundingIncrement);
528
+ const r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
529
+ let n, xFinal;
530
+ let m;
531
+ if (r.eq(r1)) {
532
+ n = n1;
533
+ xFinal = r1;
534
+ } else {
535
+ n = n2;
536
+ xFinal = r2;
537
+ }
538
+ if (n.isZero()) m = "0";
539
+ else m = n.toString();
540
+ let int;
541
+ if (f !== 0) {
542
+ let k = m.length;
543
+ if (k <= f) {
544
+ m = repeat("0", f - k + 1) + m;
545
+ k = f + 1;
546
+ }
547
+ const a = m.slice(0, k - f);
548
+ const b = m.slice(m.length - f);
549
+ m = a + "." + b;
550
+ int = a.length;
551
+ } else int = m.length;
552
+ let cut = maxFraction - minFraction;
553
+ while (cut > 0 && m[m.length - 1] === "0") {
554
+ m = m.slice(0, m.length - 1);
555
+ cut--;
556
+ }
557
+ if (m[m.length - 1] === ".") m = m.slice(0, m.length - 1);
558
+ return {
559
+ formattedString: m,
560
+ roundedNumber: xFinal,
561
+ integerDigitsCount: int,
562
+ roundingMagnitude: -f
563
+ };
564
+ }
565
+ //#endregion
566
+ //#region packages/ecma402-abstract/NumberFormat/ToRawPrecision.js
567
+ function findN1E1R1(x, p) {
568
+ const maxN1 = getPowerOf10(p);
569
+ const minN1 = getPowerOf10(p - 1);
570
+ let e1 = x.log(10).floor();
571
+ const divisor = getPowerOf10(e1.minus(p).plus(1));
572
+ let n1 = x.div(divisor).floor();
573
+ let r1 = n1.times(divisor);
574
+ if (n1.greaterThanOrEqualTo(maxN1)) {
575
+ e1 = e1.plus(1);
576
+ const newDivisor = getPowerOf10(e1.minus(p).plus(1));
577
+ n1 = x.div(newDivisor).floor();
578
+ r1 = n1.times(newDivisor);
579
+ } else if (n1.lessThan(minN1)) {
580
+ e1 = e1.minus(1);
581
+ const newDivisor = getPowerOf10(e1.minus(p).plus(1));
582
+ n1 = x.div(newDivisor).floor();
583
+ r1 = n1.times(newDivisor);
584
+ }
585
+ if (r1.lessThanOrEqualTo(x) && n1.lessThan(maxN1) && n1.greaterThanOrEqualTo(minN1)) return {
586
+ n1,
587
+ e1,
588
+ r1
589
+ };
590
+ let currentE1 = x.div(minN1).log(10).plus(p).minus(1).ceil();
591
+ while (true) {
592
+ const currentDivisor = getPowerOf10(currentE1.minus(p).plus(1));
593
+ let currentN1 = x.div(currentDivisor).floor();
594
+ if (currentN1.lessThan(maxN1) && currentN1.greaterThanOrEqualTo(minN1)) {
595
+ const currentR1 = currentN1.times(currentDivisor);
596
+ if (currentR1.lessThanOrEqualTo(x)) return {
597
+ n1: currentN1,
598
+ e1: currentE1,
599
+ r1: currentR1
600
+ };
601
+ }
602
+ currentE1 = currentE1.minus(1);
603
+ }
604
+ }
605
+ function findN2E2R2(x, p) {
606
+ const maxN2 = getPowerOf10(p);
607
+ const minN2 = getPowerOf10(p - 1);
608
+ let e2 = x.log(10).floor();
609
+ const divisor = getPowerOf10(e2.minus(p).plus(1));
610
+ let n2 = x.div(divisor).ceil();
611
+ let r2 = n2.times(divisor);
612
+ if (n2.greaterThanOrEqualTo(maxN2)) {
613
+ e2 = e2.plus(1);
614
+ const newDivisor = getPowerOf10(e2.minus(p).plus(1));
615
+ n2 = x.div(newDivisor).ceil();
616
+ r2 = n2.times(newDivisor);
617
+ } else if (n2.lessThan(minN2)) {
618
+ e2 = e2.minus(1);
619
+ const newDivisor = getPowerOf10(e2.minus(p).plus(1));
620
+ n2 = x.div(newDivisor).ceil();
621
+ r2 = n2.times(newDivisor);
622
+ }
623
+ if (r2.greaterThanOrEqualTo(x) && n2.lessThan(maxN2) && n2.greaterThanOrEqualTo(minN2)) return {
624
+ n2,
625
+ e2,
626
+ r2
627
+ };
628
+ let currentE2 = x.div(maxN2).log(10).plus(p).minus(1).floor();
629
+ while (true) {
630
+ const currentDivisor = getPowerOf10(currentE2.minus(p).plus(1));
631
+ let currentN2 = x.div(currentDivisor).ceil();
632
+ if (currentN2.lessThan(maxN2) && currentN2.greaterThanOrEqualTo(minN2)) {
633
+ const currentR2 = currentN2.times(currentDivisor);
634
+ if (currentR2.greaterThanOrEqualTo(x)) return {
635
+ n2: currentN2,
636
+ e2: currentE2,
637
+ r2: currentR2
638
+ };
639
+ }
640
+ currentE2 = currentE2.plus(1);
641
+ }
642
+ }
643
+ /**
644
+ * https://tc39.es/ecma402/#sec-torawprecision
645
+ * @param x a finite non-negative Number or BigInt
646
+ * @param minPrecision an integer between 1 and 21
647
+ * @param maxPrecision an integer between 1 and 21
648
+ */
649
+ function ToRawPrecision(x, minPrecision, maxPrecision, unsignedRoundingMode) {
650
+ const p = maxPrecision;
651
+ let m;
652
+ let e;
653
+ let xFinal;
654
+ if (x.isZero()) {
655
+ m = repeat("0", p);
656
+ e = 0;
657
+ xFinal = ZERO$1;
658
+ } else {
659
+ const { n1, e1, r1 } = findN1E1R1(x, p);
660
+ const { n2, e2, r2 } = findN2E2R2(x, p);
661
+ let r = ApplyUnsignedRoundingMode(x, r1, r2, unsignedRoundingMode);
662
+ let n;
663
+ if (r.eq(r1)) {
664
+ n = n1;
665
+ e = e1.toNumber();
666
+ xFinal = r1;
667
+ } else {
668
+ n = n2;
669
+ e = e2.toNumber();
670
+ xFinal = r2;
671
+ }
672
+ m = n.toString();
673
+ }
674
+ let int;
675
+ if (e >= p - 1) {
676
+ m = m + repeat("0", e - p + 1);
677
+ int = e + 1;
678
+ } else if (e >= 0) {
679
+ m = m.slice(0, e + 1) + "." + m.slice(m.length - (p - (e + 1)));
680
+ int = e + 1;
681
+ } else {
682
+ invariant$1(e < 0, "e should be less than 0");
683
+ m = "0." + repeat("0", -e - 1) + m;
684
+ int = 1;
685
+ }
686
+ if (m.includes(".") && maxPrecision > minPrecision) {
687
+ let cut = maxPrecision - minPrecision;
688
+ while (cut > 0 && m[m.length - 1] === "0") {
689
+ m = m.slice(0, m.length - 1);
690
+ cut--;
691
+ }
692
+ if (m[m.length - 1] === ".") m = m.slice(0, m.length - 1);
693
+ }
694
+ return {
695
+ formattedString: m,
696
+ roundedNumber: xFinal,
697
+ integerDigitsCount: int,
698
+ roundingMagnitude: e
699
+ };
700
+ }
701
+ //#endregion
702
+ //#region packages/ecma402-abstract/NumberFormat/FormatNumericToString.js
703
+ /**
704
+ * https://tc39.es/ecma402/#sec-formatnumberstring
705
+ */
706
+ function FormatNumericToString(intlObject, _x) {
707
+ let x = _x;
708
+ let sign;
709
+ if (x.isZero() && x.isNegative()) {
710
+ sign = "negative";
711
+ x = ZERO$1;
712
+ } else {
713
+ invariant$1(x.isFinite(), "NumberFormatDigitInternalSlots value is not finite");
714
+ if (x.lessThan(0)) sign = "negative";
715
+ else sign = "positive";
716
+ if (sign === "negative") x = x.negated();
717
+ }
718
+ let result;
719
+ const roundingType = intlObject.roundingType;
720
+ const unsignedRoundingMode = GetUnsignedRoundingMode(intlObject.roundingMode, sign === "negative");
721
+ switch (roundingType) {
722
+ case "significantDigits":
723
+ result = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
724
+ break;
725
+ case "fractionDigits":
726
+ result = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
727
+ break;
728
+ default:
729
+ let sResult = ToRawPrecision(x, intlObject.minimumSignificantDigits, intlObject.maximumSignificantDigits, unsignedRoundingMode);
730
+ let fResult = ToRawFixed(x, intlObject.minimumFractionDigits, intlObject.maximumFractionDigits, intlObject.roundingIncrement, unsignedRoundingMode);
731
+ if (intlObject.roundingType === "morePrecision") if (sResult.roundingMagnitude <= fResult.roundingMagnitude) result = sResult;
732
+ else result = fResult;
733
+ else {
734
+ invariant$1(intlObject.roundingType === "lessPrecision", "Invalid roundingType");
735
+ if (sResult.roundingMagnitude <= fResult.roundingMagnitude) result = fResult;
736
+ else result = sResult;
737
+ }
738
+ break;
739
+ }
740
+ x = result.roundedNumber;
741
+ let string = result.formattedString;
742
+ if (intlObject.trailingZeroDisplay === "stripIfInteger" && x.isInteger()) {
743
+ let i = string.indexOf(".");
744
+ if (i > -1) string = string.slice(0, i);
745
+ }
746
+ const int = result.integerDigitsCount;
747
+ const minInteger = intlObject.minimumIntegerDigits;
748
+ if (int < minInteger) string = repeat("0", minInteger - int) + string;
749
+ if (sign === "negative") if (x.isZero()) x = NEGATIVE_ZERO;
750
+ else x = x.negated();
751
+ return {
752
+ roundedNumber: x,
753
+ formattedString: string
754
+ };
755
+ }
756
+ //#endregion
757
+ //#region packages/ecma262-abstract/ToNumber.js
758
+ const ZERO = new Decimal$1(0);
759
+ function invariant(condition, message, Err = Error) {
760
+ if (!condition) throw new Err(message);
761
+ }
762
+ /**
763
+ * https://tc39.es/ecma262/#sec-tonumber
764
+ */
765
+ function ToNumber(arg) {
766
+ if (typeof arg === "number") return new Decimal$1(arg);
767
+ if (typeof arg === "bigint") return new Decimal$1(arg.toString());
768
+ invariant(typeof arg !== "symbol", "Symbol is not supported", TypeError);
769
+ if (arg === void 0) return new Decimal$1(NaN);
770
+ if (arg === null || arg === 0) return ZERO;
771
+ if (arg === true) return new Decimal$1(1);
772
+ if (typeof arg === "string") try {
773
+ return new Decimal$1(arg);
774
+ } catch {
775
+ return new Decimal$1(NaN);
776
+ }
777
+ invariant(typeof arg === "object", "object expected", TypeError);
778
+ let primValue = ToPrimitive(arg, "number");
779
+ invariant(typeof primValue !== "object", "object expected", TypeError);
780
+ return ToNumber(primValue);
781
+ }
782
+ //#endregion
783
+ //#region packages/ecma402-abstract/PluralRules/GetOperands.js
784
+ /**
785
+ * ECMA-402 Spec: GetOperands abstract operation
786
+ * https://tc39.es/ecma402/#sec-getoperands
787
+ *
788
+ * Implementation: Extended to support compact exponent (c/e operands)
789
+ *
790
+ * @param s Formatted number string
791
+ * @param exponent Compact decimal exponent (c/e operand), defaults to 0
792
+ */
793
+ function GetOperands(s, exponent = 0) {
794
+ invariant$1(typeof s === "string", `GetOperands should have been called with a string`);
795
+ const n = ToNumber(s);
796
+ invariant$1(n.isFinite(), "n should be finite");
797
+ let dp = s.indexOf(".");
798
+ let iv;
799
+ let f;
800
+ let v;
801
+ let fv = "";
802
+ if (dp === -1) {
803
+ iv = n;
804
+ f = ZERO$1;
805
+ v = 0;
806
+ } else {
807
+ iv = s.slice(0, dp);
808
+ fv = s.slice(dp, s.length);
809
+ f = ToNumber(fv);
810
+ v = fv.length;
811
+ }
812
+ const i = ToNumber(iv).abs();
813
+ let w;
814
+ let t;
815
+ if (!f.isZero()) {
816
+ const ft = fv.replace(/0+$/, "");
817
+ w = ft.length;
818
+ t = ToNumber(ft);
819
+ } else {
820
+ w = 0;
821
+ t = ZERO$1;
822
+ }
823
+ return {
824
+ Number: n,
825
+ IntegerDigits: i.lessThanOrEqualTo(Number.MAX_SAFE_INTEGER) && i.greaterThanOrEqualTo(-Number.MAX_SAFE_INTEGER) ? i.toNumber() : i.toString(),
826
+ NumberOfFractionDigits: v,
827
+ NumberOfFractionDigitsWithoutTrailing: w,
828
+ FractionDigits: f.toNumber(),
829
+ FractionDigitsWithoutTrailing: t.toNumber(),
830
+ CompactExponent: exponent
831
+ };
832
+ }
833
+ //#endregion
834
+ //#region packages/ecma402-abstract/PluralRules/ResolvePlural.js
835
+ /**
836
+ * ResolvePluralInternal ( pluralRules, n )
837
+ *
838
+ * Internal version of ResolvePlural that returns both the formatted string and plural category.
839
+ * This is needed for selectRange, which must compare formatted strings to determine if the
840
+ * start and end values are identical.
841
+ *
842
+ * The formatted string is obtained by applying the number formatting options (digit options)
843
+ * from the PluralRules object to the input number. This ensures that formatting-sensitive
844
+ * plural rules work correctly (e.g., rules that depend on visible fraction digits).
845
+ *
846
+ * @param pl - An initialized PluralRules object
847
+ * @param n - Mathematical value to resolve
848
+ * @returns Record containing the formatted string and plural category
849
+ */
850
+ function ResolvePluralInternal(pl, n, { getInternalSlots, PluralRuleSelect }) {
851
+ const internalSlots = getInternalSlots(pl);
852
+ invariant$1(Type(internalSlots) === "Object", "pl has to be an object");
853
+ invariant$1("initializedPluralRules" in internalSlots, "pluralrules must be initialized");
854
+ if (!n.isFinite()) return {
855
+ formattedString: String(n),
856
+ pluralCategory: "other"
857
+ };
858
+ const { locale, type, notation } = internalSlots;
859
+ const s = FormatNumericToString(internalSlots, n).formattedString;
860
+ let exponent = 0;
861
+ if (notation === "compact" && !n.isZero()) {
862
+ if (internalSlots.dataLocaleData?.numbers) try {
863
+ exponent = ComputeExponentForMagnitude(internalSlots, new Decimal(Math.floor(Math.log10(Math.abs(n.toNumber())))));
864
+ } catch {
865
+ exponent = 0;
866
+ }
867
+ }
868
+ return {
869
+ formattedString: s,
870
+ pluralCategory: PluralRuleSelect(locale, type, n, GetOperands(s, exponent))
871
+ };
872
+ }
873
+ /**
874
+ * http://ecma-international.org/ecma-402/7.0/index.html#sec-resolveplural
875
+ * @param pl
876
+ * @param n
877
+ * @param PluralRuleSelect Has to pass in bc it's implementation-specific
878
+ */
879
+ function ResolvePlural(pl, n, { getInternalSlots, PluralRuleSelect }) {
880
+ return ResolvePluralInternal(pl, n, {
881
+ getInternalSlots,
882
+ PluralRuleSelect
883
+ }).pluralCategory;
884
+ }
885
+ //#endregion
886
+ //#region packages/ecma402-abstract/PluralRules/ResolvePluralRange.js
887
+ /**
888
+ * ResolvePluralRange ( pluralRules, x, y )
889
+ *
890
+ * The ResolvePluralRange abstract operation is called with arguments pluralRules (which must be
891
+ * an object initialized as a PluralRules), x (a mathematical value), and y (a mathematical value).
892
+ * It resolves the appropriate plural form for a range by determining the plural forms of both the
893
+ * start and end values, then consulting locale-specific range data.
894
+ *
895
+ * Specification: https://tc39.es/ecma402/#sec-resolvepluralrange
896
+ *
897
+ * @param pluralRules - An initialized PluralRules object
898
+ * @param x - Mathematical value for the range start
899
+ * @param y - Mathematical value for the range end
900
+ * @returns The plural category for the range (zero, one, two, few, many, or other)
901
+ */
902
+ function ResolvePluralRange(pluralRules, x, y, { getInternalSlots, PluralRuleSelect, PluralRuleSelectRange }) {
903
+ if (!x.isFinite() || !y.isFinite()) throw new RangeError("selectRange requires start and end values to be finite numbers");
904
+ const internalSlots = getInternalSlots(pluralRules);
905
+ invariant$1(Type(internalSlots) === "Object", "pluralRules has to be an object");
906
+ invariant$1("initializedPluralRules" in internalSlots, "pluralrules must be initialized");
907
+ const xp = ResolvePluralInternal(pluralRules, x, {
908
+ getInternalSlots,
909
+ PluralRuleSelect
910
+ });
911
+ const yp = ResolvePluralInternal(pluralRules, y, {
912
+ getInternalSlots,
913
+ PluralRuleSelect
914
+ });
915
+ if (xp.formattedString === yp.formattedString) return xp.pluralCategory;
916
+ const { locale, type } = internalSlots;
917
+ return PluralRuleSelectRange(locale, type, xp.pluralCategory, yp.pluralCategory);
918
+ }
919
+ //#endregion
920
+ //#region packages/intl-pluralrules/get_internal_slots.ts
921
+ const internalSlotMap = /* @__PURE__ */ new WeakMap();
922
+ function getInternalSlots(x) {
923
+ let internalSlots = internalSlotMap.get(x);
924
+ if (!internalSlots) {
925
+ internalSlots = Object.create(null);
926
+ internalSlotMap.set(x, internalSlots);
927
+ }
928
+ return internalSlots;
929
+ }
930
+ //#endregion
931
+ //#region packages/intl-pluralrules/index.ts
932
+ function validateInstance(instance, method) {
933
+ if (!(instance instanceof PluralRules)) throw new TypeError(`Method Intl.PluralRules.prototype.${method} called on incompatible receiver ${String(instance)}`);
11
934
  }
12
935
  /**
13
936
  * http://ecma-international.org/ecma-402/7.0/index.html#sec-pluralruleselect
@@ -17,7 +940,6 @@ function validateInstance(instance, method) {
17
940
  * @param param3
18
941
  */
19
942
  function PluralRuleSelect(locale, type, _n, { IntegerDigits, NumberOfFractionDigits, FractionDigits, CompactExponent }) {
20
- // Always pass a string to the compiled function to preserve precision for huge numbers
21
943
  return PluralRules.localeData[locale].fn(NumberOfFractionDigits ? `${IntegerDigits}.${FractionDigits}` : String(IntegerDigits), type === "ordinal", CompactExponent);
22
944
  }
23
945
  /**
@@ -43,26 +965,13 @@ function PluralRuleSelect(locale, type, _n, { IntegerDigits, NumberOfFractionDig
43
965
  */
44
966
  function PluralRuleSelectRange(locale, type, xp, yp) {
45
967
  const localeData = PluralRules.localeData[locale];
46
- if (!localeData || !localeData.pluralRanges) {
47
- // Fallback: If no range data is available, return the end category.
48
- // This is a reasonable default as the end value often determines the plural form.
49
- return yp;
50
- }
51
- // Construct lookup key: "start_end" (e.g., "one_other", "few_many")
968
+ if (!localeData || !localeData.pluralRanges) return yp;
52
969
  const key = `${xp}_${yp}`;
53
- // Select the appropriate range data based on type (cardinal vs ordinal)
54
- const rangeData = type === "ordinal" ? localeData.pluralRanges.ordinal : localeData.pluralRanges.cardinal;
55
- // Look up the result, falling back to end category if not found
56
- return rangeData?.[key] ?? yp;
970
+ return (type === "ordinal" ? localeData.pluralRanges.ordinal : localeData.pluralRanges.cardinal)?.[key] ?? yp;
57
971
  }
58
- export class PluralRules {
972
+ var PluralRules = class PluralRules {
59
973
  constructor(locales, options) {
60
- // test262/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js
61
- // Cannot use `new.target` bc of IE11 & TS transpiles it to something else
62
- const newTarget = this && this instanceof PluralRules ? this.constructor : void 0;
63
- if (!newTarget) {
64
- throw new TypeError("Intl.PluralRules must be called with 'new'");
65
- }
974
+ if (!(this && this instanceof PluralRules ? this.constructor : void 0)) throw new TypeError("Intl.PluralRules must be called with 'new'");
66
975
  return InitializePluralRules(this, locales, options, {
67
976
  availableLocales: PluralRules.availableLocales,
68
977
  relevantExtensionKeys: PluralRules.relevantExtensionKeys,
@@ -85,17 +994,13 @@ export class PluralRules {
85
994
  "maximumSignificantDigits"
86
995
  ].forEach((field) => {
87
996
  const val = internalSlots[field];
88
- if (val !== undefined) {
89
- opts[field] = val;
90
- }
997
+ if (val !== void 0) opts[field] = val;
91
998
  });
92
999
  opts.pluralCategories = [...PluralRules.localeData[opts.locale].categories[opts.type]];
93
1000
  return opts;
94
1001
  }
95
1002
  select(val) {
96
1003
  validateInstance(this, "select");
97
- // Use ToIntlMathematicalValue which handles bigint per ECMA-402
98
- // https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.select
99
1004
  const n = ToIntlMathematicalValue(val);
100
1005
  return ResolvePlural(this, n, {
101
1006
  getInternalSlots,
@@ -138,19 +1043,9 @@ export class PluralRules {
138
1043
  */
139
1044
  selectRange(start, end) {
140
1045
  validateInstance(this, "selectRange");
141
- // Spec: https://tc39.es/ecma402/#sec-intl.pluralrules.prototype.selectrange
142
- // 1. Let pr be the this value.
143
- // 2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
144
- // (Validation is done by validateInstance above)
145
- // 3. If start is undefined or end is undefined, throw a TypeError exception.
146
- if (start === undefined || end === undefined) {
147
- throw new TypeError("selectRange requires both start and end arguments");
148
- }
149
- // 4. Let x be ? ToIntlMathematicalValue(start).
1046
+ if (start === void 0 || end === void 0) throw new TypeError("selectRange requires both start and end arguments");
150
1047
  const x = ToIntlMathematicalValue(start);
151
- // 5. Let y be ? ToIntlMathematicalValue(end).
152
1048
  const y = ToIntlMathematicalValue(end);
153
- // 6. Return ? ResolvePluralRange(pr, x, y).
154
1049
  return ResolvePluralRange(this, x, y, {
155
1050
  getInternalSlots,
156
1051
  PluralRuleSelect,
@@ -167,32 +1062,36 @@ export class PluralRules {
167
1062
  for (const { data: d, locale } of data) {
168
1063
  PluralRules.localeData[locale] = d;
169
1064
  PluralRules.availableLocales.add(locale);
170
- if (!PluralRules.__defaultLocale) {
171
- PluralRules.__defaultLocale = locale;
172
- }
1065
+ if (!PluralRules.__defaultLocale) PluralRules.__defaultLocale = locale;
173
1066
  }
174
1067
  }
175
- static localeData = {};
176
- static availableLocales = new Set();
177
- static __defaultLocale = "";
1068
+ static {
1069
+ this.localeData = {};
1070
+ }
1071
+ static {
1072
+ this.availableLocales = /* @__PURE__ */ new Set();
1073
+ }
1074
+ static {
1075
+ this.__defaultLocale = "";
1076
+ }
178
1077
  static getDefaultLocale() {
179
1078
  return PluralRules.__defaultLocale;
180
1079
  }
181
- static relevantExtensionKeys = [];
182
- static polyfilled = true;
183
- }
184
- try {
185
- // IE11 does not have Symbol
186
- if (typeof Symbol !== "undefined") {
187
- Object.defineProperty(PluralRules.prototype, Symbol.toStringTag, {
188
- value: "Intl.PluralRules",
189
- writable: false,
190
- enumerable: false,
191
- configurable: true
192
- });
1080
+ static {
1081
+ this.relevantExtensionKeys = [];
1082
+ }
1083
+ static {
1084
+ this.polyfilled = true;
193
1085
  }
1086
+ };
1087
+ try {
1088
+ if (typeof Symbol !== "undefined") Object.defineProperty(PluralRules.prototype, Symbol.toStringTag, {
1089
+ value: "Intl.PluralRules",
1090
+ writable: false,
1091
+ enumerable: false,
1092
+ configurable: true
1093
+ });
194
1094
  try {
195
- // https://github.com/tc39/test262/blob/master/test/intl402/PluralRules/length.js
196
1095
  Object.defineProperty(PluralRules, "length", {
197
1096
  value: 0,
198
1097
  writable: false,
@@ -200,14 +1099,12 @@ try {
200
1099
  configurable: true
201
1100
  });
202
1101
  } catch {}
203
- // https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/length.js
204
1102
  Object.defineProperty(PluralRules.prototype.constructor, "length", {
205
1103
  value: 0,
206
1104
  writable: false,
207
1105
  enumerable: false,
208
1106
  configurable: true
209
1107
  });
210
- // https://github.com/tc39/test262/blob/master/test/intl402/RelativeTimeFormat/constructor/supportedLocalesOf/length.js
211
1108
  Object.defineProperty(PluralRules.supportedLocalesOf, "length", {
212
1109
  value: 1,
213
1110
  writable: false,
@@ -221,3 +1118,7 @@ try {
221
1118
  configurable: true
222
1119
  });
223
1120
  } catch {}
1121
+ //#endregion
1122
+ export { PluralRules };
1123
+
1124
+ //# sourceMappingURL=index.js.map