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
package/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # boletos.ts
2
+
3
+ #### NPM badges
4
+ <!-- [START badges] -->
5
+ [![NPM boletos.ts package](https://img.shields.io/npm/v/boletos.ts.svg)](https://npmjs.org/package/boletos.ts)
6
+ [![npm downloads](https://img.shields.io/npm/dm/boletos.ts.svg?maxAge=604800)](https://npm-stat.com/charts.html?package=boletos.ts&from=2017-01-1)
7
+ [![npm downloads](https://img.shields.io/npm/dt/boletos.ts.svg?maxAge=604800)](https://npm-stat.com/charts.html?package=boletos.ts&from=2017-01-1)
8
+ <!-- [END badges] -->
9
+
10
+ Biblioteca em Node.js para geração de boletos utilizando PDFKit
11
+
12
+ Geração de boletos para bancos:
13
+ - Bradesco
14
+ - Caixa
15
+ - Ailos (Cecred)
16
+ - Itaú
17
+ - Sicoob
18
+ - Sicredi
19
+ - Santander
20
+ - Banco do Brasil
21
+
22
+ ### Install
23
+
24
+ ```javascript
25
+ npm i boletos.ts
26
+ ```
27
+ ```javascript
28
+ yarn add boletos.ts
29
+ ```
30
+ ### Exemplos de uso
31
+
32
+ ```javascript
33
+ npm run gerarBrasil
34
+ ```
35
+ ```javascript
36
+ npm run gerarBradesco
37
+ ```
38
+ ```javascript
39
+ npm run gerarCecred
40
+ ```
41
+
42
+ * [pasta com arquivos de exemplo](/examples)
43
+
44
+ ### Run tests
45
+
46
+ ```javascript
47
+ npm run test
48
+ ```
49
+
50
+
@@ -0,0 +1,72 @@
1
+ const { Bancos, Boletos, streamToPromise } = require('../lib/index');
2
+ const QrCode = require('qrcode');
3
+
4
+ gerarBoletoBB().then(r => r);
5
+
6
+ async function gerarBoletoBB(){
7
+ const boleto = {
8
+ banco: new Bancos.BancoBrasil(),
9
+ pagador: {
10
+ nome: 'José Bonifácio de Andrada',
11
+ registroNacional: '12345678',
12
+ endereco: {
13
+ logradouro: 'Rua Pedro Lessa, 15',
14
+ bairro: 'Centro',
15
+ cidade: 'Rio de Janeiro',
16
+ estadoUF: 'RJ',
17
+ cep: '20030-030'
18
+ }
19
+ },
20
+ instrucoes: ['Após o vencimento Mora dia R$ 1,59', 'Após o vencimento, multa de 2%'],
21
+ beneficiario: {
22
+ nome: 'Empresa Fictícia LTDA',
23
+ cnpj:'43576788000191',
24
+ dadosBancarios: {
25
+ carteira: '09',
26
+ agencia: '18455',
27
+ agenciaDigito: '4',
28
+ conta: '1277165',
29
+ contaDigito: '1',
30
+ nossoNumero: '00000000061',
31
+ nossoNumeroDigito: '8'
32
+ },
33
+ endereco: {
34
+ logradouro: 'Rua Pedro Lessa, 15',
35
+ bairro: 'Centro',
36
+ cidade: 'Rio de Janeiro',
37
+ estadoUF: 'RJ',
38
+ cep: '20030-030'
39
+ }
40
+ },
41
+ boleto: {
42
+ numeroDocumento: '1001',
43
+ especieDocumento: 'DM',
44
+ valor: 110.00,
45
+ datas: {
46
+ vencimento: '02-04-2020',
47
+ processamento: '02-04-2019',
48
+ documentos: '02-04-2019'
49
+ },
50
+ emv: 'teste.com.br', //preencher aqui com o texto do Pix Copia e Copia,
51
+ imagemQrCode: '',
52
+ }
53
+ };
54
+
55
+ if (boleto.boleto.emv){
56
+ boleto.boleto.imagemQrCode = await gerarQrCodePix(boleto.boleto.emv);
57
+ }
58
+
59
+ const novoBoleto = new Boletos(boleto);
60
+ novoBoleto.gerarBoleto();
61
+
62
+ novoBoleto.pdfFile().then(async ({ stream }) => {
63
+ // ctx.res.set('Content-type', 'application/pdf');
64
+ await streamToPromise(stream);
65
+ }).catch((error) => {
66
+ return error;
67
+ });
68
+ }
69
+
70
+ async function gerarQrCodePix(emv) {
71
+ return QrCode.toDataURL(emv, { errorCorrectionLevel: 'H' });
72
+ }
@@ -0,0 +1,58 @@
1
+ const {Bancos, Boletos, streamToPromise} = require('../lib/index');
2
+
3
+ const boleto = {
4
+ banco: new Bancos.Bradesco(),
5
+ pagador: {
6
+ nome: 'José Bonifácio de Andrada',
7
+ RegistroNacional: '12345678',
8
+ endereco: {
9
+ logradouro: 'Rua Pedro Lessa, 15',
10
+ bairro: 'Centro',
11
+ cidade: 'Rio de Janeiro',
12
+ estadoUF: 'RJ',
13
+ cep: '20030-030'
14
+ }
15
+ },
16
+ instrucoes: ['Após o vencimento Mora dia R$ 1,59', 'Após o vencimento, multa de 2%'],
17
+ beneficiario: {
18
+ nome: 'Empresa Fictícia LTDA',
19
+ cnpj: '43576788000191',
20
+ dadosBancarios: {
21
+ carteira: '09',
22
+ agencia: '0101',
23
+ agenciaDigito: '5',
24
+ conta: '0326446',
25
+ contaDigito: '0',
26
+ nossoNumero: '00000000061',
27
+ nossoNumeroDigito: '8'
28
+ },
29
+ endereco: {
30
+ logradouro: 'Rua Pedro Lessa, 15',
31
+ bairro: 'Centro',
32
+ cidade: 'Rio de Janeiro',
33
+ estadoUF: 'RJ',
34
+ cep: '20030-030'
35
+ }
36
+ },
37
+ boleto: {
38
+ numeroDocumento: '1001',
39
+ especieDocumento: 'DM',
40
+ valor: 110.00,
41
+ datas: {
42
+ vencimento: '02-04-2020',
43
+ processamento: '02-04-2019',
44
+ documentos: '02-04-2019'
45
+ }
46
+ }
47
+ };
48
+
49
+ const novoBoleto = new Boletos(boleto);
50
+ novoBoleto.gerarBoleto();
51
+
52
+ novoBoleto.pdfFile().then(async ({stream}) => {
53
+ // ctx.res.set('Content-type', 'application/pdf');
54
+ await streamToPromise(stream);
55
+ }).catch((error) => {
56
+ return error;
57
+ });
58
+
@@ -0,0 +1,59 @@
1
+ const {Bancos, Boletos, streamToPromise} = require('../lib/index');
2
+
3
+ const boleto = {
4
+ banco: new Bancos.Cecred(),
5
+ pagador: {
6
+ nome: 'José Bonifácio de Andrada',
7
+ RegistroNacional: '12345678',
8
+ endereco: {
9
+ logradouro: 'Rua Pedro Lessa, 15',
10
+ bairro: 'Centro',
11
+ cidade: 'Rio de Janeiro',
12
+ estadoUF: 'RJ',
13
+ cep: '20030-030'
14
+ }
15
+ },
16
+ instrucoes: ['Após o vencimento Mora dia R$ 1,59', 'Após o vencimento, multa de 2%'],
17
+ beneficiario: {
18
+ nome: 'Empresa Fictícia LTDA',
19
+ cnpj: '43576788000191',
20
+ dadosBancarios: {
21
+ carteira: '09',
22
+ convenio: '123456',
23
+ agencia: '0101',
24
+ agenciaDigito: '5',
25
+ conta: '03264467',
26
+ contaDigito: '0',
27
+ nossoNumero: '00115290000000004',
28
+ nossoNumeroDigito: '8'
29
+ },
30
+ endereco: {
31
+ logradouro: 'Rua Pedro Lessa, 15',
32
+ bairro: 'Centro',
33
+ cidade: 'Rio de Janeiro',
34
+ estadoUF: 'RJ',
35
+ cep: '20030-030'
36
+ }
37
+ },
38
+ boleto: {
39
+ numeroDocumento: '1001',
40
+ especieDocumento: 'DM',
41
+ valor: 110.00,
42
+ datas: {
43
+ vencimento: '02-04-2020',
44
+ processamento: '02-04-2019',
45
+ documentos: '02-04-2019'
46
+ }
47
+ }
48
+ };
49
+
50
+ const novoBoleto = new Boletos(boleto);
51
+ novoBoleto.gerarBoleto();
52
+
53
+ novoBoleto.pdfFile().then(async ({stream}) => {
54
+ // ctx.res.set('Content-type', 'application/pdf');
55
+ await streamToPromise(stream);
56
+ }).catch((error) => {
57
+ return error;
58
+ });
59
+
package/index.d.ts ADDED
@@ -0,0 +1,372 @@
1
+ import {WriteStream} from 'fs';
2
+
3
+ declare module 'boletos.ts' {
4
+ export interface BoletoInfo {
5
+ banco: Bancos;
6
+ pagador: PagadorInterface;
7
+ boleto: BoletoInterface;
8
+ beneficiario: BeneficiarioInterface;
9
+ instrucoes: string[];
10
+ }
11
+
12
+ export interface GerarBoletoResult {
13
+ boleto: Boleto;
14
+ stream: WriteStream;
15
+ }
16
+
17
+ export class Boletos {
18
+ constructor(options: BoletoInfo);
19
+
20
+ gerarBoleto(): void;
21
+
22
+ pdfFile(): Promise<GerarBoletoResult>;
23
+
24
+ pdfStream(stream: WriteStream): Promise<GerarBoletoResult>;
25
+ }
26
+
27
+ interface PagadorInterface {
28
+ nome: string;
29
+ RegistroNacional: string;
30
+ endereco: EnderecoInterface;
31
+ }
32
+
33
+ interface Pagador {
34
+ getNome(): string;
35
+
36
+ comNome(nome: string): this;
37
+
38
+ getIdentificacao(): string;
39
+
40
+ getRegistroNacional(): string;
41
+
42
+ getRegistroNacionalFormatado(): string;
43
+
44
+ temRegistroNacional(): boolean;
45
+
46
+ comCNPJ(cnpj: string): this;
47
+
48
+ comCPF(cpf: string): this;
49
+
50
+ comRegistroNacional(registroNacional: string): this;
51
+
52
+ getDocumento(): string;
53
+
54
+ comDocumento(documento: string): this;
55
+
56
+ getEndereco(): Endereco;
57
+
58
+ comEndereco(endereco: Endereco): this;
59
+ }
60
+
61
+ interface BeneficiarioInterface {
62
+ nome: string;
63
+ cnpj: string;
64
+ dadosBancarios: DadosBancariosInterface;
65
+ endereco: EnderecoInterface;
66
+ }
67
+
68
+ interface DadosBancariosInterface {
69
+ carteira: string;
70
+ agencia: string;
71
+ agenciaDigito: string;
72
+ conta: string;
73
+ contaDigito: string;
74
+ nossoNumero: string;
75
+ nossoNumeroDigito: string;
76
+ }
77
+
78
+ interface Beneficiario {
79
+ getIdentificacao(): string;
80
+
81
+ getRegistroNacional(): string;
82
+
83
+ getRegistroNacionalFormatado(): string;
84
+
85
+ temRegistroNacional(): boolean;
86
+
87
+ comCNPJ(cnpj: string): this;
88
+
89
+ comCPF(cpf: string): this;
90
+
91
+ comRegistroNacional(registroNacional: string): this;
92
+
93
+ comAgencia(agencia: string): this;
94
+
95
+ getAgencia(): string;
96
+
97
+ comCodPosto(posto: string): this;
98
+
99
+ getCodposto(): string;
100
+
101
+ getAgenciaFormatada(): string;
102
+
103
+ comDigitoAgencia(digitoAgencia: string): this;
104
+
105
+ getDigitoAgencia(): string;
106
+
107
+ comCodigoBeneficiario(codigo: string): this;
108
+
109
+ getCodigoBeneficiario(): string;
110
+
111
+ getDigitoCodigoBeneficiario(): string;
112
+
113
+ comDigitoCodigoBeneficiario(digitoCodigoBeneficiario: string): this;
114
+
115
+ getCarteira(): string;
116
+
117
+ comCarteira(carteira: string): this;
118
+
119
+ getNossoNumero(): string;
120
+
121
+ comNossoNumero(nossoNumero: string): this;
122
+
123
+ getDigitoNossoNumero(): string;
124
+
125
+ comDigitoNossoNumero(digitoNossoNumero: string): this;
126
+
127
+ getNome(): string;
128
+
129
+ comNome(nomeBeneficiario: string): this;
130
+
131
+ getEndereco(): Endereco;
132
+
133
+ comEndereco(endereco: Endereco): this;
134
+
135
+ getNumeroConvenio(): string;
136
+
137
+ comNumeroConvenio(numeroConvenio: string): this;
138
+
139
+ getDocumento(): string;
140
+
141
+ comDocumento(documento: string): this;
142
+ }
143
+
144
+ interface DatasInterface {
145
+ vencimento: string;
146
+ processamento: string;
147
+ documentos: string;
148
+ }
149
+
150
+ interface Datas {
151
+ comDocumento(documento: Date | string, locate?: 'usa' | 'brl'): this;
152
+
153
+ getDocumento(): Date;
154
+
155
+ getDocumentoFormatado(): string;
156
+
157
+ comProcessamento(
158
+ processamento: Date | string,
159
+ locate?: 'usa' | 'brl'
160
+ ): this;
161
+
162
+ getProcessamento(): Date;
163
+
164
+ getProcessamentoFormatado(): string;
165
+
166
+ comVencimento(vencimento: Date | string, locate?: 'usa' | 'brl'): this;
167
+
168
+ getVencimento(): Date;
169
+
170
+ getVencimentoFormatado(): string;
171
+ }
172
+
173
+ interface EnderecoInterface {
174
+ logradouro: string;
175
+ bairro: string;
176
+ cidade: string;
177
+ estadoUF: string;
178
+ cep: string;
179
+ }
180
+
181
+ interface Endereco {
182
+ getLogradouro(): string;
183
+
184
+ comLogradouro(logradouro: string): this;
185
+
186
+ getBairro(): string;
187
+
188
+ comBairro(bairro: string): this;
189
+
190
+ getCep(): string;
191
+
192
+ getCepFormatado(): string;
193
+
194
+ comCep(cep: string): this;
195
+
196
+ getCidade(): string;
197
+
198
+ comCidade(cidade: string): this;
199
+
200
+ getUf(): string;
201
+
202
+ comUf(uf: string): this;
203
+
204
+ getPrimeiraLinha(): string;
205
+
206
+ getSegundaLinha(): string;
207
+
208
+ getEnderecoCompleto(): string;
209
+ }
210
+
211
+ interface BoletoInterface {
212
+ numeroDocumento: string;
213
+ especieDocumento: string;
214
+ valor: number;
215
+ datas: DatasInterface;
216
+ emv?: string
217
+ imagemQrCode?: string;
218
+ }
219
+
220
+ interface Boleto {
221
+ getFatorVencimento(): string;
222
+
223
+ comEspecieMoeda(especieMoeda: string): this;
224
+
225
+ getEspecieMoeda(): string;
226
+
227
+ getCodigoEspecieMoeda(): string;
228
+
229
+ comCodigoEspecieMoeda(codigoEspecieMoeda: string | number): this;
230
+
231
+ getAceite(): boolean;
232
+
233
+ getAceiteFormatado(): string;
234
+
235
+ comAceite(aceite: boolean): this;
236
+
237
+ getEspecieDocumento(): string;
238
+
239
+ comEspecieDocumento(especieDocumento: string): this;
240
+
241
+ getDatas(): Datas;
242
+
243
+ comDatas(datas: Datas): this;
244
+
245
+ getValorFormatado(): string;
246
+
247
+ getValorFormatadoBRL(): string;
248
+
249
+ getValorBoleto(): number;
250
+
251
+ comValorBoleto(valorBoleto: number): this;
252
+
253
+ comValor(valorBoleto: number): void;
254
+
255
+ getNumeroDoDocumentoFormatado(): string;
256
+
257
+ getNumeroDoDocumento(): string;
258
+
259
+ comNumeroDoDocumento(numeroDoDocumento: string): this;
260
+
261
+ getInstrucoes(): string[];
262
+
263
+ comInstrucoes(...instrucoes: string[]): this;
264
+
265
+ getDescricoes(): string[];
266
+
267
+ comDescricoes(...descricoes: string[]): this;
268
+
269
+ getLocaisDePagamento(): string[];
270
+
271
+ comLocaisDePagamento(...locaisDePagamento: string[]): this;
272
+
273
+ getQuantidadeDeMoeda(): string;
274
+
275
+ comQuantidadeDeMoeda(quantidadeDeMoeda: string): this;
276
+
277
+ getBanco(): Bancos;
278
+
279
+ comBanco(banco: Bancos): this;
280
+
281
+ getPagador(): Pagador;
282
+
283
+ comPagador(pagador: Pagador): this;
284
+
285
+ getBeneficiario(): Beneficiario;
286
+
287
+ comBeneficiario(beneficiario: Beneficiario): this;
288
+
289
+ getValorDescontosFormatadoBRL(): string;
290
+
291
+ getValorDescontos(): number;
292
+
293
+ comValorDescontos(valorDescontos: number): this;
294
+
295
+ getValorDeducoesFormatadoBRL(): string;
296
+
297
+ getValorDeducoes(): number;
298
+
299
+ comValorDeducoes(valorDeducoes: number): this;
300
+
301
+ getValorMultaFormatadoBRL(): string;
302
+
303
+ getValorMulta(): number;
304
+
305
+ comValorMulta(valorMulta: number): this;
306
+
307
+ getValorAcrescimosFormatadoBRL(): string;
308
+
309
+ getValorAcrescimos(): number;
310
+
311
+ comValorAcrescimos(valorAcrescimos: number): this;
312
+
313
+ getLinhaDigitavelFormatado(): { linha: string; numeroDocumento: string };
314
+ }
315
+
316
+ export {Pagador, Beneficiario, Datas, Endereco, Boleto};
317
+
318
+ class Itau {
319
+ }
320
+
321
+ class Caixa {
322
+ }
323
+
324
+ class Bradesco {
325
+ }
326
+
327
+ class BancoBrasil {
328
+ }
329
+
330
+ class Cecred {
331
+ }
332
+
333
+ class Sicoob {
334
+ }
335
+
336
+ class Santander {
337
+ }
338
+
339
+ class Sicredi {
340
+ }
341
+
342
+ class Bancos {
343
+ static Itau: typeof Itau;
344
+ static '341': typeof Itau;
345
+ static Caixa: typeof Caixa;
346
+ static '104': typeof Caixa;
347
+ static Bradesco: typeof Bradesco;
348
+ static '237': typeof Bradesco;
349
+ static BancoBrasil: typeof BancoBrasil;
350
+ static '001': typeof BancoBrasil;
351
+ static Cecred: typeof Cecred;
352
+ static '085': typeof Cecred;
353
+ static Sicoob: typeof Sicoob;
354
+ static '756': typeof Sicoob;
355
+ static Santander: typeof Santander;
356
+ static '033': typeof Santander;
357
+ static Sicredi: typeof Sicredi;
358
+ static '748': typeof Sicredi;
359
+ }
360
+
361
+ export {
362
+ Bancos,
363
+ Itau,
364
+ Caixa,
365
+ Bradesco,
366
+ BancoBrasil,
367
+ Cecred,
368
+ Sicoob,
369
+ Santander,
370
+ Sicredi,
371
+ };
372
+ }