boletos-ademitech 1.0.0

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.
Files changed (60) hide show
  1. package/.eslintrc.json +25 -0
  2. package/LICENSE +661 -0
  3. package/README.md +50 -0
  4. package/examples/gerar-boleto-BancoDoBrasil.js +72 -0
  5. package/examples/gerar-boleto-bradesco.js +58 -0
  6. package/examples/gerar-boleto-cecred.js +59 -0
  7. package/index.d.ts +372 -0
  8. package/lib/boleto/bancos/banco-do-brasil.js +125 -0
  9. package/lib/boleto/bancos/bradesco.js +115 -0
  10. package/lib/boleto/bancos/caixa.js +140 -0
  11. package/lib/boleto/bancos/cecred.js +117 -0
  12. package/lib/boleto/bancos/itau.js +124 -0
  13. package/lib/boleto/bancos/logotipos/ailos.png +0 -0
  14. package/lib/boleto/bancos/logotipos/banco-do-brasil.png +0 -0
  15. package/lib/boleto/bancos/logotipos/bradesco.png +0 -0
  16. package/lib/boleto/bancos/logotipos/caixa-economica-federal.png +0 -0
  17. package/lib/boleto/bancos/logotipos/itau.png +0 -0
  18. package/lib/boleto/bancos/logotipos/santander.png +0 -0
  19. package/lib/boleto/bancos/logotipos/sicoob.png +0 -0
  20. package/lib/boleto/bancos/logotipos/sicredi.png +0 -0
  21. package/lib/boleto/bancos/santander.js +118 -0
  22. package/lib/boleto/bancos/sicoob.js +118 -0
  23. package/lib/boleto/bancos/sicredi.js +143 -0
  24. package/lib/boleto/codigo-de-barras-builder.js +38 -0
  25. package/lib/boleto/fontes/Code25I.ttf +0 -0
  26. package/lib/boleto/fontes/Times New Roman Bold Italic.ttf +0 -0
  27. package/lib/boleto/fontes/Times New Roman Bold.ttf +0 -0
  28. package/lib/boleto/fontes/Times New Roman Italic.ttf +0 -0
  29. package/lib/boleto/fontes/Times New Roman.ttf +0 -0
  30. package/lib/boleto/gerador-de-boleto.js +1198 -0
  31. package/lib/boleto/gerador-de-digito-padrao.js +42 -0
  32. package/lib/boleto/gerador-de-linha-digitavel.js +26 -0
  33. package/lib/boleto/imagens/tesoura128.png +0 -0
  34. package/lib/boleto/valida-codigo-barras.js +12 -0
  35. package/lib/index.js +14 -0
  36. package/lib/metodosPublicos/boletoMetodos.js +50 -0
  37. package/lib/pdf-gerador.js +26 -0
  38. package/lib/stringify/boletoStringify.js +49 -0
  39. package/lib/utils/array-utils.js +13 -0
  40. package/lib/utils/date-utils.js +8 -0
  41. package/lib/utils/functions/bancosUtils.js +104 -0
  42. package/lib/utils/functions/boletoUtils.js +895 -0
  43. package/lib/utils/functions/formatacoesUtils.js +287 -0
  44. package/lib/utils/functions/validacoesUtils.js +233 -0
  45. package/lib/utils/math-utils.js +53 -0
  46. package/lib/utils/object-utils.js +8 -0
  47. package/lib/utils/stream-utils.js +6 -0
  48. package/lib/utils/string-utils.js +60 -0
  49. package/package.json +60 -0
  50. package/tests/bancos-test.js +116 -0
  51. package/tests/boleto/bancos/bradesco-test.js +145 -0
  52. package/tests/boleto/bancos/caixa-test.js +428 -0
  53. package/tests/boleto/bancos/itau-test.js +342 -0
  54. package/tests/boleto/bancos/sicoob-test.js +341 -0
  55. package/tests/boleto/gerador-de-digito-padrao-test.js +22 -0
  56. package/tests/boleto-test.js +349 -0
  57. package/tests/brasil-test.js +66 -0
  58. package/tests/formatacoes-test.js +349 -0
  59. package/tests/validacoes-test.js +309 -0
  60. package/tmp/boletos/.gitkeep +0 -0
