@osimatic/helpers-js 1.0.61 → 1.0.62

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/number.js +19 -32
  2. package/package.json +1 -1
package/number.js CHANGED
@@ -1,10 +1,6 @@
1
1
 
2
2
  Number.prototype.format = Number.prototype.format || function(nbDecimal, locale) {
3
- nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
4
- return new Intl.NumberFormat(locale, {
5
- minimumFractionDigits: nbDecimal,
6
- maximumFractionDigits: nbDecimal
7
- }).format(this);
3
+ return Number.format(this, nbDecimal, locale);
8
4
  }
9
5
 
10
6
  if (!Number.format) {
@@ -32,32 +28,44 @@ Number.prototype.formatForDisplay = Number.prototype.formatForDisplay || functio
32
28
  };
33
29
 
34
30
  Number.prototype.formatCurrency = Number.prototype.formatCurrency || function(currency, nbDecimal, locale) {
31
+ return Number.formatCurrency(this, currency, nbDecimal, locale);
32
+ }
33
+ Number.formatCurrency = Number.formatCurrency || function(number, currency, nbDecimal, locale) {
35
34
  nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
36
35
  return new Intl.NumberFormat(locale, {
37
36
  style: 'currency',
38
37
  currency: currency,
39
38
  minimumFractionDigits: nbDecimal,
40
39
  maximumFractionDigits: nbDecimal
41
- }).format(this);
40
+ }).format(number);
42
41
  }
43
42
 
44
43
  Number.prototype.formatPercent = Number.prototype.formatPercent || function(nbDecimal, locale) {
44
+ return Number.formatPercent(this, nbDecimal, locale);
45
+ }
46
+ Number.formatPercent = Number.formatPercent || function(number, nbDecimal, locale) {
45
47
  nbDecimal = (typeof nbDecimal != 'undefined'?nbDecimal:2);
46
48
  return new Intl.NumberFormat(locale, {
47
49
  style: 'percent',
48
50
  minimumFractionDigits: nbDecimal,
49
51
  maximumFractionDigits: nbDecimal
50
- }).format(this);
52
+ }).format(number);
51
53
  }
52
54
 
53
- Number.prototype.padLeft2 = Number.prototype.padLeft2 || function(n) {
54
- return this > 9 ? "" + this : "0" + this;
55
+ Number.prototype.padLeft2 = Number.prototype.padLeft2 || function() {
56
+ return Number.padLeft2(this);
57
+ }
58
+ Number.padLeft2 = Number.padLeft2 || function(n) {
59
+ return n > 9 ? "" + n : "0" + n;
55
60
  }
56
61
 
57
62
  Number.prototype.roundDecimal = Number.prototype.roundDecimal || function(precision) {
63
+ return Number.roundDecimal(this, precision);
64
+ }
65
+ Number.roundDecimal = Number.roundDecimal || function(number, precision) {
58
66
  precision = precision || 2;
59
- var tmp = Math.pow(10, precision);
60
- return Math.round(this*tmp) / tmp;
67
+ let tmp = Math.pow(10, precision);
68
+ return Math.round(number*tmp) / tmp;
61
69
  }
62
70
 
63
71
  if (!Number.random) {
@@ -65,24 +73,3 @@ if (!Number.random) {
65
73
  return Math.floor(Math.random() * (max - min + 1)) + min;
66
74
  };
67
75
  }
68
-
69
- /** @deprecated */
70
- Number.prototype.formatAsString = function(locale, minimumFractionDigits) {
71
- minimumFractionDigits = (typeof minimumFractionDigits != 'undefined'?minimumFractionDigits:0);
72
- return new Intl.NumberFormat(locale, {minimumFractionDigits: minimumFractionDigits}).format(this);
73
- };
74
- /** @deprecated */
75
- Number.prototype.formatAsCurrency = function(locale, currency, nbFractionDigits) {
76
- nbFractionDigits = (typeof nbFractionDigits != 'undefined'?nbFractionDigits:2);
77
- return new Intl.NumberFormat(locale, {
78
- style: 'currency',
79
- currency: 'EUR',
80
- minimumFractionDigits: nbFractionDigits,
81
- maximumFractionDigits: nbFractionDigits
82
- }).format(this);
83
- };
84
- /** @deprecated */
85
- Number.prototype.formatAsPercent = function(locale, minimumFractionDigits) {
86
- minimumFractionDigits = (typeof minimumFractionDigits != 'undefined'?minimumFractionDigits:0);
87
- return new Intl.NumberFormat(locale, {style: 'percent', minimumFractionDigits:minimumFractionDigits}).format(this);
88
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.0.61",
3
+ "version": "1.0.62",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"