@formatjs/intl-pluralrules 6.0.4 → 6.0.5

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 (2) hide show
  1. package/package.json +5 -5
  2. package/polyfill.iife.js +56 -11
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@formatjs/intl-pluralrules",
3
3
  "description": "Polyfill for Intl.PluralRules",
4
- "version": "6.0.4",
4
+ "version": "6.0.5",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
7
  "type": "module",
@@ -16,12 +16,12 @@
16
16
  "dependencies": {
17
17
  "decimal.js": "^10.4.3",
18
18
  "tslib": "^2.8.0",
19
- "@formatjs/intl-localematcher": "0.7.2",
20
- "@formatjs/ecma402-abstract": "3.0.3"
19
+ "@formatjs/ecma402-abstract": "3.0.4",
20
+ "@formatjs/intl-localematcher": "0.7.2"
21
21
  },
22
22
  "devDependencies": {
23
- "@formatjs/intl-locale": "5.0.4",
24
- "@formatjs/intl-getcanonicallocales": "3.0.3"
23
+ "@formatjs/intl-locale": "5.0.5",
24
+ "@formatjs/intl-getcanonicallocales": "3.0.4"
25
25
  },
26
26
  "bugs": "https://github.com/formatjs/formatjs/issues",
27
27
  "gitHead": "a7842673d8ad205171ad7c8cb8bb2f318b427c0c",
package/polyfill.iife.js CHANGED
@@ -2808,6 +2808,11 @@
2808
2808
  return r2;
2809
2809
  }
2810
2810
 
2811
+ // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/decimal-cache.js
2812
+ var getPowerOf10 = memoize(function(exponent) {
2813
+ return Decimal.pow(10, exponent);
2814
+ });
2815
+
2811
2816
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ComputeExponentForMagnitude.js
2812
2817
  Decimal.set({
2813
2818
  toExpPos: 100
@@ -2848,10 +2853,10 @@
2848
2853
  toExpPos: 100
2849
2854
  });
2850
2855
  function ToRawFixedFn(n, f) {
2851
- return n.times(Decimal.pow(10, -f));
2856
+ return n.times(getPowerOf10(-f));
2852
2857
  }
2853
2858
  function findN1R1(x, f, roundingIncrement) {
2854
- var nx = x.times(Decimal.pow(10, f)).floor();
2859
+ var nx = x.times(getPowerOf10(f)).floor();
2855
2860
  var n1 = nx.div(roundingIncrement).floor().times(roundingIncrement);
2856
2861
  var r1 = ToRawFixedFn(n1, f);
2857
2862
  return {
@@ -2860,7 +2865,7 @@
2860
2865
  };
2861
2866
  }
