applay-utils 1.8.7 → 1.8.9
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/package.json +1 -1
- package/utils/tools.js +45 -0
package/package.json
CHANGED
package/utils/tools.js
CHANGED
|
@@ -46,6 +46,51 @@ var tools = {
|
|
|
46
46
|
client.end()
|
|
47
47
|
})
|
|
48
48
|
}),
|
|
49
|
+
'convert': (data, tipo, param1, param2, param3)=>{
|
|
50
|
+
//convert
|
|
51
|
+
var moeda = param1;
|
|
52
|
+
var digitos = param2;
|
|
53
|
+
var max = param3 || 20;
|
|
54
|
+
var locale = 'pt-BR'
|
|
55
|
+
if (typeof param1 == 'number') {
|
|
56
|
+
digitos = param1;
|
|
57
|
+
moeda = null;
|
|
58
|
+
}
|
|
59
|
+
if (typeof param2 == 'number') {
|
|
60
|
+
max = param2;
|
|
61
|
+
}
|
|
62
|
+
if (tipo == 'number' && moeda == 'us') {
|
|
63
|
+
return parseFloat(data);
|
|
64
|
+
}
|
|
65
|
+
if (tipo == 'number' && moeda != 'us') {
|
|
66
|
+
return parseFloat(('' + (data || '0')).split('.').join('').replace(',', '.').replace('R$', '').trim());
|
|
67
|
+
}
|
|
68
|
+
if (moeda == 'br') { moeda = 'R$'; locale = 'pt-BR'; digitos = 2; }
|
|
69
|
+
if (moeda == 'virgula') { moeda = ''; locale = 'pt-BR'; digitos = 2; }
|
|
70
|
+
if (moeda == 'us' || moeda == '$') { moeda = '$'; locale = 'en-US' }
|
|
71
|
+
if (moeda == 'value') { moeda = false; locale = 'en-US' }
|
|
72
|
+
|
|
73
|
+
if (tipo == 'valor' || tipo == 'texto') {
|
|
74
|
+
var options = { maximumFractionDigits: max };
|
|
75
|
+
if (digitos) {
|
|
76
|
+
options.minimumFractionDigits = digitos;
|
|
77
|
+
}
|
|
78
|
+
var result = '' + data;
|
|
79
|
+
|
|
80
|
+
if (locale == 'pt-BR') {
|
|
81
|
+
if (!data) { data = 0; }
|
|
82
|
+
result = data.toLocaleString(locale, options);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (moeda) {
|
|
86
|
+
result = moeda + ' ' + result;
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
},
|
|
93
|
+
'validation': (data, rules) => rules.every(e => Object.keys(data).indexOf(e) >= 0 || data[e] == ''),
|
|
49
94
|
/**
|
|
50
95
|
* @param {number} milliseconds Valor em milisegundos para ser convertido
|
|
51
96
|
* @returns Retorna uma string no formato **0h 0m 0s** ou retorna **--** em caso de erro
|