investira.sdk 2.4.25 → 2.4.26
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/lib/utils/formats.js +58 -0
- package/package.json +4 -4
package/lib/utils/formats.js
CHANGED
|
@@ -144,6 +144,7 @@ const formats = {
|
|
|
144
144
|
|
|
145
145
|
let xTime = '';
|
|
146
146
|
const localeData = moment.localeData();
|
|
147
|
+
//@ts-ignore
|
|
147
148
|
xTime = localeData.relativeTime(pValue, false, pKey);
|
|
148
149
|
|
|
149
150
|
return xTime;
|
|
@@ -381,3 +382,60 @@ const formats = {
|
|
|
381
382
|
return xHostPath;
|
|
382
383
|
}
|
|
383
384
|
};
|
|
385
|
+
|
|
386
|
+
module.exports = formats;
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Retorna o número simplificado
|
|
390
|
+
*
|
|
391
|
+
* @param {*} pDIM Dimensão
|
|
392
|
+
* @param {*} pValue Valor a ser simplificado
|
|
393
|
+
* @param {number} [pDecimals=2] Quantidade máxima de casas decimais
|
|
394
|
+
* @param {boolean} [pShowCurrency=false] Se exibe o símbolo da moeda do país definido em formats.CURRENCY.
|
|
395
|
+
* @returns {String} Valor formatado de forma simplificada
|
|
396
|
+
*/
|
|
397
|
+
const pvSimplify = (pDIM, pValue, pDecimals = 2, pShowCurrency = false, pBase = null) => {
|
|
398
|
+
const xOptions = {
|
|
399
|
+
minimumFractionDigits: 0,
|
|
400
|
+
maximumFractionDigits: pDecimals,
|
|
401
|
+
style: pShowCurrency ? 'currency' : 'decimal',
|
|
402
|
+
currencyDisplay: 'symbol',
|
|
403
|
+
currency: formats.CURRENCY
|
|
404
|
+
};
|
|
405
|
+
//Limite máximo do array
|
|
406
|
+
const xMaxLenght = pDIM.VALUES.length * pDIM.BASE;
|
|
407
|
+
//Converte para número e arredonda
|
|
408
|
+
let xValueRounded = toNumber(pValue);
|
|
409
|
+
//Salva o sinal
|
|
410
|
+
const xSign = Math.sign(xValueRounded) || 1;
|
|
411
|
+
//Retira o sinal
|
|
412
|
+
xValueRounded = Math.abs(xValueRounded);
|
|
413
|
+
|
|
414
|
+
//Tamanho de números inteiros
|
|
415
|
+
let xIntLength = trunc(xValueRounded, 0).toString().length - 1;
|
|
416
|
+
if (xIntLength == 0 && xValueRounded != 0) {
|
|
417
|
+
return round(xValueRounded, pDecimals).toLocaleString(formats.LOCALE, xOptions);
|
|
418
|
+
} else if (xIntLength > xMaxLenght) {
|
|
419
|
+
//Limita simplify a quantidade máxima de dimensões
|
|
420
|
+
xIntLength = xMaxLenght;
|
|
421
|
+
}
|
|
422
|
+
//Calcula quantidade de dígitos que serão reduzidos
|
|
423
|
+
let xReducer = 0;
|
|
424
|
+
if (pBase != null) {
|
|
425
|
+
const xIndex = formats.DIM_NUMBER.VALUES.indexOf(String(pBase).toLocaleLowerCase());
|
|
426
|
+
if (xIndex > -1) {
|
|
427
|
+
xReducer = 3 * xIndex;
|
|
428
|
+
}
|
|
429
|
+
} else {
|
|
430
|
+
xReducer = xIntLength - (xIntLength % pDIM.BASE);
|
|
431
|
+
}
|
|
432
|
+
//Calcula parte inteira
|
|
433
|
+
let xValueInt = xValueRounded / Math.pow(10, xReducer);
|
|
434
|
+
//Adiciona o sufixo
|
|
435
|
+
let xSuf = ' ' + pDIM.VALUES[trunc(xReducer / pDIM.BASE, 0)];
|
|
436
|
+
//Restaura o sinal
|
|
437
|
+
xValueInt *= xSign;
|
|
438
|
+
//Configura formatação
|
|
439
|
+
//@ts-ignore
|
|
440
|
+
return xValueInt.toLocaleString(formats.LOCALE, xOptions) + xSuf.trimEnd();
|
|
441
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "investira.sdk",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.26",
|
|
4
4
|
"author": "Investira",
|
|
5
5
|
"description": "Investira SDK",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"type": "commonjs",
|
|
8
8
|
"registry": true,
|
|
9
|
-
"raw": "investira.sdk@2.4.
|
|
9
|
+
"raw": "investira.sdk@2.4.26",
|
|
10
10
|
"escapedName": "investira.sdk",
|
|
11
|
-
"rawSpec": "2.4.
|
|
11
|
+
"rawSpec": "2.4.26",
|
|
12
12
|
"saveSpec": null,
|
|
13
|
-
"fetchSpec": "2.4.
|
|
13
|
+
"fetchSpec": "2.4.26",
|
|
14
14
|
"homepage": "https://investira.com.br/",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=11.11.0 <=18.12",
|