-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (48 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Mask = /** @class */ (function () {
function Mask() {
}
/**
* Formata o valor passada de acordo com a máscara fornecida
* @param value valor a ser mascarado
* @param valueMask máscara
* @returns string
*/
Mask.format = function (value, valueMask) {
try {
var currentValue = value.toString().replace(/\-|\.|\/|\(|\)| /g, '');
var valuePosition = 0;
var valueMasked = '';
var totalChars = currentValue.length;
var maskItem = new RegExp(/\-|\.|\/|\(|\)| /g);
for (var i = 0; i <= totalChars; i++) {
if (maskItem.test(valueMask.charAt(i))) {
valueMasked += valueMask.charAt(i);
totalChars++;
}
else {
valueMasked += currentValue.charAt(valuePosition);
valuePosition++;
}
}
return valueMasked;
}
catch (error) {
return valueMask;
}
};
/**
* Remove uma máscara aplicada
* @param value valor em string
* @returns number
*/
Mask.removeMask = function (value) {
if (!value)
value = 0;
return parseInt(value.toString().replace(/\D/g, ''));
};
return Mask;
}());
exports.default = Mask;
//# sourceMappingURL=index.js.map