investira.sdk 2.2.12 → 2.2.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/CHANGELOG.md CHANGED
@@ -437,3 +437,16 @@ O contrutor para a criação das mensagem foi alterado.
437
437
  # 2.2.12
438
438
 
439
439
  - [investira.data] Atualização
440
+
441
+ # 2.2.13
442
+
443
+ - [investira.data] Controle de vigência do feriado
444
+
445
+ # 2.2.14
446
+
447
+ - [investira.data] Controle de vigência do feriado
448
+
449
+ # 2.2.15
450
+
451
+ - [numbers] Aumento da precisão do trunc e do round
452
+ - [formats] Substituicão do trimRight por trimEnd no friendlyNumber
@@ -89,7 +89,7 @@ test('\ndates addWorkingDays', t => {
89
89
 
90
90
  test('\ndates weekNames', t => {
91
91
  dates.locale('pt-BR');
92
- t.equal(dates.weekNames()[0], 'Domingo');
92
+ t.equal(dates.weekNames()[0], 'domingo');
93
93
  dates.locale('en-US');
94
94
  t.equal(dates.weekNames()[0], 'Sunday');
95
95
  t.end();
@@ -126,6 +126,9 @@ test('\ndates workingDaysBetween', t => {
126
126
  xData1 = dates.toDate('2019-04-30');
127
127
  xData2 = dates.toDate('2019-05-01');
128
128
  t.equal(dates.workingDaysBetween(xData1, xData2), 0);
129
+ // xData1 = dates.toDate('1988-04-20');
130
+ // xData2 = dates.toDate('1988-04-21');
131
+ // t.equal(dates.workingDaysBetween(xData1, xData2), 0);
129
132
  xData1 = dates.toDate('2019-04-30');
130
133
  xData2 = dates.toDate('2019-05-02');
131
134
  t.equal(dates.workingDaysBetween(xData1, xData2), 1);
@@ -14,26 +14,24 @@ test('\nformats.formatPhone', t => {
14
14
  });
15
15
 
16
16
  test('\nformats.friendlyNumber', t => {
17
- t.equal(formats.friendlyNumber(123, 0, true), 'R$123');
18
- t.equal(formats.friendlyNumber(123, 0, false), '123');
19
- t.equal(formats.friendlyNumber(123, 0, true), 'R$123');
17
+ t.equal(formats.friendlyNumber(123, 0, true), `R$${String.fromCharCode(160)}123`);
20
18
  t.equal(formats.friendlyNumber(123, 0, false), '123');
21
19
  t.equal(formats.friendlyNumber(1234567, 0, false), '1 mi');
22
- t.equal(formats.friendlyNumber(1234567, 1, false), '1.2 mi');
23
- t.equal(formats.friendlyNumber(1234567, 2, false), '1.23 mi');
24
- t.equal(formats.friendlyNumber(1234567, 3, false), '1.235 mi');
20
+ t.equal(formats.friendlyNumber(1234567, 1, false), '1,2 mi');
21
+ t.equal(formats.friendlyNumber(1234567, 2, false), '1,23 mi');
22
+ t.equal(formats.friendlyNumber(1234567, 3, false), '1,235 mi');
25
23
  t.equal(formats.friendlyNumber(1234000, 0, false), '1 mi');
26
- t.equal(formats.friendlyNumber(1234000, 1, false), '1.2 mi');
27
- t.equal(formats.friendlyNumber(1234000, 2, false), '1.23 mi');
28
- t.equal(formats.friendlyNumber(1234000, 3, false), '1.234 mi');
29
- t.equal(formats.friendlyNumber(1234000, 0, true), 'R$1 mi');
30
- t.equal(formats.friendlyNumber(1234000, 1, true), 'R$1.2 mi');
31
- t.equal(formats.friendlyNumber(1234000, 2, true), 'R$1.23 mi');
32
- t.equal(formats.friendlyNumber(1234000, 3, true), 'R$1.234 mi');
33
- t.equal(formats.friendlyNumber(-1234000, 3, false), '-1.234 mi');
24
+ t.equal(formats.friendlyNumber(1234000, 1, false), '1,2 mi');
25
+ t.equal(formats.friendlyNumber(1234000, 2, false), '1,23 mi');
26
+ t.equal(formats.friendlyNumber(1234000, 3, false), '1,234 mi');
27
+ t.equal(formats.friendlyNumber(1234000, 0, true), `R$${String.fromCharCode(160)}1 mi`);
28
+ t.equal(formats.friendlyNumber(1234000, 1, true), `R$${String.fromCharCode(160)}1,2 mi`);
29
+ t.equal(formats.friendlyNumber(1234000, 2, true), `R$${String.fromCharCode(160)}1,23 mi`);
30
+ t.equal(formats.friendlyNumber(1234000, 3, true), `R$${String.fromCharCode(160)}1,234 mi`);
31
+ t.equal(formats.friendlyNumber(-1234000, 3, false), '-1,234 mi');
34
32
  t.equal(formats.friendlyNumber(0, 3, false), '0');
35
- t.equal(formats.friendlyNumber(0.9123123424, 2, false), '0.91');
36
- t.equal(formats.friendlyNumber(0.9123123424, 2, true), 'R$0.91');
33
+ t.equal(formats.friendlyNumber(0.9123123424, 2, false), '0,91');
34
+ t.equal(formats.friendlyNumber(0.9123123424, 2, true), `R$${String.fromCharCode(160)}0,91`);
37
35
  t.end();
38
36
  });
39
37
 
@@ -69,8 +69,8 @@ test('\nnumbers mul', t => {
69
69
  t.equal(numbers.mul(4.300000000000001, 5), 21.500000000000004);
70
70
  t.equal(numbers.mul(4.0001, 5.0002), 20.00130002);
71
71
  t.equal(numbers.mul(4.0001, 5.0002), 20.00130002);
72
- t.equal(numbers.mul(2357.12345679, 1234567), 2910026834.6788597); //2910026834.67886 = Se fosse bigDecimal
73
- t.equal(numbers.mul(-0.123456789012345678901, -1230.123456789012345678901), 151.86709206351316); //151.86709206393883 = Se fosse bigDecimal
72
+ t.equal(numbers.mul(2357.12345679, 1234567), 2910026834.6788597);
73
+ t.equal(numbers.mul(-0.123456789012345678901, -1230.123456789012345678901), 151.86709206393846); //151.86709206393883 = Se fosse bigDecimal
74
74
  t.end();
75
75
  });
76
76
 
@@ -50,11 +50,16 @@ const dates = {
50
50
  //Le todos os feriados cadastrados
51
51
  for (let xHolidayString of dataHolidays[xKey].holidays) {
52
52
  //Se for feriado fixo - que se repete todos os anos - configura o ano
53
- if (xHolidayString.startsWith('X')) {
54
- const xMMDD = xHolidayString.substring(4, 12);
55
- for (let x = 1970; x <= 2080; x++) {
56
- xHolidayString = x + xMMDD;
57
- pvLoadDataPush(xHolidays, xKey, xHolidayString);
53
+ if (xHolidayString.hasOwnProperty('date')) {
54
+ const xMMDD = xHolidayString.date.substring(4, 12);
55
+ for (let x = 1970; x <= 2090; x++) {
56
+ //Verifica se esta dentro do período de validade
57
+ if (
58
+ (!xHolidayString.since || x >= xHolidayString.since) &&
59
+ (!xHolidayString.until || x <= xHolidayString.until)
60
+ ) {
61
+ pvLoadDataPush(xHolidays, xKey, x + xMMDD);
62
+ }
58
63
  }
59
64
  } else {
60
65
  pvLoadDataPush(xHolidays, xKey, xHolidayString);
@@ -131,7 +136,7 @@ const dates = {
131
136
  * Isso posto:
132
137
  * Se feriado cair em um dia normalmente não útil(fim de semana), retornará false.
133
138
  * Para saber se é um dia útil considerando fim de semana, utilize isWorkingDay.
134
- * @param {Date} pData
139
+ * @param {Date} pDate
135
140
  * @returns {boolean}
136
141
  */
137
142
  isHoliday: pDate => {
@@ -293,7 +293,7 @@ module.exports = formats;
293
293
  * @param {*} pValue Valor a ser simplificado
294
294
  * @param {number} [pDecimals=2] Quantidade máxima de casas decimais
295
295
  * @param {boolean} [pShowCurrency=false] Se exibe o símbolo da moeda do país definido em formats.CURRENCY.
296
- * @returns Valor formatado de forma simplificada
296
+ * @returns {String} Valor formatado de forma simplificada
297
297
  */
298
298
  const pvSimplify = (pDIM, pValue, pDecimals = 2, pShowCurrency = false) => {
299
299
  const xOptions = {
@@ -330,5 +330,5 @@ const pvSimplify = (pDIM, pValue, pDecimals = 2, pShowCurrency = false) => {
330
330
  xValueInt *= xSign;
331
331
  //Configura formatação
332
332
 
333
- return xValueInt.toLocaleString(formats.LOCALE, xOptions) + xSuf.trimRight();
333
+ return xValueInt.toLocaleString(formats.LOCALE, xOptions) + xSuf.trimEnd();
334
334
  };
@@ -17,7 +17,7 @@ const numbers = {
17
17
  return null;
18
18
  }
19
19
  const xP = Math.pow(10, pDecimals);
20
- let xValue = Number(Math.round(pValue * xP));
20
+ let xValue = Number(Math.round(numbers.mul(pValue, xP)));
21
21
  xValue = Math[xValue < 0 ? 'ceil' : 'floor'](xValue);
22
22
  return xValue / xP;
23
23
  },
@@ -34,7 +34,7 @@ const numbers = {
34
34
  return null;
35
35
  }
36
36
  const xP = Math.pow(10, pDecimals);
37
- let xValue = Number(pValue * xP);
37
+ let xValue = numbers.mul(pValue, xP);
38
38
  xValue = Math[xValue < 0 ? 'ceil' : 'floor'](xValue);
39
39
  return xValue / xP;
40
40
  },
@@ -313,14 +313,7 @@ const pvCalc = (pValue1, pValue2, pOperation) => {
313
313
  }
314
314
  const xValue1Str = numbers.apart(pValue1);
315
315
  const xValue2Str = numbers.apart(pValue2);
316
- const xMaxInt = Math.max(xValue1Str.int.length, xValue2Str.int.length);
317
- let xMaxDec = Math.max(xValue1Str.dec.length, xValue2Str.dec.length);
318
- const xOver = xMaxInt + xMaxDec - PRECISION;
319
- if (xOver > 0 && xMaxDec > xOver) {
320
- xMaxDec -= xOver;
321
- xValue1Str.dec = xValue1Str.dec.substring(0, xMaxDec);
322
- xValue2Str.dec = xValue2Str.dec.substring(0, xMaxDec);
323
- }
316
+ const xMaxDec = Math.max(xValue1Str.dec.length, xValue2Str.dec.length);
324
317
 
325
318
  //Como se estivesse multiplicando os valores por 10^xMaxDec,
326
319
  //mas concatena os zeros para evitar um possível residuo no cálculo
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "investira.sdk",
3
- "version": "2.2.12",
3
+ "version": "2.2.15",
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.2.12",
9
+ "raw": "investira.sdk@2.2.15",
10
10
  "escapedName": "investira.sdk",
11
- "rawSpec": "2.2.12",
11
+ "rawSpec": "2.2.15",
12
12
  "saveSpec": null,
13
- "fetchSpec": "2.2.12",
13
+ "fetchSpec": "2.2.15",
14
14
  "homepage": "https://investira.com.br/",
15
15
  "engines": {
16
16
  "node": ">=11.11.0 <=14.17.5",
@@ -31,13 +31,14 @@
31
31
  },
32
32
  "scripts": {
33
33
  "start": "node ./lib/tests",
34
+ "debug": "nodemon ./lib/tests",
34
35
  "_test": "nodemon ./_tests/test"
35
36
  },
36
37
  "dependencies": {
37
38
  "axios": "0.25.0",
38
39
  "deep-diff": "1.0.2",
39
40
  "flatted": "3.2.2",
40
- "investira.data": "^1.1.15",
41
+ "investira.data": "^1.2.2",
41
42
  "moment": "^2.29.4"
42
43
  },
43
44
  "devDependencies": {