2862
2867
  function findN2R2(x, f, roundingIncrement) {
2863
- var nx = x.times(Decimal.pow(10, f)).ceil();
2868
+ var nx = x.times(getPowerOf10(f)).ceil();
2864
2869
  var n2 = nx.div(roundingIncrement).ceil().times(roundingIncrement);
2865
2870
  var r2 = ToRawFixedFn(n2, f);
2866
2871
  return {
@@ -2920,14 +2925,34 @@
2920
2925
 
2921
2926
  // node_modules/.aspect_rules_js/@formatjs+ecma402-abstract@0.0.0/node_modules/@formatjs/ecma402-abstract/NumberFormat/ToRawPrecision.js
2922
2927
  function findN1E1R1(x, p) {
2923
- var maxN1 = Decimal.pow(10, p);
2924
- var minN1 = Decimal.pow(10, p - 1);
2928
+ var maxN1 = getPowerOf10(p);
2929
+ var minN1 = getPowerOf10(p - 1);
2930
+ var log10x = x.log(10);
2931
+ var e1 = log10x.floor();
2932
+ var divisor = getPowerOf10(e1.minus(p).plus(1));
2933
+ var n1 = x.div(divisor).floor();
2934
+ var r1 = n1.times(divisor);
2935
+ if (n1.greaterThanOrEqualTo(maxN1)) {
2936
+ e1 = e1.plus(1);
2937
+ var newDivisor = getPowerOf10(e1.minus(p).plus(1));
2938
+ n1 = x.div(newDivisor).floor();
2939
+ r1 = n1.times(newDivisor);
2940
+ } else if (n1.lessThan(minN1)) {
2941
+ e1 = e1.minus(1);
2942
+ var newDivisor = getPowerOf10(e1.minus(p).plus(1));
2943
+ n1 = x.div(newDivisor).floor();
2944
+ r1 = n1.times(newDivisor);
2945
+ }
2946
+ if (r1.lessThanOrEqualTo(x) && n1.lessThan(maxN1) && n1.greaterThanOrEqualTo(minN1)) {
2947
+ return { n1, e1, r1 };
2948
+ }
2925
2949
  var maxE1 = x.div(minN1).log(10).plus(p).minus(1).ceil();
2926
2950
  var currentE1 = maxE1;
2927
2951
  while (true) {
2928
- var currentN1 = x.div(Decimal.pow(10, currentE1.minus(p).plus(1))).floor();
2952
+ var currentDivisor = getPowerOf10(currentE1.minus(p).plus(1));
2953
+ var currentN1 = x.div(currentDivisor).floor();
2929
2954
  if (currentN1.lessThan(maxN1) && currentN1.greaterThanOrEqualTo(minN1)) {
2930
- var currentR1 = currentN1.times(Decimal.pow(10, currentE1.minus(p).plus(1)));
2955
+ var currentR1 = currentN1.times(currentDivisor);
2931
2956
  if (currentR1.lessThanOrEqualTo(x)) {
2932
2957
  return {
2933
2958
  n1: currentN1,
@@ -2940,14 +2965,34 @@
2940
2965
  }
2941
2966
  }
2942
2967
  function findN2E2R2(x, p) {
2943
- var maxN2 = Decimal.pow(10, p);
2944
- var minN2 = Decimal.pow(10, p - 1);
2968
+ var maxN2 = getPowerOf10(p);
2969
+ var minN2 = getPowerOf10(p - 1);
2970
+ var log10x = x.log(10);
2971
+ var e2 = log10x.floor();
2972
+ var divisor = getPowerOf10(e2.minus(p).plus(1));
2973
+ var n2 = x.div(divisor).ceil();
2974
+ var r2 = n2.times(divisor);
2975
+ if (n2.greaterThanOrEqualTo(maxN2)) {
2976
+ e2 = e2.plus(1);
2977
+ var newDivisor = getPowerOf10(e2.minus(p).plus(1));
2978
+ n2 = x.div(newDivisor).ceil();
2979
+ r2 = n2.times(newDivisor);
2980
+ } else if (n2.lessThan(minN2)) {
2981
+ e2 = e2.minus(1);
2982
+ var newDivisor = getPowerOf10(e2.minus(p).plus(1));
2983
+ n2 = x.div(newDivisor).ceil();
2984
+ r2 = n2.times(newDivisor);
2985
+ }
2986
+ if (r2.greaterThanOrEqualTo(x) && n2.lessThan(maxN2) && n2.greaterThanOrEqualTo(minN2)) {
2987
+ return { n2, e2, r2 };
2988
+ }
2945
2989
  var minE2 = x.div(maxN2).log(10).plus(p).minus(1).floor();
2946
2990
  var currentE2 = minE2;
2947
2991
  while (true) {
2948
- var currentN2 = x.div(Decimal.pow(10, currentE2.minus(p).plus(1))).ceil();
2992
+ var currentDivisor = getPowerOf10(currentE2.minus(p).plus(1));
2993
+ var currentN2 = x.div(currentDivisor).ceil();
2949
2994
  if (currentN2.lessThan(maxN2) && currentN2.greaterThanOrEqualTo(minN2)) {
2950
- var currentR2 = currentN2.times(Decimal.pow(10, currentE2.minus(p).plus(1)));
2995
+ var currentR2 = currentN2.times(currentDivisor);
2951
2996
  if (currentR2.greaterThanOrEqualTo(x)) {
2952
2997
  return {
2953
2998
  n2: currentN2,