ztxkui 3.4.14 → 3.4.15
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/dist/hooks/useFormatter.js +35 -3
- package/package.json +1 -1
|
@@ -64,12 +64,44 @@ function useFormatter(formatterType, currencySymbol) {
|
|
|
64
64
|
precision: precision,
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
+
function formatCurrency(n) {
|
|
68
|
+
if (n != null) {
|
|
69
|
+
var _n = n.toString();
|
|
70
|
+
var pointIndex = _n.indexOf('.');
|
|
71
|
+
var pointAfterNum = '';
|
|
72
|
+
if (pointIndex !== -1) {
|
|
73
|
+
n = _n.slice(0, pointIndex);
|
|
74
|
+
pointAfterNum = _n.slice(pointIndex);
|
|
75
|
+
}
|
|
76
|
+
var res = '';
|
|
77
|
+
var s = n.toString();
|
|
78
|
+
var length_1 = s.length;
|
|
79
|
+
for (var i = length_1 - 1; i >= 0; i--) {
|
|
80
|
+
var j = length_1 - i;
|
|
81
|
+
if (j % 3 === 0) {
|
|
82
|
+
if (i === 0) {
|
|
83
|
+
res = s[i] + res;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
res = ',' + s[i] + res;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
res = s[i] + res;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return res + pointAfterNum;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
return n;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
67
99
|
export function getFormatter(formatterType, currencySymbol) {
|
|
68
100
|
if (currencySymbol === void 0) { currencySymbol = '$'; }
|
|
69
101
|
if (formatterType === 'currency') {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
102
|
+
// let formatterFn: IFormatterFuc = (value) =>
|
|
103
|
+
// `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
104
|
+
var formatterFn = function (value) { return formatCurrency(value); };
|
|
73
105
|
var parserFn = function (value) { return value.replace(/(,*)/g, ''); };
|
|
74
106
|
return {
|
|
75
107
|
formatter: formatterFn,
|