@@ -0,0 +1,22 @@
1
+ const GeradorDeDigitoPadrao = require('../../lib/boleto/gerador-de-digito-padrao');
2
+
3
+ module.exports = {
4
+ 'Verifica a geração de dígitos mod11': function(test) {
5
+ test.equal(5, GeradorDeDigitoPadrao.mod11('0019386000000040000000001207113000900020618'));
6
+ test.equal(6, GeradorDeDigitoPadrao.mod11('2379316800000001002949060000000000300065800'));
7
+ test.equal(3, GeradorDeDigitoPadrao.mod11('0000039104766'));
8
+ test.equal(3, GeradorDeDigitoPadrao.mod11('3999100100001200000351202000003910476618602'));
9
+ test.equal(1, GeradorDeDigitoPadrao.mod11('3999597400000001002461722000000001934404542'));
10
+
11
+ test.done();
12
+ },
13
+
14
+ 'Verifica a geração de dígitos mod10': function(test) {
15
+ test.equal(9, GeradorDeDigitoPadrao.mod10('237929490'));
16
+ test.equal(4, GeradorDeDigitoPadrao.mod10('6000000000'));
17
+ test.equal(9, GeradorDeDigitoPadrao.mod10('0300065800'));
18
+ test.equal(8, GeradorDeDigitoPadrao.mod10('399903512'));
19
+
20
+ test.done();
21
+ }
22
+ };
@@ -0,0 +1,349 @@
1
+ const boleto = require('../lib/utils/functions/boletoUtils');
2
+ const bancos = boleto.bancos;
3
+ const Endereco = boleto.Endereco;
4
+ const Gerador = boleto.Gerador;
5
+ const Boleto = boleto.Boleto;
6
+ const Datas = boleto.Datas;
7
+
8
+ module.exports = {
9
+ especiesDeDocumento: {
10
+ 'Verifica que contém o número correto de espécies': function(test) {
11
+ test.equals(Object.keys(boleto.especiesDeDocumento).length, 21);
12
+ test.done();
13
+ },
14
+ },
15
+
16
+ bancos: {
17
+ 'Todos os bancos estão disponíveis': function(test) {
18
+ test.ok(new bancos.Itau());
19
+ test.ok(new bancos['341']());
20
+
21
+ test.ok(new bancos.Caixa());
22
+ test.ok(new bancos['104']());
23
+
24
+ test.ok(new bancos.Bradesco());
25
+ test.ok(new bancos['237']());
26
+
27
+ test.ok(new bancos.Sicoob());
28
+ test.ok(new bancos['756']());
29
+
30
+ test.ok(new bancos.Cecred());
31
+ test.ok(new bancos['085']());
32
+ console.log(Object.keys(bancos).length);
33
+ test.equals(16, Object.keys(bancos).length);
34
+ test.done();
35
+ },
36
+ },
37
+
38
+ Gerador: {
39
+ 'Verifica que é possível instanciar o gerador': function(test) {
40
+ test.ok(new Gerador());
41
+ test.done();
42
+ },
43
+
44
+ 'Verifica que o gerador apresenta as funções esperadas': function(test) {
45
+ var gerador = new Gerador();
46
+
47
+ test.equal(typeof gerador.gerarPDF, 'function');
48
+ test.equal(typeof gerador.gerarHTML, 'function');
49
+ test.done();
50
+ },
51
+
52
+ 'Verifica que a geração de HTML lança uma exceção': function(test) {
53
+ test.throws(function() {
54
+ new Gerador().gerarHTML();
55
+ });
56
+
57
+ test.done();
58
+ }
59
+ },
60
+
61
+ Pagador: {
62
+
63
+ },
64
+
65
+ Beneficiario: {
66
+
67
+ },
68
+
69
+ Datas: {
70
+ 'É possível instanciar um objeto de datas': function(test) {
71
+ var datas = Datas.novasDatas();
72
+
73
+ test.ok(datas);
74
+ test.done();
75
+ },
76
+
77
+ 'Deve lançar exceção se as datas forem muito antigas': function(test) {
78
+ test.throws(function() {
79
+ Datas.novasDatas()
80
+ .comDocumento(1, 1, 1996)
81
+ .comVencimento(1, 1, 1996)
82
+ .comProcessamento(1, 1, 1996);
83
+ });
84
+
85
+ test.done();
86
+ },
87
+
88
+ 'Deve lançar exceção se as datas estiverem além de 2024': function(test) {
89
+ test.throws(function() {
90
+ Datas.novasDatas()
91
+ .comDocumento(1, 1, 2024)
92
+ .comVencimento(1, 1, 2024)
93
+ .comProcessamento(1, 1, 2024);
94
+ });
95
+
96
+ test.done();
97
+ }
98
+ },
99
+
100
+ Endereco: {
101
+ 'Deve imprimir endereco completo': function(test) {
102
+ var endereco = Endereco.novoEndereco()
103
+ .comLogradouro('RODOVIA SC 401, KM 1 - EDIFÍCIO CELTA')
104
+ .comBairro('PARQTEC ALFA')
105
+ .comCep('88030-000')
106
+ .comCidade('FLORIANÓPOLIS')
107
+ .comUf('SC');
108
+
109
+ test.equals(endereco.getEnderecoCompleto(), [
110
+ 'RODOVIA SC 401, KM 1 - EDIFÍCIO CELTA ',
111
+ 'PARQTEC ALFA 88.030-000 FLORIANÓPOLIS SC'
112
+ ].join(''));
113
+
114
+ test.done();
115
+ },
116
+
117
+ 'Deve imprimir endereco sem logradouro': function(test) {
118
+ var endereco = Endereco.novoEndereco()
119
+ .comBairro('PARQTEC ALFA')
120
+ .comCep('88030-000')
121
+ .comCidade('FLORIANÓPOLIS')
122
+ .comUf('SC');
123
+
124
+ test.equals(endereco.getEnderecoCompleto(), 'PARQTEC ALFA 88.030-000 FLORIANÓPOLIS SC');
125
+
126
+ test.done();
127
+ },
128
+
129
+ 'Deve imprimir endereco sem cep': function(test) {
130
+ var endereco = Endereco.novoEndereco()
131
+ .comLogradouro('RODOVIA SC 401, KM 1 - EDIFÍCIO CELTA')
132
+ .comBairro('PARQTEC ALFA')
133
+ .comCidade('FLORIANÓPOLIS')
134
+ .comUf('SC');
135
+
136
+ test.equals(endereco.getEnderecoCompleto(), [
137
+ 'RODOVIA SC 401, KM 1 - EDIFÍCIO CELTA ',
138
+ 'PARQTEC ALFA FLORIANÓPOLIS SC'
139
+ ].join(''));
140
+
141
+ test.done();
142
+ },
143
+
144
+ 'Deve imprimir vazio se endereço não preenchido': function(test) {
145
+ var endereco = Endereco.novoEndereco();
146
+
147
+ test.equals(endereco.getEnderecoCompleto(), '');
148
+ test.done();
149
+ },
150
+ },
151
+
152
+ Boleto: {
153
+ 'É possível instanciar um novo boleto': function(test) {
154
+ var boleto = Boleto.novoBoleto();
155
+
156
+ test.ok(boleto);
157
+ test.done();
158
+ },
159
+
160
+ 'Novo boleto deve ter alguns valores padrão': function(test) {
161
+ var boleto = Boleto.novoBoleto();
162
+
163
+ test.equals(boleto.getEspecieMoeda(), 'R$');
164
+ test.equals(boleto.getCodigoEspecieMoeda(), 9);
165
+ test.equals(boleto.getAceite(), false);
166
+ test.equals(boleto.getEspecieDocumento(), 'DV');
167
+
168
+ test.done();
169
+ },
170
+
171
+ 'Calcula corretamente o fator de vencimento': function(test) {
172
+ var dataDeVencimento = new Date(2015, 3 - 1, 21, 0, 0, 0, 0),
173
+ datas = Datas.novasDatas().comVencimento(dataDeVencimento),
174
+ boleto = Boleto.novoBoleto().comDatas(datas);
175
+
176
+ test.equals(boleto.getFatorVencimento(), '6374');
177
+ test.done();
178
+ },
179
+
180
+ 'Calcula corretamente o fator de vencimento, ignorando as horas - 1': function(test) {
181
+ var dataDeVencimento = new Date(2008, 5 - 1, 2, 0, 0, 0, 0),
182
+ datas = Datas.novasDatas().comVencimento(dataDeVencimento),
183
+ boleto = Boleto.novoBoleto().comDatas(datas);
184
+
185
+ test.equals(boleto.getFatorVencimento(), '3860');
186
+ test.done();
187
+ },
188
+
189
+ 'Calcula corretamente o fator de vencimento, ignorando as horas - 2': function(test) {
190
+ var dataDeVencimento = new Date(2008, 5 - 1, 2, 23, 59, 59, 999),
191
+ datas = Datas.novasDatas().comVencimento(dataDeVencimento),
192
+ boleto = Boleto.novoBoleto().comDatas(datas);
193
+
194
+ test.equals(boleto.getFatorVencimento(), '3860');
195
+ test.done();
196
+ },
197
+
198
+ 'Lança exceção ao tentar definir um valor negativo para o boleto': function(test) {
199
+ test.throws(function() {
200
+ Boleto.novoBoleto().comValorBoleto(-5);
201
+ });
202
+
203
+ test.done();
204
+ },
205
+
206
+ 'O valor formatado deve ter 10 digitos - 1': function(test) {
207
+ var boleto = Boleto.novoBoleto().comValorBoleto(3),
208
+ valorFormatado = boleto.getValorFormatado();
209
+
210
+ test.equals(10, valorFormatado.length);
211
+ test.equals('0000000300', valorFormatado);
212
+ test.done();
213
+ },
214
+
215
+ 'O valor formatado deve ter 10 digitos - 2': function(test) {
216
+ var boleto = Boleto.novoBoleto().comValorBoleto(3.1),
217
+ valorFormatado = boleto.getValorFormatado();
218
+
219
+ test.equals(10, valorFormatado.length);
220
+ test.equals('0000000310', valorFormatado);
221
+ test.done();
222
+ },
223
+
224
+ 'O valor formatado deve ter 10 digitos - 3': function(test) {
225
+ var boleto = Boleto.novoBoleto().comValorBoleto(3.18),
226
+ valorFormatado = boleto.getValorFormatado();
227
+
228
+ test.equals(10, valorFormatado.length);
229
+ test.equals('0000000318', valorFormatado);
230
+ test.done();
231
+ },
232
+
233
+ 'O valor formatado deve ter 10 digitos - 4': function(test) {
234
+ var boleto = Boleto.novoBoleto().comValorBoleto(300),
235
+ valorFormatado = boleto.getValorFormatado();
236
+
237
+ test.equals(10, valorFormatado.length);
238
+ test.equals('0000030000', valorFormatado);
239
+ test.done();
240
+ },
241
+
242
+ 'São consideradas apenas as primeiras duas casas decimais do valor': function(test) {
243
+ var boleto = Boleto.novoBoleto().comValorBoleto(3.189),
244
+ valorFormatado = boleto.getValorFormatado();
245
+
246
+ test.equals(10, valorFormatado.length);
247
+ test.equals('0000000318', valorFormatado);
248
+ test.done();
249
+ },
250
+
251
+ 'Número do documento formatado deve ter 4 digitos': function(test) {
252
+ var boleto = Boleto.novoBoleto().comNumeroDoDocumento('232'),
253
+ numeroFormatado = boleto.getNumeroDoDocumentoFormatado();
254
+
255
+ test.equals(4, numeroFormatado.length);
256
+ test.equals('0232', numeroFormatado);
257
+ test.done();
258
+ },
259
+
260
+ 'Boleto não deve aceitar mais do que cinco instruções': function(test) {
261
+ test.throws(function() {
262
+ Boleto.novoBoleto().comInstrucoes('', '', '', '', '', '');
263
+ });
264
+
265
+ test.throws(function() {
266
+ Boleto.novoBoleto().comInstrucoes(['', '', '', '', '', '']);
267
+ });
268
+
269
+ test.done();
270
+ },
271
+
272
+ 'Boleto não deve aceitar mais do que cinco descrições': function(test) {
273
+ test.throws(function() {
274
+ Boleto.novoBoleto().comDescricoes('', '', '', '', '', '');
275
+ });
276
+
277
+ test.throws(function() {
278
+ Boleto.novoBoleto().comDescricoes(['', '', '', '', '', '']);
279
+ });
280
+
281
+ test.done();
282
+ },
283
+
284
+ 'Boleto não deve aceitar mais do que dois locais de pagamento': function(test) {
285
+ test.throws(function() {
286
+ Boleto.novoBoleto().comLocaisDePagamento('', '', '');
287
+ });
288
+
289
+ test.throws(function() {
290
+ Boleto.novoBoleto().comLocaisDePagamento(['', '', '']);
291
+ });
292
+
293
+ test.done();
294
+ },
295
+
296
+ 'Não deve ser possivel definir um novo boleto com valor superior a R$ 99.999.999,99': function(test) {
297
+ test.throws(function() {
298
+ var boleto = Boleto.novoBoleto().comValorBoleto(100000000.00);
299
+ });
300
+
301
+ test.done();
302
+ },
303
+
304
+ 'Deve retornar formatação em formato legivel': function(test) {
305
+ var boleto;
306
+
307
+ boleto = Boleto.novoBoleto().comValorBoleto(0);
308
+ test.equal('R$ 0,00', boleto.getValorFormatadoBRL());
309
+
310
+ boleto = Boleto.novoBoleto().comValorBoleto(1);
311
+ test.equal('R$ 1,00', boleto.getValorFormatadoBRL());
312
+
313
+ boleto = Boleto.novoBoleto().comValorBoleto(1.2);
314
+ test.equal('R$ 1,20', boleto.getValorFormatadoBRL());
315
+
316
+ boleto = Boleto.novoBoleto().comValorBoleto(1.23);
317
+ test.equal('R$ 1,23', boleto.getValorFormatadoBRL());
318
+
319
+ boleto = Boleto.novoBoleto().comValorBoleto(1.235);
320
+ test.equal('R$ 1,23', boleto.getValorFormatadoBRL());
321
+
322
+ boleto = Boleto.novoBoleto().comValorBoleto(10.23);
323
+ test.equal('R$ 10,23', boleto.getValorFormatadoBRL());
324
+
325
+ boleto = Boleto.novoBoleto().comValorBoleto(100.23);
326
+ test.equal('R$ 100,23', boleto.getValorFormatadoBRL());
327
+
328
+ boleto = Boleto.novoBoleto().comValorBoleto(1000.23);
329
+ test.equal('R$ 1.000,23', boleto.getValorFormatadoBRL());
330
+
331
+ boleto = Boleto.novoBoleto().comValorBoleto(10002.23);
332
+ test.equal('R$ 10.002,23', boleto.getValorFormatadoBRL());
333
+
334
+ boleto = Boleto.novoBoleto().comValorBoleto(210002.23);
335
+ test.equal('R$ 210.002,23', boleto.getValorFormatadoBRL());
336
+
337
+ boleto = Boleto.novoBoleto().comValorBoleto(3210002.23);
338
+ test.equal('R$ 3.210.002,23', boleto.getValorFormatadoBRL());
339
+
340
+ boleto = Boleto.novoBoleto().comValorBoleto(13210002.23);
341
+ test.equal('R$ 13.210.002,23', boleto.getValorFormatadoBRL());
342
+
343
+ boleto = Boleto.novoBoleto().comValorBoleto(99999999.99);
344
+ test.equal('R$ 99.999.999,99', boleto.getValorFormatadoBRL());
345
+
346
+ test.done();
347
+ }
348
+ }
349
+ };
@@ -0,0 +1,66 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const utils = require('../lib/index');
4
+
5
+ var existsSync = (process.version.indexOf('v0.6') !== -1 ? require('path').existsSync : existsSync = fs.existsSync);
6
+
7
+ module.exports = {
8
+ 'Verifica que todos os submodulos estão disponíveis': function(test){
9
+ fs.readdirSync(path.join(__dirname, '/../lib')).forEach(function(file){
10
+ var match = file.match(/(.*)Utils.js/);
11
+
12
+ if(match){
13
+ //console.log(match[1] + " / " + typeof utils[match[1]]);
14
+ test.ok(utils[match[1]]);
15
+ }
16
+ });
17
+
18
+ test.done();
19
+ },
20
+
21
+ 'Verifica que para cada submodulo existe um arquivo de teste': function(test){
22
+ fs.readdirSync(path.join(__dirname, '/../lib')).forEach(function(file){
23
+ var match = file.match(/(.*)Utils.js/);
24
+
25
+ if(match){
26
+ var exists = existsSync(__dirname + '/' + match[1] + '-test.js');
27
+ //console.log(match[1] + " / " + exists);
28
+ test.ok(exists);
29
+ }
30
+ });
31
+
32
+ test.done();
33
+ },
34
+
35
+ 'Verifica que para cada propriedade exposta por um submodulo existe um conjunto de testes': function(test){
36
+ fs.readdirSync(path.join(__dirname, '/../lib')).forEach(function(file){
37
+ var match = file.match(/(.*)Utils.js/);
38
+
39
+ if(match){
40
+ var testFilePath = __dirname + '/' + match[1] + '-test.js';
41
+ var exists = existsSync(testFilePath);
42
+ if(exists){
43
+ var submoduleTest = require(testFilePath);
44
+ var submodule = require(__dirname + '/../lib/' + file);
45
+
46
+ //console.log(match[1] + " / " + file);
47
+
48
+ for(var property in submodule){
49
+ if(Object.prototype.isPrototypeOf.call(submodule,property)){
50
+ var temTeste = property in submoduleTest;
51
+
52
+ if(!temTeste) {
53
+ console.error(' > Missing tests for: ' + match[1] + ':' + property);
54
+ }
55
+
56
+ test.ok(temTeste);
57
+ }
58
+ }
59
+
60
+ }
61
+ }
62
+ });
63
+
64
+ test.done();
65
+ }
66
+ };