investira.sdk 2.3.7 → 2.3.8

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
@@ -484,3 +484,7 @@ O contrutor para a criação das mensagem foi alterado.
484
484
 
485
485
  - [arrays] Inclui função removeDuplicated
486
486
  - [dates] Correção do nome da função para nextMonthAnniversary
487
+
488
+ # 2.3.8
489
+
490
+ - [dates] Correção do cálculo de semanas
@@ -18,6 +18,7 @@ const dates = {
18
18
  ONE_DAY: 864e5, //24 * 60 * 60 * 1000,
19
19
  ONE_WEEK: 6048e5, //24 * 60 * 60 * 1000 * 7,
20
20
  SCHEDULE_TYPE: ['D', 'W', 'M', 'Y'],
21
+ WEEKENDS_DAYS: [0, 6],
21
22
 
22
23
  /**
23
24
  * Configura o locale atual
@@ -99,12 +100,25 @@ const dates = {
99
100
  * Retorna date UTC a partir de uma string no formato ISO 8601 YYYY-MM-DD HH:mm:ss.
100
101
  * - ATENÇÃO: Fora deste formato o resultado pode ser imprevisível.
101
102
  * - A informação dos segundos(ss) e, horas(hh) + minutos(mm) são opcionais.
102
- * @param {string} [pDate=null] String no formato informado em pFormat ou, quando não informado, no formato YYYY-MM-DD HH:mm:ss. ss, HH:mm são opcionais
103
- * @param {string} [pFormat=null] Formato que se encontra a data informada
103
+ * @param {string | Date} [pDate=null] String no formato informado em pFormat ou, quando não informado, no formato YYYY-MM-DD HH:mm:ss. ss, HH:mm são opcionais
104
+ * @param {string | Date} [pFormat=null] Formato que se encontra a data informada
104
105
  * @returns {Date} Date
105
106
  */
106
107
  toDate: (pDate = null, pFormat = null) => {
107
108
  //TODO: Implemantar possibilidade configuração do timeZone. ex new Date().toLocaleString("pt-BR", {timeZone: "America/Sao_Paulo"});
109
+ // let xDate = null;
110
+ // if (pDate) {
111
+ // if (pFormat) {
112
+ // xDate = moment(pDate, pFormat);
113
+ // } else {
114
+ // xDate = moment(pDate);
115
+ // }
116
+ // if (xDate && xDate.isValid()) {
117
+ // xDate = xDate.toDate();
118
+ // }
119
+ // return xDate;
120
+ // }
121
+ // return null;
108
122
  let xDate = null;
109
123
  if (!isNull(pFormat)) {
110
124
  if (!isEmpty(pDate)) {
@@ -151,19 +165,27 @@ const dates = {
151
165
  * Retorna quantidade de dias que são feriados.
152
166
  * Feriados que caem em dia não util não são considerados.
153
167
  *
154
- * @param {Date} pDateStart
155
- * @param {Date} pDateEnd
168
+ * @param {Date} pDateStart Data inicial
169
+ * @param {Date} pDateEnd Data final
156
170
  * @returns {number}
157
171
  */
158
172
  holidays: (pDateStart, pDateEnd) => {
159
173
  const xLocale = dates.localeData()._holidays;
174
+ let xDateStart = dates.toDate(pDateStart);
175
+ let xDateEnd = dates.toDate(pDateEnd);
176
+ let xSign = 1;
177
+ if (pDateEnd < pDateStart) {
178
+ [xDateStart, xDateEnd] = [xDateEnd, xDateStart];
179
+ xSign = -1;
180
+ }
181
+
160
182
  //Procura feriado posterior mais próximo data inicial, desconsiderando a própria data
161
- const xI1 = seekDate(xLocale, pvToHolidayFormat(dates.addDays(pDateStart, 1)), true);
183
+ const xI1 = seekDate(xLocale, pvToHolidayFormat(xDateStart), true);
162
184
  //Procura feriado anterior mais próximo a data final
163
- const xI2 = seekDate(xLocale, pvToHolidayFormat(pDateEnd), false);
185
+ const xI2 = seekDate(xLocale, pvToHolidayFormat(xDateEnd), false);
164
186
  //A quantidade de feriados será a diferença de itens entre as duas datas.
165
187
  if (xI1 <= xI2) {
166
- return xI2 - xI1 + 1;
188
+ return (xI2 - xI1 + 1) * xSign;
167
189
  } else {
168
190
  return 0;
169
191
  }
@@ -275,11 +297,11 @@ const dates = {
275
297
  try {
276
298
  if (isNumber(pDate)) {
277
299
  // @ts-ignore
278
- const xSeconds = Math.floor((pDate / 1000) % 60);
300
+ const xSeconds = Math.floor((pDate / ONE_SECOND) % 60);
279
301
  // @ts-ignore
280
- const xMinutes = Math.floor((pDate / 1000 / 60) % 60);
302
+ const xMinutes = Math.floor((pDate / ONE_MINUTE) % 60);
281
303
  // @ts-ignore
282
- const xHours = Math.floor((pDate / (1000 * 60 * 60)) % 24);
304
+ const xHours = Math.floor((pDate / ONE_HOUR) % 24);
283
305
  return `${xHours}:${xMinutes}:${xSeconds}`;
284
306
  } else if (isDate(pDate)) {
285
307
  // @ts-ignore
@@ -398,29 +420,47 @@ const dates = {
398
420
 
399
421
  /**
400
422
  * Quantidade de dias úteis entre duas datas.
423
+ * Se a data inicial for superior a data fi:nal, as datas serão invertidas
424
+ * Exclui a data incial da contagem
401
425
  *
402
426
  * @param {Date} pDateStart
403
427
  * @param {Date} pDateEnd
404
428
  * @returns {number}
405
429
  */
406
- workingDaysBetween: (pDateStart, pDateEnd) => {
407
- let xDateStart = pDateStart;
408
- let xDateEnd = pDateEnd;
409
- let xD = 0;
410
- if (pDateStart > pDateEnd) {
411
- xDateEnd = pDateStart;
412
- xDateStart = pDateEnd;
413
- if (dates.isWorkingDay(xDateStart)) {
414
- xD += 1;
430
+ workingDaysBetween: (pDateStart, pDateEnd, pCountDateStart = false) => {
431
+ //Força datas para o mesmo horário
432
+ let xDateStart = dates.toDate(pDateStart);
433
+ let xDateEnd = dates.toDate(pDateEnd);
434
+ if (xDateStart.getTime() === xDateEnd.getTime()) {
435
+ return 0;
436
+ }
437
+ let xSign = 1;
438
+ if (pDateEnd < pDateStart) {
439
+ xSign = -1;
440
+ }
441
+
442
+ //Calculo de dias entre duas datas
443
+ let xDays = pvDaysDif(xDateStart, xDateEnd);
444
+ if (!pCountDateStart) {
445
+ if (xDateEnd > xDateStart) {
446
+ //Desconsidera data inicial
447
+ xDateStart.setDate(xDateStart.getDate() + 1);
448
+ } else {
449
+ //Desconsidera data inicial
450
+ xDateStart.setDate(xDateStart.getDate() - 1);
415
451
  }
416
- if (dates.isWorkingDay(xDateEnd)) {
417
- xD -= 1;
452
+ if (xDateStart.getTime() === xDateEnd.getTime()) {
453
+ xDays = dates.isWorkingDay(xDateEnd) ? 1 : 0;
454
+ return xDays * xSign;
418
455
  }
419
456
  }
420
- xD += dates.diff('day', xDateStart, xDateEnd, true);
421
- const xW = dates.weekends(xDateStart, xDateEnd);
457
+ //Quantidade de feriados entre as datas
422
458
  const xH = dates.holidays(xDateStart, xDateEnd);
423
- return xD - xW - xH;
459
+ //Quantidade de finais de semana entre as datas
460
+ const xW = dates.weekends(xDateStart, xDateEnd);
461
+ //Subtrai quantidade de feriados e finais de semana
462
+ xDays = xDays - xW - xH;
463
+ return xDays;
424
464
  },
425
465
  /**
426
466
  * Retorna quantidade de dias do mês informado
@@ -429,8 +469,8 @@ const dates = {
429
469
  * @returns {number}
430
470
  */
431
471
  workingDaysInMonth: pDate => {
432
- let xDate1 = moment(pDate).utcOffset(0).startOf('month').add(-1, 'days').toDate();
433
- let xDate2 = moment(pDate).utcOffset(0).endOf('month').toDate();
472
+ let xDate1 = dates.addDays(dates.startOf('month', dates.toUTCDate(pDate)), -1);
473
+ let xDate2 = dates.endOf('month', dates.toUTCDate(pDate));
434
474
  return dates.workingDaysBetween(xDate1, xDate2);
435
475
  },
436
476
  /**
@@ -442,7 +482,7 @@ const dates = {
442
482
  workingDaysInYear: pDate => {
443
483
  let xDate1 = moment(pDate).utcOffset(0).startOf('year').add(-1, 'days').toDate();
444
484
  let xDate2 = moment(pDate).utcOffset(0).endOf('year').toDate();
445
- return dates.workingDaysBetween(xDate1, xDate2);
485
+ return dates.workingDaysBetween(xDate1, xDate2, true);
446
486
  },
447
487
  /**
448
488
  * Retorna diferença entre duas data conforma a unidade informada.
@@ -513,6 +553,25 @@ const dates = {
513
553
  return pDate.toISOString();
514
554
  },
515
555
 
556
+ /**
557
+ * Retorna string no formato UTC ISO 8601
558
+ *
559
+ * @param {Date | Number} pDateOrYear
560
+ * @param {Number} pMonth
561
+ * @param {Number} pDay
562
+ * @returns {Date}
563
+ */
564
+ toUTCDate: (pDateOrYear, pMonth = null, pDay = null) => {
565
+ if (isNumber(pDateOrYear)) {
566
+ // @ts-ignore
567
+ return new Date(Date.UTC(pDateOrYear, pMonth, pDay, 0, 0, 0, 0));
568
+ } else {
569
+ return new Date(
570
+ // @ts-ignore
571
+ Date.UTC(pDateOrYear.getFullYear(), pDateOrYear.getMonth(), pDateOrYear.getDate(), 0, 0, 0, 0)
572
+ );
573
+ }
574
+ },
516
575
  /**
517
576
  * Retorna datacom acréscimo dos milisegundos informados
518
577
  *
@@ -550,16 +609,71 @@ const dates = {
550
609
  pDays = 1;
551
610
  }
552
611
 
612
+ //Adiciona a quantidade de dias para se aproximar a data alvo
553
613
  let xDate = dates.add('days', pDate, pDays);
554
- let xDays = dates.workingDaysBetween(pDate, xDate) * Math.sign(pDays);
555
-
614
+ //Conta a quantidade de dias úteis entre a data inicial e a data alvo
615
+ let xDays = dates.workingDaysBetween(pDate, xDate);
616
+ //Se resultado for a quantidade de dias informada, retorna a data alvo
556
617
  if (xDays === pDays) {
557
618
  return xDate;
558
619
  } else {
620
+ //Chada recursiva até encontrar a data alvo que contenha a quantidade de dias úteis informada
559
621
  const xDif = pDays - xDays;
560
622
  return dates.addWorkingDays(xDate, xDif);
561
623
  }
562
624
  },
625
+ /**
626
+ * Retorna a quantidade dias que são finais de semana(Sábados e Domingos) entre duas datas
627
+ * A data início e a data fim são incluídas na contagem
628
+ *
629
+ * @param {Date} pDateStart
630
+ * @param {Date} pDateEnd
631
+ * @returns {number}
632
+ */
633
+ weekends: (pDateStart, pDateEnd) => {
634
+ //Força datas para o mesmo horário
635
+ let xDateStart = dates.toDate(pDateStart);
636
+ let xDateEnd = dates.toDate(pDateEnd);
637
+ let xSign = 1;
638
+ if (pDateEnd < pDateStart) {
639
+ [xDateStart, xDateEnd] = [xDateEnd, xDateStart];
640
+ xSign = -1;
641
+ }
642
+ let xWeekends = 0;
643
+ // Calcula TOTAL de dias entre as datas, incluido o próprio dia.
644
+ // Ex: 01/01/2019 a 01/01/2019 = 1 dia
645
+ let xDays = pvDaysDif(xDateStart, xDateEnd) + 1;
646
+ // Ajusta contador se data inicial for sábado ou domingo
647
+ const xStartWeekDay = xDateStart.getDay();
648
+ const xEndWeekDay = xDateEnd.getDay();
649
+
650
+ //Se data inicial for sábado ou data for domingo
651
+ if (dates.WEEKENDS_DAYS.includes(xStartWeekDay) || dates.WEEKENDS_DAYS.includes(xEndWeekDay)) {
652
+ if (xStartWeekDay === 6) {
653
+ xDays -= 2;
654
+ xWeekends += 2;
655
+ }
656
+ if (xEndWeekDay === 0) {
657
+ xDays -= 2;
658
+ xWeekends += 2;
659
+ }
660
+ if (xStartWeekDay === 0) {
661
+ xDays -= 1;
662
+ xWeekends += 1;
663
+ }
664
+ if (xEndWeekDay === 6) {
665
+ xDays -= 1;
666
+ xWeekends += 1;
667
+ }
668
+ } else if (xStartWeekDay > xEndWeekDay) {
669
+ xDays -= 2;
670
+ xWeekends += 2;
671
+ }
672
+ // Calcula número de finais de semana. Sábado e domingo
673
+ xWeekends += Math.floor(xDays / 7) * 2;
674
+ return xWeekends * xSign;
675
+ },
676
+
563
677
  /**
564
678
  * Verifica se data é um dia útil.
565
679
  *
@@ -678,39 +792,6 @@ const dates = {
678
792
  return moment(pDate).endOf(pUnit).toDate();
679
793
  },
680
794
 
681
- /**
682
- * Retorna a quantidade de finais de semana(Sábados e Domingos) entre duas datas
683
- *
684
- * @param {Date} pDateStart
685
- * @param {Date} pDateEnd
686
- * @returns {number}
687
- */
688
- weekends: (pDateStart, pDateEnd) => {
689
- //Quantidade sábados e domingos entre a datas
690
- let xDateI = pDateStart;
691
- let xDateF = pDateEnd;
692
- if (pDateStart > pDateEnd) {
693
- xDateI = pDateEnd;
694
- xDateF = pDateStart;
695
- }
696
- let xWeekends = dates.daysBetween(xDateI, xDateF);
697
- const xSemanas = numbers.apart(numbers.div(xWeekends, 7));
698
- //Quantidade de semanas existentes entre as duas datas
699
- xWeekends = Number(xSemanas.int) * 2;
700
- const xWI = xDateI.getUTCDay();
701
- //Artifício para não precisar fazer cálculo
702
- const xDias = Math.trunc(Number('0.' + xSemanas.dec) * 7);
703
- const xWF = xWI + xDias;
704
- let xCalc = xWF - 5;
705
- if (xCalc > 0) {
706
- xWeekends += Math.min(2, xCalc);
707
- }
708
- if (xWI === 6) {
709
- xWeekends--;
710
- }
711
- return xWeekends;
712
- },
713
-
714
795
  /**
715
796
  * Verifica se string é uma hora válida
716
797
  *
@@ -1003,5 +1084,12 @@ const pvLoadDataPush = (pHolidays, pKey, pHolidayString) => {
1003
1084
  pHolidays.push(pHolidayString);
1004
1085
  }
1005
1086
  };
1087
+
1088
+ const pvDaysDif = (pDateStart, pDateEnd) => {
1089
+ const xDateStart = dates.toUTCDate(pDateStart);
1090
+ const xDateEnd = dates.toUTCDate(pDateEnd);
1091
+ let xDays = Math.floor((xDateEnd.getTime() - xDateStart.getTime()) / dates.ONE_DAY);
1092
+ return xDays;
1093
+ };
1006
1094
  //Carrega informações dos feriados
1007
1095
  dates.loadData();
@@ -179,62 +179,62 @@ const formats = {
179
179
  if (isEmpty(pValue) || !isNumber(pValue) || pValue < 1) {
180
180
  return '';
181
181
  }
182
- const xData1 = new Date();
183
- let xData2 = new Date();
182
+ const xDataI = new Date();
183
+ let xDataF = new Date();
184
184
 
185
185
  if (pType === 'd') {
186
- xData2 = addDays(xData1, pValue);
186
+ xDataF = addDays(xDataI, pValue);
187
187
  }
188
188
 
189
189
  if (pType === 'm') {
190
- xData2 = addMonths(xData1, pValue);
190
+ xDataF = addMonths(xDataI, pValue);
191
191
  }
192
192
 
193
193
  if (pType === 'y') {
194
- xData2 = addYears(xData1, pValue);
194
+ xDataF = addYears(xDataI, pValue);
195
195
  }
196
196
 
197
- return formats.friendlyBetweenDates(xData1, xData2);
197
+ return formats.friendlyBetweenDates(xDataI, xDataF);
198
198
  },
199
199
 
200
200
  /**
201
201
  * Retorna string no formado x ano(s) e/ou y (mês)es e/ou z dia(s).
202
202
  *
203
- * @param {string | Date} pDate1 Data inicial
204
- * @param {string | Date} pDate2 Data final
203
+ * @param {string | Date} pDateI Data inicial
204
+ * @param {string | Date} pDateF Data final
205
205
  * @returns
206
206
  */
207
- friendlyBetweenDates: (pDate1, pDate2) => {
207
+ friendlyBetweenDates: (pDateI, pDateF) => {
208
208
  let xPeriod = '';
209
- if (isEmpty(pDate1) || isEmpty(pDate2)) {
209
+ if (isEmpty(pDateI) || isEmpty(pDateF)) {
210
210
  return xPeriod;
211
211
  }
212
212
 
213
- let xDate1 = pDate1;
214
- let xDate2 = pDate2;
213
+ let xDateI = pDateI;
214
+ let xDateF = pDateF;
215
215
 
216
- if (isString(pDate1)) {
216
+ if (isString(pDateI)) {
217
217
  // @ts-ignore
218
- xDate1 = toDate(xDate1);
218
+ xDateI = toDate(xDateI);
219
219
  }
220
- if (isString(pDate2)) {
220
+ if (isString(pDateF)) {
221
221
  // @ts-ignore
222
- xDate2 = toDate(xDate2);
222
+ xDateF = toDate(xDateF);
223
223
  }
224
224
  // @ts-ignore
225
- xDate1 = startOf('day', xDate1);
225
+ xDateI = startOf('day', xDateI);
226
226
  // @ts-ignore
227
- xDate2 = startOf('day', xDate2);
227
+ xDateF = startOf('day', xDateF);
228
228
 
229
- if (daysBetween(xDate1, xDate2) == 0) {
229
+ if (daysBetween(xDateI, xDateF) == 0) {
230
230
  return '';
231
231
  }
232
232
 
233
- const xYears = Math.floor(yearsBetween(xDate1, xDate2));
234
- xDate2 = addYears(xDate2, -xYears);
235
- const xMonths = Math.floor(monthsBetween(xDate1, xDate2));
236
- xDate2 = addMonths(xDate2, -xMonths);
237
- const xDays = daysBetween(xDate1, xDate2, true);
233
+ const xYears = Math.floor(yearsBetween(xDateI, xDateF));
234
+ xDateF = addYears(xDateF, -xYears);
235
+ const xMonths = Math.floor(monthsBetween(xDateI, xDateF));
236
+ xDateF = addMonths(xDateF, -xMonths);
237
+ const xDays = daysBetween(xDateI, xDateF, true);
238
238
  const xSlugs = formats.slugPeriod(xYears, xMonths, xDays);
239
239
 
240
240
  if (xYears > 0 && xMonths > 0) {
@@ -256,7 +256,7 @@ const formats = {
256
256
  /**
257
257
  * Retorna string no formato: há 4 anos atrás.
258
258
  *
259
- * @param {Date} pDate1 Data inicial
259
+ * @param {Date} pDate Data inicial
260
260
  * @param {boolean} pSuffix Sem sufixo
261
261
  * @returns
262
262
  */
@@ -266,7 +266,7 @@ const formats = {
266
266
  /**
267
267
  * Retorna string no formato: em 4 anos.
268
268
  *
269
- * @param {Date} pDate1 Data inicial
269
+ * @param {Date} pDate Data inicial
270
270
  * @param {boolean} pPrefix Sem sufixo
271
271
  * @returns
272
272
  */
@@ -98,6 +98,9 @@ const validators = {
98
98
  * @returns {boolean}
99
99
  */
100
100
  isUndefined: toValidate => {
101
+ if (toValidate === undefined) {
102
+ return true;
103
+ }
101
104
  return validators.trueTypeOf(toValidate) === 'undefined';
102
105
  },
103
106
 
@@ -165,7 +168,7 @@ const validators = {
165
168
 
166
169
  /**
167
170
  * Retorna se tamanho é maior que outro
168
- * @param {object} toValidate Elemento a ser verificado
171
+ * @param {object} length Elemento a ser verificado
169
172
  * @returns
170
173
  */
171
174
  isLengthGreaterThen: length => toValidate => toValidate.length > length,
@@ -197,10 +200,7 @@ const validators = {
197
200
  */
198
201
  isTrue: pValue => {
199
202
  //Separado em vário if's para otimizar performance
200
- if (pValue === null) {
201
- return false;
202
- }
203
- if (validators.isUndefined(pValue)) {
203
+ if (pValue === null || validators.isUndefined(pValue)) {
204
204
  return false;
205
205
  }
206
206
  if (pValue === -1 || pValue === 1) {
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "investira.sdk",
3
- "version": "2.3.7",
3
+ "version": "2.3.8",
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.3.7",
9
+ "raw": "investira.sdk@2.3.8",
10
10
  "escapedName": "investira.sdk",
11
- "rawSpec": "2.3.7",
11
+ "rawSpec": "2.3.8",
12
12
  "saveSpec": null,
13
- "fetchSpec": "2.3.7",
13
+ "fetchSpec": "2.3.8",
14
14
  "homepage": "https://investira.com.br/",
15
15
  "engines": {
16
16
  "node": ">=11.11.0 <=18.12",
@@ -1,14 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "trace": true,
6
- "name": "debug node",
7
- "type": "node",
8
- "request": "attach",
9
- "restart": true,
10
- "cwd": "${workspaceFolder}",
11
- "port": 9233,
12
- }
13
- ]
14
- }
@@ -1,6 +0,0 @@
1
- {
2
- "debug.node.autoAttach": "on",
3
- "debug.javascript.usePreview": false,
4
- "debug.javascript.usePreviewAutoAttach": false,
5
- "debug.javascript.autoAttachFilter": "onlyWithFlag"
6
- }
@@ -1,9 +0,0 @@
1
- require('./test_formats');
2
- require('./test_dates');
3
- require('./test_invests');
4
- require('./test_numbers');
5
- require('./test_strings');
6
- require('./test_arrays');
7
- require('./test_spellChecker');
8
- require('./test_validators');
9
- require('./test_objects');
@@ -1,138 +0,0 @@
1
- const test = require('tape');
2
- const arrays = require('../utils/arrays');
3
- const dates = require('../utils/dates');
4
- const arrayNumber = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90];
5
- const arrayDate = [
6
- new Date('2000-01-01'),
7
- new Date('2000-02-01'),
8
- new Date('2000-03-01'),
9
- new Date('2000-04-01'),
10
- new Date('2000-05-01'),
11
- new Date('2000-06-01'),
12
- new Date('2000-07-01'),
13
- new Date('2000-08-01'),
14
- new Date('2000-09-01'),
15
- new Date('2000-10-01')
16
- ];
17
- const arrayDateString = [
18
- '2000-01-01',
19
- '2000-02-01',
20
- '2000-03-01',
21
- '2000-04-01',
22
- '2000-05-01',
23
- '2000-06-01',
24
- '2000-07-01',
25
- '2000-08-01',
26
- '2000-09-01',
27
- '2000-10-01'
28
- ];
29
- const arrayString = ['A', 'D', 'G', 'J', 'K', 'N', 'Q', 'T', 'W', 'Z'];
30
-
31
- test('\narrays seek number', t => {
32
- //O mais próximo
33
- t.equal(arrays.seek(arrayNumber, 30), arrayNumber.indexOf(30));
34
- //O anterior mais próximo
35
- t.equal(arrays.seek(arrayNumber, 30, false), arrayNumber.indexOf(30));
36
- //O posterior mais próximo
37
- t.equal(arrays.seek(arrayNumber, 30, true), arrayNumber.indexOf(30));
38
-
39
- //O mais próximo
40
- t.equal(arrays.seek(arrayNumber, 31), arrayNumber.indexOf(30));
41
- //O anterior mais próximo
42
- t.equal(arrays.seek(arrayNumber, 31, false), arrayNumber.indexOf(30));
43
- //O posterior mais próximo
44
- t.equal(arrays.seek(arrayNumber, 31, true), arrayNumber.indexOf(40));
45
-
46
- //O mais próximo
47
- t.equal(arrays.seek(arrayNumber, 29), arrayNumber.indexOf(30));
48
- //O anterior mais próximo
49
- t.equal(arrays.seek(arrayNumber, 29, false), arrayNumber.indexOf(20));
50
- //O posterior mais próximo
51
- t.equal(arrays.seek(arrayNumber, 29, true), arrayNumber.indexOf(30));
52
-
53
- //O posterior mais próximo
54
- t.equal(arrays.seek(arrayNumber, 1000), arrayNumber.indexOf(90));
55
- //O anterior mais próximo
56
- t.equal(arrays.seek(arrayNumber, 1000, false), arrayNumber.indexOf(90));
57
- //O posterior mais próximo
58
- t.equal(arrays.seek(arrayNumber, 1000, true), arrayNumber.indexOf(90));
59
-
60
- //O posterior mais próximo
61
- t.equal(arrays.seek(arrayNumber, -1000), arrayNumber.indexOf(0));
62
- //O anterior mais próximo
63
- t.equal(arrays.seek(arrayNumber, -1000, false), arrayNumber.indexOf(0));
64
- //O posterior mais próximo
65
- t.equal(arrays.seek(arrayNumber, -1000, true), arrayNumber.indexOf(0));
66
- t.end();
67
- });
68
-
69
- test('\narrays seek date', t => {
70
- //O mais próximo
71
- t.equal(arrays.seek(arrayDate, new Date('2000-05-15')), 4);
72
- //O anterior mais próximo
73
- t.equal(arrays.seek(arrayDate, new Date('2000-05-15'), false), 4);
74
- //O posterior mais próximo
75
- t.equal(arrays.seek(arrayDate, new Date('2000-05-15'), true), 5);
76
-
77
- //O mais próximo
78
- t.equal(arrays.seek(arrayDate, new Date('2010-05-15')), 9);
79
- //O anterior mais próximo
80
- t.equal(arrays.seek(arrayDate, new Date('2010-05-15'), false), 9);
81
- //O posterior mais próximo
82
- t.equal(arrays.seek(arrayDate, new Date('2010-05-15'), true), 9);
83
-
84
- //O mais próximo
85
- t.equal(arrays.seek(arrayDate, new Date('1999-05-15')), 0);
86
- //O anterior mais próximo
87
- t.equal(arrays.seek(arrayDate, new Date('1999-05-15'), false), 0);
88
- //O posterior mais próximo
89
- t.equal(arrays.seek(arrayDate, new Date('1999-05-15'), true), 0);
90
-
91
- t.end();
92
- });
93
-
94
- test('\narrays seek date string', t => {
95
- //O mais próximo
96
- t.equal(arrays.seekDate(arrayDateString, '2000-05-15'), arrayDateString.indexOf('2000-05-01'));
97
- // //O anterior mais próximo
98
- t.equal(arrays.seekDate(arrayDateString, '2000-05-15', false), arrayDateString.indexOf('2000-05-01'));
99
- //O posterior mais próximo
100
- t.equal(arrays.seekDate(arrayDateString, '2000-05-15', true), arrayDateString.indexOf('2000-06-01'));
101
-
102
- //O mais próximo
103
- t.equal(arrays.seekDate(arrayDateString, '2010-05-15'), arrayDateString.indexOf('2000-10-01'));
104
- //O anterior mais próximo
105
- t.equal(arrays.seekDate(arrayDateString, '2010-05-15', false), arrayDateString.indexOf('2000-10-01'));
106
- //O posterior mais próximo
107
- t.equal(arrays.seekDate(arrayDateString, '2010-05-15', true), arrayDateString.indexOf('2000-10-01'));
108
-
109
- //O mais próximo
110
- t.equal(arrays.seekDate(arrayDateString, '1999-05-15'), arrayDateString.indexOf('2000-01-01'));
111
- //O anterior mais próximo
112
- t.equal(arrays.seekDate(arrayDateString, '1999-05-15', false), arrayDateString.indexOf('2000-01-01'));
113
- //O posterior mais próximo
114
- t.equal(arrays.seekDate(arrayDateString, '1999-05-15', true), arrayDateString.indexOf('2000-01-01'));
115
- t.end();
116
- });
117
-
118
- test('\ntoArray', t => {
119
- t.deepEqual(arrays.toArray('uma frase qualquer,outra frase qualquer,terceira frase qualquer'), [
120
- 'uma frase qualquer',
121
- 'outra frase qualquer',
122
- 'terceira frase qualquer'
123
- ]);
124
- t.deepEqual(arrays.toArray('uma frase qualquer,outra frase qualquer,terceira frase qualquer', undefined, '%'), [
125
- '%uma frase qualquer',
126
- '%outra frase qualquer',
127
- '%terceira frase qualquer'
128
- ]);
129
- t.deepEqual(
130
- arrays.toArray('uma frase qualquer,outra frase qualquer,terceira frase qualquer', undefined, '%', '%'),
131
- ['%uma frase qualquer%', '%outra frase qualquer%', '%terceira frase qualquer%']
132
- );
133
- t.deepEqual(
134
- arrays.toArray(['uma frase qualquer', 'outra frase qualquer', 'terceira frase qualquer'], undefined, '%', '%'),
135
- ['%uma frase qualquer%', '%outra frase qualquer%', '%terceira frase qualquer%']
136
- );
137
- t.end();
138
- });
@@ -1,270 +0,0 @@
1
- const test = require('tape');
2
- const { formatDateCustom } = require('../utils/formats');
3
-
4
- const dates = require('../utils/dates');
5
-
6
- test('\ndates scheduleToDate', t => {
7
- dates.locale('pt-BR');
8
- t.deepEqual(
9
- dates.scheduleToDate({ type: 'D', time: '08:30', workingDay: true }, dates.toDate('2001-01-01T00:00')),
10
- dates.toDate('2001-01-02T08:30:00')
11
- );
12
- t.deepEqual(
13
- dates.scheduleToDate({ type: 'M', time: '08:30', workingDay: true }, dates.toDate('2001-01-10T00:00')),
14
- dates.toDate('2001-02-01T08:30:00')
15
- );
16
- t.deepEqual(
17
- dates.scheduleToDate(
18
- { type: 'W', time: '08:30', weekday: 2, workingDay: false },
19
- dates.toDate('2020-09-28T00:00')
20
- ),
21
- dates.toDate('2020-09-29T08:30')
22
- );
23
- t.deepEqual(
24
- dates.scheduleToDate(
25
- { type: 'W', time: '08:30', weekday: 1, workingDay: false },
26
- dates.toDate('2020-09-29T08:31')
27
- ),
28
- dates.toDate('2020-10-05T08:30')
29
- );
30
- t.end();
31
- });
32
-
33
- test('\ndates areDatesEqual', t => {
34
- dates.locale('pt-BR');
35
- t.equal(dates.areDatesEqual(dates.toDate('2001-01-01T00:00Z'), dates.toDate('2001-01-01T00:00Z')), true);
36
- t.equal(dates.areDatesEqual(dates.toDate('2001-01-01T00:00Z'), dates.toDate('2001-01-01T00:01Z')), true);
37
- t.equal(dates.areDatesEqual(dates.toDate('2001-01-01T00:00Z'), dates.toDate('2001-01-02T00:01Z')), false);
38
- t.end();
39
- });
40
-
41
- test('\ndates areDateTimesEqual', t => {
42
- dates.locale('pt-BR');
43
- t.equal(dates.areDateTimesEqual(dates.toDate('2001-01-01T00:00Z'), dates.toDate('2001-01-01T00:00Z')), true);
44
- t.equal(dates.areDateTimesEqual(dates.toDate('2001-01-01T00:00Z'), dates.toDate('2001-01-01T00:01Z')), false);
45
- t.equal(dates.areDateTimesEqual(dates.toDate('2001-01-01T00:00Z'), dates.toDate('2001-01-02T00:01Z')), false);
46
- t.end();
47
- });
48
-
49
- test('\ndates isWorkingDay', t => {
50
- dates.locale('pt-BR');
51
- t.equal(dates.isWorkingDay(dates.toDate('2019-08-03')), false);
52
- t.equal(dates.isWorkingDay(dates.toDate('2019-08-05')), true);
53
- t.equal(dates.isWorkingDay(dates.toDate('2019-09-07')), false);
54
- t.end();
55
- });
56
-
57
- test('\ndates isTime', t => {
58
- dates.locale('pt-BR');
59
- t.equal(dates.isTime('25:00'), false);
60
- t.equal(dates.isTime('24:01'), false);
61
- t.equal(dates.isTime('24:00'), false);
62
- t.equal(dates.isTime('00:00'), true);
63
- t.equal(dates.isTime('00:60'), false);
64
- t.equal(dates.isTime('00:01'), true);
65
- t.equal(dates.isTime('0:0'), false);
66
- t.equal(dates.isTime('00'), false);
67
- t.end();
68
- });
69
-
70
- test('\ndates addWorkingDays', t => {
71
- dates.locale('pt-BR');
72
-
73
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-01'), -252), dates.toDate('2018-07-30T03:00:00.000Z'));
74
- t.deepEqual(dates.addWorkingDays(dates.toDate('2018-07-30'), 252), dates.toDate('2019-08-01T03:00:00.000Z'));
75
-
76
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-03'), -1), dates.toDate('2019-08-02T03:00:00.000Z'));
77
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-04'), -1), dates.toDate('2019-08-02T03:00:00.000Z'));
78
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-05'), -1), dates.toDate('2019-08-02T03:00:00.000Z'));
79
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-06'), -1), dates.toDate('2019-08-05T03:00:00.000Z'));
80
-
81
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-03'), 0), dates.toDate('2019-08-05T03:00:00.000Z'));
82
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-05'), 0), dates.toDate('2019-08-05T03:00:00.000Z'));
83
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-03'), 1), dates.toDate('2019-08-05T03:00:00.000Z'));
84
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-05'), 1), dates.toDate('2019-08-06T03:00:00.000Z'));
85
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-03'), 2), dates.toDate('2019-08-06T03:00:00.000Z'));
86
- t.deepEqual(dates.addWorkingDays(dates.toDate('2019-08-05'), 4), dates.toDate('2019-08-09T03:00:00.000Z'));
87
- t.end();
88
- });
89
-
90
- test('\ndates weekNames', t => {
91
- dates.locale('pt-BR');
92
- t.equal(dates.weekNames()[0], 'domingo');
93
- dates.locale('en-US');
94
- t.equal(dates.weekNames()[0], 'Sunday');
95
- t.end();
96
- });
97
-
98
- test('\ndates workingDaysInMonth', t => {
99
- dates.locale('pt-BR');
100
- t.equal(dates.workingDaysInMonth(dates.toDate('2019-03-03')), 19);
101
- t.equal(dates.workingDaysInMonth(dates.toDate('2019-04-03')), 21);
102
- t.end();
103
- });
104
-
105
- test('\ndates holidays', t => {
106
- dates.locale('pt-BR');
107
- t.equal(dates.isHoliday(dates.toDate('2019-05-01T23:59Z')), true);
108
- // t.equal(dates.isHoliday(dates.toDate('2019-05-01')), true);
109
- t.equal(dates.isHoliday(dates.toDate('2019-04-21T23:59Z')), false);
110
- t.equal(dates.isHoliday(dates.toDate('2019-11-11T23:59Z')), false);
111
- dates.locale('en-US');
112
- t.equal(dates.isHoliday(dates.toDate('2019-05-01T23:59Z')), false);
113
- t.equal(dates.isHoliday(dates.toDate('2019-04-21T23:59Z')), false);
114
- t.equal(dates.isHoliday(dates.toDate('2019-11-11T23:59Z')), true);
115
- t.end();
116
- });
117
-
118
- test('\ndates workingDaysBetween', t => {
119
- dates.locale('pt-BR');
120
- let xData1 = dates.toDate('2019-01-03');
121
- let xData2 = dates.toDate('2019-05-30');
122
- t.equal(dates.workingDaysBetween(xData1, xData2), 101);
123
- xData1 = dates.toDate('2019-05-01');
124
- xData2 = dates.toDate('2019-05-02');
125
- t.equal(dates.workingDaysBetween(xData1, xData2), 1);
126
- xData1 = dates.toDate('2019-04-30');
127
- xData2 = dates.toDate('2019-05-01');
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);
132
- xData1 = dates.toDate('2019-04-30');
133
- xData2 = dates.toDate('2019-05-02');
134
- t.equal(dates.workingDaysBetween(xData1, xData2), 1);
135
- xData1 = dates.toDate('1995-12-31');
136
- xData2 = dates.toDate('2018-12-31');
137
- t.equal(dates.workingDaysBetween(xData1, xData2), 5774);
138
- xData1 = dates.toDate('1995-01-01');
139
- xData2 = dates.toDate('2018-12-31');
140
- t.equal(dates.workingDaysBetween(xData1, xData2), 6022);
141
- xData1 = dates.toDate('1995-01-03');
142
- xData2 = dates.toDate('2070-01-03');
143
- t.equal(dates.workingDaysBetween(xData1, xData2), 18835);
144
- xData1 = dates.toDate('2019-08-05');
145
- xData2 = dates.toDate('2019-08-04');
146
- t.equal(dates.workingDaysBetween(xData1, xData2), 0);
147
- xData1 = dates.toDate('2019-08-03');
148
- xData2 = dates.toDate('2019-08-02');
149
- t.equal(dates.workingDaysBetween(xData1, xData2), 1);
150
- xData1 = dates.toDate('2019-08-02');
151
- xData2 = dates.toDate('2019-08-03');
152
- t.equal(dates.workingDaysBetween(xData1, xData2), 0);
153
- xData1 = dates.toDate('2019-05-01');
154
- xData2 = dates.toDate('2019-05-01');
155
- t.equal(dates.workingDaysBetween(xData1, xData2), 0);
156
- xData1 = dates.toDate('2019-05-02');
157
- xData2 = dates.toDate('2019-05-01');
158
- t.equal(dates.workingDaysBetween(xData1, xData2), 0);
159
- xData1 = dates.toDate('2019-05-01');
160
- xData2 = dates.toDate('2019-05-02');
161
- t.equal(dates.workingDaysBetween(xData1, xData2), 1);
162
- xData1 = dates.toDate('2019-08-03');
163
- xData2 = dates.toDate('2019-08-03');
164
- t.equal(dates.workingDaysBetween(xData1, xData2), 0);
165
- xData1 = dates.toDate('2019-08-02');
166
- xData2 = dates.toDate('2019-08-03');
167
- t.equal(dates.workingDaysBetween(xData1, xData2), 0);
168
- xData1 = dates.toDate('2019-08-01');
169
- xData2 = dates.toDate('2019-08-03');
170
- t.equal(dates.workingDaysBetween(xData1, xData2), 1);
171
-
172
- t.end();
173
- });
174
-
175
- test('\ndates addmonth', t => {
176
- t.equal(formatDateCustom(dates.addMonths(dates.toDate('2019-01-31'), 1), 'DD/MM/YY'), '28/02/19');
177
- t.equal(formatDateCustom(dates.addMonths(dates.toDate('2019-01-31T23:59:59'), 1), 'DD/MM/YY'), '28/02/19');
178
- t.end();
179
- });
180
-
181
- test('\ndates isExpired', t => {
182
- t.equal(dates.isExpired(dates.addDays(dates.toDate(), -1), 1), true);
183
- t.equal(dates.isExpired(dates.addDays(dates.toDate(), 1), 1), false);
184
- t.end();
185
- });
186
-
187
- test('\ndates addYears', t => {
188
- t.equal(formatDateCustom(dates.addYears(dates.toDate('2019-01-31T23:59:59'), 1), 'DD/MM/YY'), '31/01/20');
189
- t.end();
190
- });
191
-
192
- test('\ndates daysBetween', t => {
193
- t.equal(dates.daysBetween(dates.toDate('2018-12-31'), dates.toDate('2018-12-31')), 0);
194
- t.equal(dates.daysBetween(dates.toDate('2018-12-31'), dates.toDate('2018-12-30')), -1);
195
- t.equal(dates.daysBetween(dates.toDate('2018-12-30'), dates.toDate('2018-12-31')), 1);
196
- t.equal(dates.daysBetween(dates.toDate('2018-12-30T00:01Z'), dates.toDate('2018-12-31T23:01Z'), true), 1);
197
- t.equal(dates.daysBetween(dates.toDate('2018-12-30T23:01Z'), dates.toDate('2018-12-31T00:01Z'), true), 1);
198
- t.equal(dates.daysBetween(dates.toDate('2018-01-01T00:01Z'), dates.toDate('2018-01-02T23:59Z'), true), 1);
199
- t.equal(
200
- dates.daysBetween(dates.toDate('2018-01-01T00:01Z'), dates.toDate('2018-01-02T23:59Z')),
201
- 1.9986111111111111
202
- );
203
- t.end();
204
- });
205
- test('\ndates yearsBetween', t => {
206
- t.equal(
207
- dates.yearsBetween(dates.toDate('2018-12-31T23:59Z'), dates.toDate('2019-01-01T00:01Z')),
208
- 0.0000037335722819593786
209
- );
210
- t.equal(dates.yearsBetween(dates.toDate('2018-12-31T23:59Z'), dates.toDate('2019-01-01T00:01Z'), true), 1);
211
- t.end();
212
- });
213
-
214
- test('\ndates getWeekends', t => {
215
- t.equal(dates.weekends(dates.toDate('2019-04-27'), dates.toDate('2019-05-03')), 1, '2019-04-27 2019-05-03');
216
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-03')), 0, '2019-05-01 2019-05-03');
217
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-04')), 1, '2019-05-01 2019-05-04');
218
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-05')), 2, '2019-05-01 2019-05-05');
219
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-06')), 2, '2019-05-01 2019-05-06');
220
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-07')), 2, '2019-05-01 2019-05-07');
221
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-10')), 2, '2019-05-01 2019-05-10');
222
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-11')), 3, '2019-05-01 2019-05-11');
223
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-12')), 4, '2019-05-01 2019-05-12');
224
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-13')), 4, '2019-05-01 2019-05-13');
225
- t.equal(dates.weekends(dates.toDate('2019-05-13'), dates.toDate('2019-05-01')), 4, '2019-05-13 2019-05-01');
226
- t.equal(dates.weekends(dates.toDate('2019-05-01'), dates.toDate('2019-05-14')), 4, '2019-05-01 2019-05-14');
227
- t.equal(dates.weekends(dates.toDate('2019-05-04'), dates.toDate('2019-05-05')), 1, '2019-05-04 2019-05-05');
228
- t.equal(dates.weekends(dates.toDate('2019-05-04'), dates.toDate('2019-05-06')), 1, '2019-05-04 2019-05-06');
229
- t.equal(dates.weekends(dates.toDate('2019-05-04'), dates.toDate('2019-05-07')), 1, '2019-05-04 2019-05-07');
230
-
231
- t.equal(dates.weekends(dates.toDate('2019-05-05'), dates.toDate('2019-05-06')), 0, '2019-05-05 2019-05-06');
232
- t.equal(dates.weekends(dates.toDate('2019-05-05'), dates.toDate('2019-05-07')), 0, '2019-05-05 2019-05-07');
233
- t.equal(dates.weekends(dates.toDate('2019-05-05'), dates.toDate('2019-05-08')), 0, '2019-05-05 2019-05-08');
234
- t.end();
235
- });
236
-
237
- test('\ndates weekOfMonth (absolute)', t => {
238
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-01'), true), 1);
239
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-08'), true), 2);
240
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-15'), true), 3);
241
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-22'), true), 4);
242
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-25'), true), 5);
243
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-31'), true), 6);
244
- t.end();
245
- });
246
-
247
- test('\ndates weekOfMonth', t => {
248
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-01')), 1);
249
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-08')), 2);
250
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-15')), 3);
251
- t.equal(dates.weekOfMonth(dates.toDate('2022-01-25')), 4);
252
- t.end();
253
- });
254
-
255
- test('\ndates weekOfYear', t => {
256
- t.equal(dates.weekOfYear(dates.toDate('2022-01-01')), 1);
257
- t.equal(dates.weekOfYear(dates.toDate('2022-01-08')), 2);
258
- t.equal(dates.weekOfYear(dates.toDate('2022-01-15')), 3);
259
- t.equal(dates.weekOfYear(dates.toDate('2022-01-22')), 4);
260
- t.equal(dates.weekOfYear(dates.toDate('2022-01-24')), 5);
261
- t.end();
262
- });
263
-
264
- test('\ndates weekOf "month"', t => {
265
- t.deepEqual(dates.weekOf(dates.toDate('2022-01-01')), { month: 1, year: 1 });
266
- t.deepEqual(dates.weekOf(dates.toDate('2022-01-08')), { month: 2, year: 2 });
267
- t.deepEqual(dates.weekOf(dates.toDate('2022-01-15')), { month: 3, year: 3 });
268
- t.deepEqual(dates.weekOf(dates.toDate('2022-01-25')), { month: 4, year: 5 });
269
- t.end();
270
- });
@@ -1,80 +0,0 @@
1
- const test = require('tape');
2
-
3
- const formats = require('../utils/formats');
4
- formats.LOCALE = 'pt-BR';
5
- formats.CURRENCY = 'BRL'; //'EUR';
6
-
7
- formats.locale('pt-BR');
8
-
9
- test('\nformats.formatPhone', t => {
10
- t.equal(formats.formatPhone('12345678', '21', '55'), '+55 (21) 1234-5678');
11
- t.equal(formats.formatPhone(12345678, '21', 55), '+55 (21) 1234-5678');
12
- t.equal(formats.formatPhone(12345678, '21'), '(021) 1234-5678');
13
- t.end();
14
- });
15
-
16
- test('\nformats.friendlyNumber', t => {
17
- t.equal(formats.friendlyNumber(123, 0, true), `R$${String.fromCharCode(160)}123`);
18
- t.equal(formats.friendlyNumber(123, 0, false), '123');
19
- t.equal(formats.friendlyNumber(1234567, 0, false), '1 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');
23
- t.equal(formats.friendlyNumber(1234000, 0, false), '1 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');
32
- t.equal(formats.friendlyNumber(0, 3, false), '0');
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`);
35
- t.end();
36
- });
37
-
38
- test('\nformats.friendlyBetweenDates', t => {
39
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2025-12-31T14:05:20.000Z'), '6 anos e 6 meses');
40
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2022-10-30T14:05:20.000Z'), '3 anos e 4 meses');
41
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2021-06-24T14:05:20.000Z'), '2 anos');
42
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2020-06-24T14:05:20.000Z'), 'um ano');
43
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2019-12-24T14:05:20.000Z'), '6 meses');
44
- t.equal(formats.friendlyBetweenDates('2019-02-28T14:05:20.000Z', '2019-03-28T14:05:20.000Z'), 'um mês');
45
-
46
- t.equal(formats.friendlyBetweenDates('2019-02-28T14:05:20.000Z', '2019-03-05T14:05:20.000Z'), '5 dias');
47
-
48
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2019-06-29T14:05:20.000Z'), '5 dias');
49
-
50
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2019-06-25T14:05:20.000Z'), 'um dia');
51
-
52
- t.equal(formats.friendlyBetweenDates('2019-06-24T14:05:20.000Z', '2019-06-24T14:05:20.000Z'), '');
53
-
54
- t.end();
55
- });
56
-
57
- test('\nformats.friendlyDate', t => {
58
- t.equal(formats.friendlyDate(8), '8 dias');
59
- t.equal(formats.friendlyDate(365), 'um ano');
60
- t.equal(formats.friendlyDate(366), 'um ano e um dia');
61
- t.equal(formats.friendlyDate(370), 'um ano e 5 dias');
62
- t.equal(formats.friendlyDate(430), 'um ano e 2 meses');
63
- t.equal(formats.friendlyDate(770), '2 anos e um mês');
64
- t.equal(formats.friendlyDate(800), '2 anos e 2 meses');
65
- //@ts-ignore
66
- t.equal(formats.friendlyDate('d'), '');
67
- t.equal(formats.friendlyDate(null), '');
68
- t.end();
69
- });
70
-
71
- test('\nformats.duration', t => {
72
- t.equal(formats.duration(100), 'poucos segundos');
73
- t.equal(formats.duration(1000), 'poucos segundos');
74
- t.equal(formats.duration(30000), 'poucos segundos');
75
- t.equal(formats.duration(59999), 'um minuto');
76
- t.equal(formats.duration(60000), 'um minuto');
77
- t.equal(formats.duration(3600000), 'uma hora');
78
- t.equal(formats.duration(86400000), 'um dia');
79
- t.end();
80
- });
@@ -1,26 +0,0 @@
1
- const test = require('tape');
2
- const invests = require('../utils/invests');
3
-
4
- test('\ninvests - i', t => {
5
- let xData = {};
6
- xData = { n: 24, pv: 2500000, pmt: -217972.55, fv: 0, type: 0 };
7
- t.equal(invests.i(xData), 6.9999999);
8
- xData = { n: 24, pv: 2500000, pmt: -217972.55, fv: 1000000, type: 0 };
9
- t.equal(invests.i(xData), 5.94256711);
10
- xData = { n: 24, pv: 1000000, pmt: -217972.55, fv: 0, type: 0 };
11
- t.equal(invests.i(xData), 21.59763755);
12
- t.end();
13
- });
14
-
15
- test('\ninvests - fv', t => {
16
- let xData = {};
17
- xData = { n: 12, pv: 400, pmt: -1040, i: 3, type: 0 };
18
- t.equal(invests.fv(xData), 14189.40638926);
19
- xData = { n: 12, pv: 0, pmt: -1040, i: 3, type: 0 };
20
- t.equal(invests.fv(xData), 14759.710744);
21
- xData = { n: 12, pv: 0, pmt: -1040, i: -3, type: 0 };
22
- t.equal(invests.fv(xData), 10613.46481882);
23
- xData = { n: 12, pv: 400, pmt: 1040, i: 3, type: 0 };
24
- t.equal(invests.fv(xData), -15330.01509874);
25
- t.end();
26
- });
@@ -1,11 +0,0 @@
1
- const test = require('tape');
2
-
3
- const { CreatedMessage } = require('../messages/Success');
4
- const { BasicMessageSuccess } = require('../messages/BasicMessages');
5
-
6
- console.log(new CreatedMessage() instanceof BasicMessageSuccess);
7
-
8
- test('\nmessage', t => {
9
- t.equal(new CreatedMessage() instanceof BasicMessageSuccess, true);
10
- t.end();
11
- });
@@ -1,81 +0,0 @@
1
- const test = require('tape');
2
-
3
- const numbers = require('../utils/numbers');
4
-
5
- test('\nnumbers weightedMean', t => {
6
- t.equal(numbers.weightedMean([300, 100, 10], [10, 20, 50]), 68.75);
7
- t.end();
8
- });
9
-
10
- test('\nnumbers onlyNumbers', t => {
11
- t.equal(numbers.onlyNumbers('00.332.123/0001-33'), '00332123000133');
12
- t.equal(numbers.onlyNumbers(''), '');
13
- t.equal(numbers.onlyNumbers(null), null);
14
- t.equal(numbers.onlyNumbers('"#1.3.45678+-2'), '13456782');
15
- t.end();
16
- });
17
-
18
- test('\nnumbers apart', t => {
19
- t.deepEqual(numbers.apart(1.12), { sign: '', int: '1', dec: '12' });
20
- t.deepEqual(numbers.apart(1.123456789012345678), {
21
- sign: '',
22
- int: '1',
23
- dec: '1234567890123457'
24
- });
25
- t.deepEqual(numbers.apart(-1.123456789012345678), {
26
- sign: '-',
27
- int: '1',
28
- dec: '1234567890123457'
29
- });
30
- t.end();
31
- });
32
-
33
- test('\nnumbers add', t => {
34
- t.equal(numbers.add(1.13, 1.12), 2.25);
35
- t.equal(numbers.add(1.000000013, 1.000000012), 2.000000025);
36
- t.equal(numbers.add(1234.5689012345, 4.5689012345), 1239.137802469);
37
- t.equal(numbers.add(-1.4689012345, -3314.5689012345), -3316.037802469);
38
- t.equal(numbers.add(0.00000000001, 0.1), 0.10000000001);
39
- t.equal(numbers.add(0.00000000001, 0.0000000001), 0.00000000011);
40
- t.equal(numbers.add(0.000000000013, -0.000000000014), -0.000000000001);
41
- t.equal(numbers.add(1234567890.123, 1.12), 1234567891.243);
42
- t.end();
43
- });
44
-
45
- test('\nnumbers sub', t => {
46
- t.equal(numbers.sub(1.13, 1.12), 0.01);
47
- t.equal(numbers.sub(1.000000013, 1.000000012), 0.000000001);
48
- t.equal(numbers.sub(1234.5689012345, 4.5689012345), 1230);
49
- t.equal(numbers.sub(12.5689012345, -3314.5689012345), 3327.137802469);
50
- t.equal(numbers.sub(0.00000000001, 0.1), -0.09999999999);
51
- t.equal(numbers.sub(0.00000000001, -0.0000000001), 0.00000000011);
52
- t.equal(numbers.sub(0.000000000013, 0.000000000014), -0.000000000001);
53
- t.equal(numbers.sub(-1234567890.123, 1.12), -1234567891.243);
54
- t.end();
55
- });
56
-
57
- test('\nnumbers mul', t => {
58
- t.equal(numbers.mul(-2.2, -2.1), 4.62);
59
- t.equal(numbers.mul(1.1, 1.1), 1.21);
60
- t.equal(numbers.mul(3, 0.15), 0.45);
61
- t.equal(numbers.mul(-0.000001, 1.01), -0.00000101);
62
- t.equal(numbers.mul(244.123, 13), 3173.599);
63
- t.equal(numbers.mul(1.123, 12), 13.476);
64
- t.equal(numbers.mul(12.4344, 1.1), 13.67784);
65
- t.equal(numbers.mul(0.4344, 0.0021), 0.00091224);
66
- t.equal(numbers.mul(10.4344, 0.00021), 0.002191224);
67
- t.equal(numbers.mul(2, 4.01), 8.02);
68
- t.equal(numbers.mul(12345679.012, 1.021), 12604938.271252);
69
- t.equal(numbers.mul(4.300000000000001, 5), 21.500000000000004);
70
- t.equal(numbers.mul(4.0001, 5.0002), 20.00130002);
71
- t.equal(numbers.mul(4.0001, 5.0002), 20.00130002);
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
- t.end();
75
- });
76
-
77
- test('\nnumbers div', t => {
78
- t.equal(numbers.div(1222.1, 0.00000001), 122210000000);
79
- t.equal(numbers.div(1.001, 1.1), 0.91);
80
- t.end();
81
- });
@@ -1,16 +0,0 @@
1
- const test = require('tape');
2
- const objects = require('../utils/objects');
3
- const object = {
4
- nome: 'investira',
5
- endereco: {
6
- logradouro: 'Praia de Botafogo',
7
- numero: 501
8
- },
9
- telefone: '(21) 2586-6322'
10
- };
11
-
12
- test('\ngetSize', t => {
13
- const xObject = { ...object };
14
- t.equal(objects.getSize(xObject), 3);
15
- t.end();
16
- });
@@ -1,42 +0,0 @@
1
- const test = require('tape');
2
-
3
- const spellChecker = require('../utils/spellChecker');
4
-
5
- spellChecker.locale = 'br';
6
- test('\ncheck', t => {
7
- t.equal(
8
- spellChecker.check('Volnor Industria E Comercio Sa'),
9
- 'Volnor Indústria e Comércio S.A.'
10
- );
11
- t.equal(
12
- spellChecker.check(
13
- 'Viver Incorp. E Construtora S.a.- Em Recuperação Judicial'
14
- ),
15
- 'Viver Incorp. e Construtora S.A. em Recuperação Judicial'
16
- );
17
- t.equal(
18
- spellChecker.check('Xx De Novembro Investimentos E Participações S.a'),
19
- 'XX de Novembro Investimentos e Participações S.A.'
20
- );
21
- t.equal(
22
- spellChecker.check('Banco Do Estado De Sao Paulo S.a. - Banespa'),
23
- 'Banco do Estado de São Paulo S.A. - Banespa'
24
- );
25
- t.equal(
26
- spellChecker.check('Sperb Do Ne Sa Ind Textil'),
27
- 'Sperb do Ne S.A. Indústria Textil'
28
- );
29
- t.equal(
30
- spellChecker.check('São Carlos Empreends E Participações S.a'),
31
- 'São Carlos Empreendimentos e Participações S.A.'
32
- );
33
- t.equal(
34
- spellChecker.check('Inds De Bebs Joaquim T A F Sa'),
35
- 'Indústria de Bebidas Joaquim T A F S.A.'
36
- );
37
- t.equal(
38
- spellChecker.check('Cia Indl Schlosser Sa - Em Recuperação Judicial'),
39
- 'Cia Industrial Schlosser S.A. - em Recuperação Judicial'
40
- );
41
- t.end();
42
- });
@@ -1,46 +0,0 @@
1
- const test = require('tape');
2
-
3
- const strings = require('../utils/strings');
4
-
5
- test('\nsplitFullName', t => {
6
- t.deepEqual(strings.splitFullName('Robert Mariano de faria silva e souza'), {
7
- first: 'Robert',
8
- middle: 'Mariano de Faria Silva e',
9
- last: 'Souza'
10
- });
11
- t.deepEqual(strings.splitFullName('Investira Soluções'), {
12
- first: 'Investira',
13
- middle: null,
14
- last: 'Soluções'
15
- });
16
- t.end();
17
- });
18
-
19
- test('\nquerystringToObject', t => {
20
- t.deepEqual(strings.querystringToObject('api/v1/metas/?meta_status=A,I,R&page=1&size=8'), {
21
- meta_status: 'A,I,R',
22
- page: '1',
23
- size: '8'
24
- });
25
- t.end();
26
- });
27
-
28
- test('\ntoTitleCase', t => {
29
- t.deepEqual(strings.toTitleCase('Robert mariano de faria silva e souza'), 'Robert Mariano de Faria Silva e Souza');
30
- t.deepEqual(strings.toTitleCase('Investira soluções'), 'Investira Soluções');
31
- t.deepEqual(strings.toTitleCase('maRtin lutHer king III'), 'Martin Luther King III');
32
- t.deepEqual(strings.toTitleCase('maRtin lutHer king iv'), 'Martin Luther King IV');
33
- t.deepEqual(strings.toTitleCase('joão adalberto da silva álves'), 'João Adalberto da Silva Álves');
34
- t.deepEqual(strings.toTitleCase("Alberto D'avila"), "Alberto D'Avila");
35
- t.deepEqual(strings.toTitleCase('Alberto D`avila'), 'Alberto D`Avila');
36
- t.deepEqual(strings.toTitleCase('F.a.e.'), 'F.A.E.');
37
- t.end();
38
- });
39
-
40
- test('\nwhitespacesCleaner', t => {
41
- t.deepEqual(
42
- strings.whitespacesCleaner(' Robert mariano de faria silva e souza '),
43
- 'Robert mariano de faria silva e souza'
44
- );
45
- t.end();
46
- });
@@ -1,49 +0,0 @@
1
- const test = require('tape');
2
-
3
- const validators = require('../utils/validators');
4
-
5
- test('\nvalidators.isEmail', t => {
6
- t.equal(validators.isEmail('12345678'), false);
7
- t.equal(validators.isEmail('1234@5678'), false);
8
- t.equal(validators.isEmail('1234@5678.'), false);
9
- t.equal(validators.isEmail('1234@5678.v'), false);
10
- t.equal(validators.isEmail('1234@5678.vc'), true);
11
- t.equal(validators.isEmail('1234@5678.us'), true);
12
- t.equal(validators.isEmail('123@asdocm.com.br'), true);
13
- t.equal(validators.isEmail('wedweasdocm.com.br'), false);
14
- t.end();
15
- });
16
-
17
- test('\nvalidators.isTrue', t => {
18
- t.equal(validators.isTrue('1'), true);
19
- t.equal(validators.isTrue('-1'), true);
20
- t.equal(validators.isTrue(-1), true);
21
- t.equal(validators.isTrue(1), true);
22
- t.equal(validators.isTrue(true), true);
23
- t.equal(validators.isTrue('true'), true);
24
- t.equal(validators.isTrue('True'), true);
25
- t.equal(validators.isTrue(2), false);
26
- t.equal(validators.isTrue(), false);
27
- t.equal(validators.isTrue(null), false);
28
- t.equal(validators.isTrue(0), false);
29
- t.equal(validators.isTrue('0'), false);
30
- t.equal(validators.isTrue({}), false);
31
- t.equal(validators.isTrue(undefined), false);
32
- t.equal(validators.isTrue('-12'), false);
33
- t.equal(validators.isTrue('false'), false);
34
- t.equal(validators.isTrue(false), false);
35
- t.end();
36
- });
37
-
38
- test('\nvalidators.isNumber', t => {
39
- t.equal(validators.isNumber(1), true);
40
- t.equal(validators.isNumber(-1), true);
41
- t.equal(validators.isNumber(0), true);
42
- t.equal(validators.isNumber('1'), false);
43
- t.equal(validators.isNumber('-1'), false);
44
- t.equal(validators.isNumber(1.5), true);
45
- t.equal(validators.isNumber('1.5'), false);
46
- t.equal(validators.isNumber('1,5'), false);
47
- t.equal(validators.isNumber(NaN), false);
48
- t.end();
49
- });