@br-validators/core 0.10.0-alpha.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.
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/boleto.d.ts +113 -0
- package/dist/boleto.js +4 -0
- package/dist/boleto.js.map +1 -0
- package/dist/cartao-credito.d.ts +47 -0
- package/dist/cartao-credito.js +4 -0
- package/dist/cartao-credito.js.map +1 -0
- package/dist/cep.d.ts +20 -0
- package/dist/cep.js +7 -0
- package/dist/cep.js.map +1 -0
- package/dist/chunk-54DTXC6V.js +207 -0
- package/dist/chunk-54DTXC6V.js.map +1 -0
- package/dist/chunk-7FOWIH6F.js +20 -0
- package/dist/chunk-7FOWIH6F.js.map +1 -0
- package/dist/chunk-AKJHIJ5E.js +387 -0
- package/dist/chunk-AKJHIJ5E.js.map +1 -0
- package/dist/chunk-B2TDI3YS.js +23 -0
- package/dist/chunk-B2TDI3YS.js.map +1 -0
- package/dist/chunk-DKRM66US.js +35 -0
- package/dist/chunk-DKRM66US.js.map +1 -0
- package/dist/chunk-EB3G4IG6.js +8 -0
- package/dist/chunk-EB3G4IG6.js.map +1 -0
- package/dist/chunk-M66MGLHE.js +156 -0
- package/dist/chunk-M66MGLHE.js.map +1 -0
- package/dist/chunk-OWJ5HN4T.js +91 -0
- package/dist/chunk-OWJ5HN4T.js.map +1 -0
- package/dist/chunk-PBNVKDCF.js +82 -0
- package/dist/chunk-PBNVKDCF.js.map +1 -0
- package/dist/chunk-RMKTJQBB.js +61 -0
- package/dist/chunk-RMKTJQBB.js.map +1 -0
- package/dist/chunk-RZ2JG5PP.js +14 -0
- package/dist/chunk-RZ2JG5PP.js.map +1 -0
- package/dist/chunk-SE33CFGM.js +276 -0
- package/dist/chunk-SE33CFGM.js.map +1 -0
- package/dist/chunk-UCJPSJN5.js +8 -0
- package/dist/chunk-UCJPSJN5.js.map +1 -0
- package/dist/chunk-W6UXVWSR.js +13 -0
- package/dist/chunk-W6UXVWSR.js.map +1 -0
- package/dist/chunk-YY4M2YS6.js +115 -0
- package/dist/chunk-YY4M2YS6.js.map +1 -0
- package/dist/chunk-Z4F75QEC.js +1180 -0
- package/dist/chunk-Z4F75QEC.js.map +1 -0
- package/dist/cnpj.d.ts +37 -0
- package/dist/cnpj.js +7 -0
- package/dist/cnpj.js.map +1 -0
- package/dist/cpf.d.ts +20 -0
- package/dist/cpf.js +7 -0
- package/dist/cpf.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/inscricao-estadual.d.ts +57 -0
- package/dist/inscricao-estadual.js +4 -0
- package/dist/inscricao-estadual.js.map +1 -0
- package/dist/pis-pasep.d.ts +20 -0
- package/dist/pis-pasep.js +5 -0
- package/dist/pis-pasep.js.map +1 -0
- package/dist/pix-DP6jnwpN.d.ts +44 -0
- package/dist/pix.d.ts +11 -0
- package/dist/pix.js +9 -0
- package/dist/pix.js.map +1 -0
- package/dist/placa.d.ts +35 -0
- package/dist/placa.js +7 -0
- package/dist/placa.js.map +1 -0
- package/dist/validation-result-BK4qJuei.d.ts +101 -0
- package/package.json +91 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BR Validators contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @br-validators/core
|
|
2
|
+
|
|
3
|
+
100% open-source Brazilian document validators (MIT).
|
|
4
|
+
|
|
5
|
+
**npm:** [`@br-validators/core`](https://www.npmjs.com/package/@br-validators/core)
|
|
6
|
+
**Repo:** [github.com/AlexandreZanata/doc-raiz](https://github.com/AlexandreZanata/doc-raiz)
|
|
7
|
+
|
|
8
|
+
> The unscoped name `br-validators` on npm is a different package. Use **`@br-validators/core`**.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @br-validators/core
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Requires Node ≥ 18. ESM only (`"type": "module"`).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Supported types
|
|
23
|
+
|
|
24
|
+
| Module | Functions | Golden vector |
|
|
25
|
+
|--------|-----------|---------------|
|
|
26
|
+
| CNPJ | `validateCnpj`, `formatCnpj`, `stripCnpj` | `12ABC34501DE35` |
|
|
27
|
+
| CPF | `validateCpf`, `formatCpf`, `stripCpf` | `12345678909` |
|
|
28
|
+
| CEP | `validateCep`, `formatCep`, `stripCep` | `01310100` |
|
|
29
|
+
| Placa | `validatePlaca`, `formatPlaca`, `convertPlacaToMercosul` | `ABC1D23` |
|
|
30
|
+
| PIS/PASEP | `validatePisPasep`, `formatPisPasep` | `10027230888` |
|
|
31
|
+
| PIX key | `validatePixKey`, `formatPixKey` | `pix@bcb.gov.br` |
|
|
32
|
+
| Boleto | `validateBoleto`, `formatBoleto` | Situação 1 + 2 |
|
|
33
|
+
| Credit card | `validateCartaoCredito`, `passesLuhn` | `4111111111111111` |
|
|
34
|
+
| IE (27 UFs) | `validateInscricaoEstadual`, `validateIeSp`, … | per UF — see docs |
|
|
35
|
+
|
|
36
|
+
Subpath imports for tree-shaking:
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { validateCnpj } from '@br-validators/core/cnpj';
|
|
40
|
+
import { validateInscricaoEstadual } from '@br-validators/core/inscricao-estadual';
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Examples
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { validateCnpj, formatCnpj } from '@br-validators/core';
|
|
49
|
+
|
|
50
|
+
const result = validateCnpj('12ABC34501DE35');
|
|
51
|
+
// { ok: true, value: '12ABC34501DE35', format: 'alphanumeric', ... }
|
|
52
|
+
|
|
53
|
+
formatCnpj('12ABC34501DE35');
|
|
54
|
+
// { ok: true, formatted: '12.ABC.345/01DE-35', ... }
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { validateInscricaoEstadual } from '@br-validators/core/inscricao-estadual';
|
|
59
|
+
|
|
60
|
+
validateInscricaoEstadual('110042490114', { uf: 'SP' });
|
|
61
|
+
validateInscricaoEstadual('0730000100109', { uf: 'DF' });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Official sources
|
|
67
|
+
|
|
68
|
+
Every algorithm cites a primary government source. Full table: [OFFICIAL-SOURCES.md](https://github.com/AlexandreZanata/doc-raiz/blob/main/docs/OFFICIAL-SOURCES.md)
|
|
69
|
+
|
|
70
|
+
Per-type URLs also available via constants (`CNPJ_OFFICIAL_SOURCE_URL`, `IE_OFFICIAL_SOURCE_URLS`, etc.).
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## API reference
|
|
75
|
+
|
|
76
|
+
[docs/LIBRARY-API.md](https://github.com/AlexandreZanata/doc-raiz/blob/main/docs/LIBRARY-API.md)
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## CLI companion
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
npm install -g @br-validators/cli
|
|
84
|
+
br-validators cnpj validate 12ABC34501DE35 --json
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
package/dist/boleto.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { b as BoletoValidationResult, V as ValidationErrorCode, B as BoletoInputKind, F as FormatResult } from './validation-result-BK4qJuei.js';
|
|
2
|
+
export { a as BoletoSituacao, f as CodigoBarras, D as DocumentFormat, L as LinhaDigitavel } from './validation-result-BK4qJuei.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* FEBRABAN bank boleto (cobrança) — linha digitável + código de barras.
|
|
6
|
+
* @see Convenção da Cobrança FB-0061/2021 — Anexos V, VI, IX, X
|
|
7
|
+
* @see https://cmsarquivos.febraban.org.br/Arquivos/documentos/PDF/Conven%C3%A7%C3%A3o%20da%20Cobran%C3%A7a%20-%2005_02_2021_f.pdf
|
|
8
|
+
*/
|
|
9
|
+
declare const BOLETO_LINHA_LENGTH = 47;
|
|
10
|
+
declare const BOLETO_CODIGO_BARRAS_LENGTH = 44;
|
|
11
|
+
declare const BOLETO_CURRENCY_REAL = "9";
|
|
12
|
+
declare const BOLETO_CODE_ISPB_HOLDER = "988";
|
|
13
|
+
declare const BOLETO_CURRENCY_ISPB = "0";
|
|
14
|
+
declare const BOLETO_GOLDEN_LINHA_MASKED = "03399.02579 08991.834006 71742.301014 6 14500000099668";
|
|
15
|
+
declare const BOLETO_GOLDEN_LINHA_STRIPPED = "03399025790899183400671742301014614500000099668";
|
|
16
|
+
declare const BOLETO_GOLDEN_CODIGO_BARRAS = "03396145000000996689025708991834007174230101";
|
|
17
|
+
declare const BOLETO_GOLDEN_LINHA_BB_STRIPPED = "00191234546789012345767890123457112340000001500";
|
|
18
|
+
declare const BOLETO_GOLDEN_CODIGO_BARRAS_BB = "00191123400000015001234567890123456789012345";
|
|
19
|
+
declare const BOLETO_GOLDEN_LINHA_SITUACAO2_STRIPPED = "98801234516789012345767890123457760746948000112";
|
|
20
|
+
declare const BOLETO_GOLDEN_CODIGO_BARRAS_SITUACAO2 = "98807607469480001121234567890123456789012345";
|
|
21
|
+
declare const BOLETO_OFFICIAL_SOURCE_URL = "https://cmsarquivos.febraban.org.br/Arquivos/documentos/PDF/Conven%C3%A7%C3%A3o%20da%20Cobran%C3%A7a%20-%2005_02_2021_f.pdf";
|
|
22
|
+
declare const BOLETO_LAYOUTS_PORTAL_URL = "https://portal.febraban.org.br/pagina/3425/33/pt-br/layout-febraban";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Modulo 10 — linha digitável field DVs (Anexo IX).
|
|
26
|
+
*/
|
|
27
|
+
declare function computeModulo10FieldDv(digits: string): number;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Modulo 11 — código de barras general DV (Anexo X).
|
|
31
|
+
*/
|
|
32
|
+
declare function computeModulo11BarcodeDv(barcodeWithoutDv: string): number;
|
|
33
|
+
|
|
34
|
+
type DetectedBoletoInputKind = 'linha-digitavel' | 'codigo-barras' | 'arrecadacao' | 'unknown';
|
|
35
|
+
declare function detectBoletoInputKind(input: string): DetectedBoletoInputKind;
|
|
36
|
+
|
|
37
|
+
type BoletoSituacaoKind = 'situacao-1' | 'situacao-2' | 'unknown';
|
|
38
|
+
type BoletoSituacaoCode = '1' | '2';
|
|
39
|
+
declare function detectBoletoSituacao(stripped: string): BoletoSituacaoKind;
|
|
40
|
+
|
|
41
|
+
declare function convertLinhaToCodigoBarrasDigits(strippedLinha: string): string;
|
|
42
|
+
declare function convertCodigoBarrasToLinhaDigits(barcode: string): string;
|
|
43
|
+
|
|
44
|
+
/** FEBRABAN typable linha digitável mask (47 digits). */
|
|
45
|
+
declare function applyLinhaDigitavelMask(stripped47: string): string;
|
|
46
|
+
/** Backward-compatible alias for applyLinhaDigitavelMask. */
|
|
47
|
+
declare function formatLinhaDigitavel(stripped: string): string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Linha digitável validation — modulo 10 field DVs (Anexo IX).
|
|
51
|
+
* @see BR-BOLETO-002, BR-BOLETO-008
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
declare function stripLinhaDigitavel(input: string): string;
|
|
55
|
+
declare function validateLinhaDigitavel(input: string): BoletoValidationResult;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Código de barras validation — modulo 11 general DV (Anexo X).
|
|
59
|
+
* @see BR-BOLETO-003, BR-BOLETO-004, BR-BOLETO-010
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
declare function stripCodigoBarras(input: string): string;
|
|
63
|
+
declare function validateCodigoBarras(input: string): BoletoValidationResult;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Due-date factor semantic validation (Situação 1 only).
|
|
67
|
+
* @see BR-BOLETO-012
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
type FatorVencimentoValidationResult = {
|
|
71
|
+
ok: true;
|
|
72
|
+
factor: string;
|
|
73
|
+
hasDueDate: boolean;
|
|
74
|
+
} | {
|
|
75
|
+
ok: false;
|
|
76
|
+
code: ValidationErrorCode;
|
|
77
|
+
message: string;
|
|
78
|
+
};
|
|
79
|
+
declare function validateFatorVencimento(factor: string): FatorVencimentoValidationResult;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Document amount semantic validation (Situação 1 only).
|
|
83
|
+
* @see BR-BOLETO-013
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
type ValorDocumentoValidationResult = {
|
|
87
|
+
ok: true;
|
|
88
|
+
amountCents: number;
|
|
89
|
+
} | {
|
|
90
|
+
ok: false;
|
|
91
|
+
code: ValidationErrorCode;
|
|
92
|
+
message: string;
|
|
93
|
+
};
|
|
94
|
+
declare function validateValorDocumento(value: string): ValorDocumentoValidationResult;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Boleto validation — linha digitável + código de barras (FEBRABAN cobrança).
|
|
98
|
+
* @see docs/use-cases/UC-007-validate-boleto.md
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
type ValidateBoletoOptions = {
|
|
102
|
+
kind?: BoletoInputKind;
|
|
103
|
+
validateDueFactor?: boolean;
|
|
104
|
+
validateAmount?: boolean;
|
|
105
|
+
};
|
|
106
|
+
declare function isValidBoleto(input: string, options?: ValidateBoletoOptions): boolean;
|
|
107
|
+
declare function validateBoleto(input: string, options?: ValidateBoletoOptions): BoletoValidationResult;
|
|
108
|
+
declare function convertLinhaToCodigoBarras(input: string): BoletoValidationResult;
|
|
109
|
+
declare function convertCodigoBarrasToLinhaDigitavel(input: string): BoletoValidationResult;
|
|
110
|
+
|
|
111
|
+
declare function formatBoleto(input: string): FormatResult;
|
|
112
|
+
|
|
113
|
+
export { BOLETO_CODE_ISPB_HOLDER, BOLETO_CODIGO_BARRAS_LENGTH, BOLETO_CURRENCY_ISPB, BOLETO_CURRENCY_REAL, BOLETO_GOLDEN_CODIGO_BARRAS, BOLETO_GOLDEN_CODIGO_BARRAS_BB, BOLETO_GOLDEN_CODIGO_BARRAS_SITUACAO2, BOLETO_GOLDEN_LINHA_BB_STRIPPED, BOLETO_GOLDEN_LINHA_MASKED, BOLETO_GOLDEN_LINHA_SITUACAO2_STRIPPED, BOLETO_GOLDEN_LINHA_STRIPPED, BOLETO_LAYOUTS_PORTAL_URL, BOLETO_LINHA_LENGTH, BOLETO_OFFICIAL_SOURCE_URL, BoletoInputKind, type BoletoSituacaoCode, type BoletoSituacaoKind, BoletoValidationResult, type DetectedBoletoInputKind, type FatorVencimentoValidationResult, type ValidateBoletoOptions, ValidationErrorCode, type ValorDocumentoValidationResult, applyLinhaDigitavelMask, computeModulo10FieldDv, computeModulo11BarcodeDv, convertCodigoBarrasToLinhaDigitavel, convertCodigoBarrasToLinhaDigits, convertLinhaToCodigoBarras, convertLinhaToCodigoBarrasDigits, detectBoletoInputKind, detectBoletoSituacao, formatBoleto, formatLinhaDigitavel, isValidBoleto, stripCodigoBarras, stripLinhaDigitavel, validateBoleto, validateCodigoBarras, validateFatorVencimento, validateLinhaDigitavel, validateValorDocumento };
|
package/dist/boleto.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BOLETO_CODE_ISPB_HOLDER, BOLETO_CODIGO_BARRAS_LENGTH, BOLETO_CURRENCY_ISPB, BOLETO_CURRENCY_REAL, BOLETO_GOLDEN_CODIGO_BARRAS, BOLETO_GOLDEN_CODIGO_BARRAS_BB, BOLETO_GOLDEN_CODIGO_BARRAS_SITUACAO2, BOLETO_GOLDEN_LINHA_BB_STRIPPED, BOLETO_GOLDEN_LINHA_MASKED, BOLETO_GOLDEN_LINHA_SITUACAO2_STRIPPED, BOLETO_GOLDEN_LINHA_STRIPPED, BOLETO_LAYOUTS_PORTAL_URL, BOLETO_LINHA_LENGTH, BOLETO_OFFICIAL_SOURCE_URL, applyLinhaDigitavelMask, computeModulo10FieldDv, computeModulo11BarcodeDv, convertCodigoBarrasToLinhaDigitavel, convertCodigoBarrasToLinhaDigits, convertLinhaToCodigoBarras, convertLinhaToCodigoBarrasDigits, detectBoletoInputKind, detectBoletoSituacao, formatBoleto, formatLinhaDigitavel, isValidBoleto, stripCodigoBarras, stripLinhaDigitavel, validateBoleto, validateCodigoBarras, validateFatorVencimento, validateLinhaDigitavel, validateValorDocumento } from './chunk-AKJHIJ5E.js';
|
|
2
|
+
import './chunk-DKRM66US.js';
|
|
3
|
+
//# sourceMappingURL=boleto.js.map
|
|
4
|
+
//# sourceMappingURL=boleto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"boleto.js"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { c as CartaoCreditoValidationResult, F as FormatResult } from './validation-result-BK4qJuei.js';
|
|
2
|
+
export { C as CartaoCredito, D as DocumentFormat, V as ValidationErrorCode } from './validation-result-BK4qJuei.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Credit card PAN constants — ISO/IEC 7812-1 Annex B (Luhn).
|
|
6
|
+
* @see https://www.iso.org/standard/70484.html
|
|
7
|
+
* @see docs/use-cases/UC-008-validate-cartao-credito.md
|
|
8
|
+
*/
|
|
9
|
+
type CardBrand = 'visa' | 'mastercard' | 'amex' | 'elo' | 'hipercard' | 'unknown';
|
|
10
|
+
declare const CARTAO_PAN_MIN_LENGTH = 8;
|
|
11
|
+
declare const CARTAO_PAN_MAX_LENGTH = 19;
|
|
12
|
+
declare const CARTAO_GOLDEN_VISA = "4111111111111111";
|
|
13
|
+
declare const CARTAO_GOLDEN_MASTERCARD = "5555555555554444";
|
|
14
|
+
declare const CARTAO_GOLDEN_AMEX = "378282246310005";
|
|
15
|
+
declare const CARTAO_GOLDEN_LUHN_WALKTHROUGH = "79927398713";
|
|
16
|
+
declare const CARTAO_GOLDEN_VISA_MASKED = "4111 1111 1111 1111";
|
|
17
|
+
declare const CARTAO_GOLDEN_MIN_LENGTH = "12345674";
|
|
18
|
+
declare const CARTAO_OFFICIAL_SOURCE_URL = "https://www.iso.org/standard/70484.html";
|
|
19
|
+
declare const CARTAO_IEC_SOURCE_URL = "https://webstore.iec.ch/en/publication/59763";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Best-effort card brand from IIN prefix — non-authoritative (BR-LUHN-005).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
declare function detectCardBrand(strippedPan: string): CardBrand;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Luhn checksum — ISO/IEC 7812-1 Annex B (modulus-10 double-add-double).
|
|
29
|
+
* @see BR-LUHN-003
|
|
30
|
+
*/
|
|
31
|
+
declare function computeLuhnSum(pan: string): number;
|
|
32
|
+
/** ISO/IEC 7812-1 Annex B — returns true when PAN passes Luhn. */
|
|
33
|
+
declare function passesLuhn(pan: string): boolean;
|
|
34
|
+
|
|
35
|
+
declare function isValidLuhn(input: string): boolean;
|
|
36
|
+
declare function isValidCartaoCredito(input: string): boolean;
|
|
37
|
+
declare function validateCartaoCredito(input: string): CartaoCreditoValidationResult;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Strip credit card PAN mask — digits only (BR-LUHN-001).
|
|
41
|
+
* @see https://www.iso.org/standard/70484.html
|
|
42
|
+
*/
|
|
43
|
+
declare function stripCartaoCredito(input: string): string;
|
|
44
|
+
|
|
45
|
+
declare function formatCartaoCredito(input: string): FormatResult;
|
|
46
|
+
|
|
47
|
+
export { CARTAO_GOLDEN_AMEX, CARTAO_GOLDEN_LUHN_WALKTHROUGH, CARTAO_GOLDEN_MASTERCARD, CARTAO_GOLDEN_MIN_LENGTH, CARTAO_GOLDEN_VISA, CARTAO_GOLDEN_VISA_MASKED, CARTAO_IEC_SOURCE_URL, CARTAO_OFFICIAL_SOURCE_URL, CARTAO_PAN_MAX_LENGTH, CARTAO_PAN_MIN_LENGTH, type CardBrand, CartaoCreditoValidationResult, FormatResult, computeLuhnSum, detectCardBrand, formatCartaoCredito, isValidCartaoCredito, isValidLuhn, passesLuhn, stripCartaoCredito, validateCartaoCredito };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CARTAO_GOLDEN_AMEX, CARTAO_GOLDEN_LUHN_WALKTHROUGH, CARTAO_GOLDEN_MASTERCARD, CARTAO_GOLDEN_MIN_LENGTH, CARTAO_GOLDEN_VISA, CARTAO_GOLDEN_VISA_MASKED, CARTAO_IEC_SOURCE_URL, CARTAO_OFFICIAL_SOURCE_URL, CARTAO_PAN_MAX_LENGTH, CARTAO_PAN_MIN_LENGTH, computeLuhnSum, detectCardBrand, formatCartaoCredito, isValidCartaoCredito, isValidLuhn, passesLuhn, stripCartaoCredito, validateCartaoCredito } from './chunk-54DTXC6V.js';
|
|
2
|
+
import './chunk-DKRM66US.js';
|
|
3
|
+
//# sourceMappingURL=cartao-credito.js.map
|
|
4
|
+
//# sourceMappingURL=cartao-credito.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"cartao-credito.js"}
|
package/dist/cep.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { m as ValidationResult, F as FormatResult } from './validation-result-BK4qJuei.js';
|
|
2
|
+
export { d as Cep, D as DocumentFormat, V as ValidationErrorCode } from './validation-result-BK4qJuei.js';
|
|
3
|
+
|
|
4
|
+
declare const CEP_GOLDEN_PRIMARY = "01310100";
|
|
5
|
+
declare const CEP_GOLDEN_SECONDARY = "20040020";
|
|
6
|
+
declare const CEP_GOLDEN_PRIMARY_MASKED = "01310-100";
|
|
7
|
+
declare const CEP_OFFICIAL_SOURCE_URL = "https://www.correios.com.br/atendimento/developers/manuais/manual-api-busca-cep";
|
|
8
|
+
|
|
9
|
+
declare function isValidCep(input: string): boolean;
|
|
10
|
+
declare function validateCep(input: string): ValidationResult;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Strip CEP mask — digits only (BR-CEP-001).
|
|
14
|
+
* @see https://www.correios.com.br/atendimento/developers/manuais/manual-api-busca-cep
|
|
15
|
+
*/
|
|
16
|
+
declare function stripCep(input: string): string;
|
|
17
|
+
|
|
18
|
+
declare function formatCep(input: string): FormatResult;
|
|
19
|
+
|
|
20
|
+
export { CEP_GOLDEN_PRIMARY, CEP_GOLDEN_PRIMARY_MASKED, CEP_GOLDEN_SECONDARY, CEP_OFFICIAL_SOURCE_URL, FormatResult, ValidationResult, formatCep, isValidCep, stripCep, validateCep };
|
package/dist/cep.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CEP_GOLDEN_PRIMARY, CEP_GOLDEN_PRIMARY_MASKED, CEP_GOLDEN_SECONDARY, CEP_OFFICIAL_SOURCE_URL, formatCep, isValidCep, validateCep } from './chunk-RMKTJQBB.js';
|
|
2
|
+
export { stripCep } from './chunk-W6UXVWSR.js';
|
|
3
|
+
import './chunk-EB3G4IG6.js';
|
|
4
|
+
import './chunk-UCJPSJN5.js';
|
|
5
|
+
import './chunk-DKRM66US.js';
|
|
6
|
+
//# sourceMappingURL=cep.js.map
|
|
7
|
+
//# sourceMappingURL=cep.js.map
|
package/dist/cep.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"cep.js"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { brandCartaoCredito } from './chunk-DKRM66US.js';
|
|
2
|
+
|
|
3
|
+
// src/strip/cartao-credito.ts
|
|
4
|
+
function stripCartaoCredito(input) {
|
|
5
|
+
return input.replace(/\D/g, "");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/core/cartao-credito/constants.ts
|
|
9
|
+
var CARTAO_PAN_MIN_LENGTH = 8;
|
|
10
|
+
var CARTAO_PAN_MAX_LENGTH = 19;
|
|
11
|
+
var CARTAO_GOLDEN_VISA = "4111111111111111";
|
|
12
|
+
var CARTAO_GOLDEN_MASTERCARD = "5555555555554444";
|
|
13
|
+
var CARTAO_GOLDEN_AMEX = "378282246310005";
|
|
14
|
+
var CARTAO_GOLDEN_LUHN_WALKTHROUGH = "79927398713";
|
|
15
|
+
var CARTAO_GOLDEN_VISA_MASKED = "4111 1111 1111 1111";
|
|
16
|
+
var CARTAO_GOLDEN_MIN_LENGTH = "12345674";
|
|
17
|
+
var CARTAO_OFFICIAL_SOURCE_URL = "https://www.iso.org/standard/70484.html";
|
|
18
|
+
var CARTAO_IEC_SOURCE_URL = "https://webstore.iec.ch/en/publication/59763";
|
|
19
|
+
var ELO_IIN_PREFIXES = [
|
|
20
|
+
"401178",
|
|
21
|
+
"401179",
|
|
22
|
+
"431274",
|
|
23
|
+
"438935",
|
|
24
|
+
"451416",
|
|
25
|
+
"457393",
|
|
26
|
+
"457631",
|
|
27
|
+
"457632",
|
|
28
|
+
"504175",
|
|
29
|
+
"506699",
|
|
30
|
+
"506770",
|
|
31
|
+
"509048",
|
|
32
|
+
"509049",
|
|
33
|
+
"627780",
|
|
34
|
+
"636297",
|
|
35
|
+
"636368",
|
|
36
|
+
"650031",
|
|
37
|
+
"650032",
|
|
38
|
+
"650033",
|
|
39
|
+
"650035",
|
|
40
|
+
"650051",
|
|
41
|
+
"650405",
|
|
42
|
+
"650439",
|
|
43
|
+
"650485",
|
|
44
|
+
"650486",
|
|
45
|
+
"650487",
|
|
46
|
+
"650488",
|
|
47
|
+
"650489",
|
|
48
|
+
"650490",
|
|
49
|
+
"650491",
|
|
50
|
+
"650492",
|
|
51
|
+
"650493",
|
|
52
|
+
"650494",
|
|
53
|
+
"650495",
|
|
54
|
+
"650496",
|
|
55
|
+
"650497",
|
|
56
|
+
"650498",
|
|
57
|
+
"650499",
|
|
58
|
+
"651652",
|
|
59
|
+
"651653",
|
|
60
|
+
"651654",
|
|
61
|
+
"651655",
|
|
62
|
+
"651656",
|
|
63
|
+
"651657",
|
|
64
|
+
"651658",
|
|
65
|
+
"651659",
|
|
66
|
+
"651660",
|
|
67
|
+
"655000",
|
|
68
|
+
"655001"
|
|
69
|
+
];
|
|
70
|
+
var HIPERCARD_IIN_PREFIXES = ["606282", "384100"];
|
|
71
|
+
|
|
72
|
+
// src/core/cartao-credito/detect-brand.ts
|
|
73
|
+
function detectCardBrand(strippedPan) {
|
|
74
|
+
for (const prefix of ELO_IIN_PREFIXES) {
|
|
75
|
+
if (strippedPan.startsWith(prefix)) {
|
|
76
|
+
return "elo";
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const prefix of HIPERCARD_IIN_PREFIXES) {
|
|
80
|
+
if (strippedPan.startsWith(prefix)) {
|
|
81
|
+
return "hipercard";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (/^3[47]/.test(strippedPan)) {
|
|
85
|
+
return "amex";
|
|
86
|
+
}
|
|
87
|
+
if (/^5[1-5]/.test(strippedPan) || /^2[2-7]/.test(strippedPan)) {
|
|
88
|
+
return "mastercard";
|
|
89
|
+
}
|
|
90
|
+
if (strippedPan.startsWith("4")) {
|
|
91
|
+
return "visa";
|
|
92
|
+
}
|
|
93
|
+
return "unknown";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/core/cartao-credito/luhn.ts
|
|
97
|
+
function computeLuhnSum(pan) {
|
|
98
|
+
let sum = 0;
|
|
99
|
+
let double = false;
|
|
100
|
+
for (let i = pan.length - 1; i >= 0; i--) {
|
|
101
|
+
let digit = Number(pan.charAt(i));
|
|
102
|
+
if (double) {
|
|
103
|
+
digit *= 2;
|
|
104
|
+
if (digit > 9) {
|
|
105
|
+
digit -= 9;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
sum += digit;
|
|
109
|
+
double = !double;
|
|
110
|
+
}
|
|
111
|
+
return sum;
|
|
112
|
+
}
|
|
113
|
+
function passesLuhn(pan) {
|
|
114
|
+
return computeLuhnSum(pan) % 10 === 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/core/cartao-credito/mask.ts
|
|
118
|
+
function applyCartaoCreditoMask(canonical) {
|
|
119
|
+
if (canonical.length < CARTAO_PAN_MIN_LENGTH || canonical.length > CARTAO_PAN_MAX_LENGTH) {
|
|
120
|
+
throw new Error(`PAN must have between ${CARTAO_PAN_MIN_LENGTH} and ${CARTAO_PAN_MAX_LENGTH} digits to apply mask`);
|
|
121
|
+
}
|
|
122
|
+
if (canonical.length === 15) {
|
|
123
|
+
return `${canonical.slice(0, 4)} ${canonical.slice(4, 10)} ${canonical.slice(10)}`;
|
|
124
|
+
}
|
|
125
|
+
const groups = [];
|
|
126
|
+
for (let i = 0; i < canonical.length; i += 4) {
|
|
127
|
+
groups.push(canonical.slice(i, i + 4));
|
|
128
|
+
}
|
|
129
|
+
return groups.join(" ");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/core/cartao-credito/index.ts
|
|
133
|
+
function failure(code, message) {
|
|
134
|
+
return { ok: false, code, message };
|
|
135
|
+
}
|
|
136
|
+
function hasRepeatedDigits(value) {
|
|
137
|
+
const first = value[0];
|
|
138
|
+
for (let i = 1; i < value.length; i++) {
|
|
139
|
+
if (value[i] !== first) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
function validateStructure(input, stripped) {
|
|
146
|
+
if (stripped.length === 0) {
|
|
147
|
+
return failure("EMPTY_INPUT", "Credit card PAN input is empty");
|
|
148
|
+
}
|
|
149
|
+
const withoutMask = input.replace(/[\s-]/g, "");
|
|
150
|
+
if (/[^0-9]/.test(withoutMask)) {
|
|
151
|
+
return failure("INVALID_CHARACTER", "Credit card PAN contains invalid characters");
|
|
152
|
+
}
|
|
153
|
+
if (stripped.length < CARTAO_PAN_MIN_LENGTH || stripped.length > CARTAO_PAN_MAX_LENGTH) {
|
|
154
|
+
return failure(
|
|
155
|
+
"INVALID_LENGTH",
|
|
156
|
+
`Credit card PAN must have between ${CARTAO_PAN_MIN_LENGTH} and ${CARTAO_PAN_MAX_LENGTH} digits after normalization`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (hasRepeatedDigits(stripped)) {
|
|
160
|
+
return failure("KNOWN_INVALID_PATTERN", "Credit card PAN with all identical digits is invalid");
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
function isValidLuhn(input) {
|
|
165
|
+
const stripped = stripCartaoCredito(input);
|
|
166
|
+
if (stripped.length < CARTAO_PAN_MIN_LENGTH || stripped.length > CARTAO_PAN_MAX_LENGTH) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const withoutMask = input.replace(/[\s-]/g, "");
|
|
170
|
+
if (/[^0-9]/.test(withoutMask)) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return passesLuhn(stripped);
|
|
174
|
+
}
|
|
175
|
+
function isValidCartaoCredito(input) {
|
|
176
|
+
return validateCartaoCredito(input).ok;
|
|
177
|
+
}
|
|
178
|
+
function validateCartaoCredito(input) {
|
|
179
|
+
const stripped = stripCartaoCredito(input);
|
|
180
|
+
const structural = validateStructure(input, stripped);
|
|
181
|
+
if (structural) {
|
|
182
|
+
return structural;
|
|
183
|
+
}
|
|
184
|
+
if (!passesLuhn(stripped)) {
|
|
185
|
+
return failure("INVALID_CHECK_DIGIT", "Credit card PAN check digit is invalid");
|
|
186
|
+
}
|
|
187
|
+
const brand = detectCardBrand(stripped);
|
|
188
|
+
return {
|
|
189
|
+
ok: true,
|
|
190
|
+
value: brandCartaoCredito(stripped),
|
|
191
|
+
format: "cartao-credito",
|
|
192
|
+
brand
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/format/cartao-credito.ts
|
|
197
|
+
function formatCartaoCredito(input) {
|
|
198
|
+
const result = validateCartaoCredito(input);
|
|
199
|
+
if (!result.ok) {
|
|
200
|
+
return { ok: false, code: result.code, message: result.message };
|
|
201
|
+
}
|
|
202
|
+
return { ok: true, formatted: applyCartaoCreditoMask(result.value) };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export { CARTAO_GOLDEN_AMEX, CARTAO_GOLDEN_LUHN_WALKTHROUGH, CARTAO_GOLDEN_MASTERCARD, CARTAO_GOLDEN_MIN_LENGTH, CARTAO_GOLDEN_VISA, CARTAO_GOLDEN_VISA_MASKED, CARTAO_IEC_SOURCE_URL, CARTAO_OFFICIAL_SOURCE_URL, CARTAO_PAN_MAX_LENGTH, CARTAO_PAN_MIN_LENGTH, computeLuhnSum, detectCardBrand, formatCartaoCredito, isValidCartaoCredito, isValidLuhn, passesLuhn, stripCartaoCredito, validateCartaoCredito };
|
|
206
|
+
//# sourceMappingURL=chunk-54DTXC6V.js.map
|
|
207
|
+
//# sourceMappingURL=chunk-54DTXC6V.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strip/cartao-credito.ts","../src/core/cartao-credito/constants.ts","../src/core/cartao-credito/detect-brand.ts","../src/core/cartao-credito/luhn.ts","../src/core/cartao-credito/mask.ts","../src/core/cartao-credito/index.ts","../src/format/cartao-credito.ts"],"names":[],"mappings":";;;AAIO,SAAS,mBAAmB,KAAA,EAAuB;AACxD,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAChC;;;ACCO,IAAM,qBAAA,GAAwB;AAC9B,IAAM,qBAAA,GAAwB;AAE9B,IAAM,kBAAA,GAAqB;AAC3B,IAAM,wBAAA,GAA2B;AACjC,IAAM,kBAAA,GAAqB;AAC3B,IAAM,8BAAA,GAAiC;AACvC,IAAM,yBAAA,GAA4B;AAClC,IAAM,wBAAA,GAA2B;AAEjC,IAAM,0BAAA,GAA6B;AACnC,IAAM,qBAAA,GAAwB;AAG9B,IAAM,gBAAA,GAAmB;AAAA,EAC9B,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;AAAA,EACA,QAAA;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;AClGO,SAAS,oBAAoB,KAAA,EAA6B;AAC/D,EAAA,MAAM,MAAA,GAAS,sBAAsB,KAAK,CAAA;AAC1C,EAAA,IAAI,CAAC,OAAO,EAAA,EAAI;AACd,IAAA,OAAO,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,OAAO,IAAA,EAAM,OAAA,EAAS,OAAO,OAAA,EAAQ;AAAA,EACjE;AACA,EAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,WAAW,sBAAA,CAAuB,MAAA,CAAO,KAAK,CAAA,EAAE;AACrE","file":"chunk-54DTXC6V.js","sourcesContent":["/**\n * Strip credit card PAN mask — digits only (BR-LUHN-001).\n * @see https://www.iso.org/standard/70484.html\n */\nexport function stripCartaoCredito(input: string): string {\n return input.replace(/\\D/g, '');\n}\n","/**\n * Credit card PAN constants — ISO/IEC 7812-1 Annex B (Luhn).\n * @see https://www.iso.org/standard/70484.html\n * @see docs/use-cases/UC-008-validate-cartao-credito.md\n */\nexport type CardBrand = 'visa' | 'mastercard' | 'amex' | 'elo' | 'hipercard' | 'unknown';\n\nexport const CARTAO_PAN_MIN_LENGTH = 8;\nexport const CARTAO_PAN_MAX_LENGTH = 19;\n\nexport const CARTAO_GOLDEN_VISA = '4111111111111111';\nexport const CARTAO_GOLDEN_MASTERCARD = '5555555555554444';\nexport const CARTAO_GOLDEN_AMEX = '378282246310005';\nexport const CARTAO_GOLDEN_LUHN_WALKTHROUGH = '79927398713';\nexport const CARTAO_GOLDEN_VISA_MASKED = '4111 1111 1111 1111';\nexport const CARTAO_GOLDEN_MIN_LENGTH = '12345674';\n\nexport const CARTAO_OFFICIAL_SOURCE_URL = 'https://www.iso.org/standard/70484.html';\nexport const CARTAO_IEC_SOURCE_URL = 'https://webstore.iec.ch/en/publication/59763';\n\n/** Best-effort IIN prefixes — longest match first (BR-LUHN-005, non-authoritative). */\nexport const ELO_IIN_PREFIXES = [\n '401178',\n '401179',\n '431274',\n '438935',\n '451416',\n '457393',\n '457631',\n '457632',\n '504175',\n '506699',\n '506770',\n '509048',\n '509049',\n '627780',\n '636297',\n '636368',\n '650031',\n '650032',\n '650033',\n '650035',\n '650051',\n '650405',\n '650439',\n '650485',\n '650486',\n '650487',\n '650488',\n '650489',\n '650490',\n '650491',\n '650492',\n '650493',\n '650494',\n '650495',\n '650496',\n '650497',\n '650498',\n '650499',\n '651652',\n '651653',\n '651654',\n '651655',\n '651656',\n '651657',\n '651658',\n '651659',\n '651660',\n '655000',\n '655001',\n] as const;\n\nexport const HIPERCARD_IIN_PREFIXES = ['606282', '384100'] as const;\n","/**\n * Best-effort card brand from IIN prefix — non-authoritative (BR-LUHN-005).\n */\nimport type { CardBrand } from './constants.js';\nimport { ELO_IIN_PREFIXES, HIPERCARD_IIN_PREFIXES } from './constants.js';\n\nexport type { CardBrand };\n\nexport function detectCardBrand(strippedPan: string): CardBrand {\n for (const prefix of ELO_IIN_PREFIXES) {\n if (strippedPan.startsWith(prefix)) {\n return 'elo';\n }\n }\n\n for (const prefix of HIPERCARD_IIN_PREFIXES) {\n if (strippedPan.startsWith(prefix)) {\n return 'hipercard';\n }\n }\n\n if (/^3[47]/.test(strippedPan)) {\n return 'amex';\n }\n\n if (/^5[1-5]/.test(strippedPan) || /^2[2-7]/.test(strippedPan)) {\n return 'mastercard';\n }\n\n if (strippedPan.startsWith('4')) {\n return 'visa';\n }\n\n return 'unknown';\n}\n","/**\n * Luhn checksum — ISO/IEC 7812-1 Annex B (modulus-10 double-add-double).\n * @see BR-LUHN-003\n */\n\nexport function computeLuhnSum(pan: string): number {\n let sum = 0;\n let double = false;\n for (let i = pan.length - 1; i >= 0; i--) {\n let digit = Number(pan.charAt(i));\n if (double) {\n digit *= 2;\n if (digit > 9) {\n digit -= 9;\n }\n }\n sum += digit;\n double = !double;\n }\n return sum;\n}\n\n/** ISO/IEC 7812-1 Annex B — returns true when PAN passes Luhn. */\nexport function passesLuhn(pan: string): boolean {\n return computeLuhnSum(pan) % 10 === 0;\n}\n","import { CARTAO_PAN_MAX_LENGTH, CARTAO_PAN_MIN_LENGTH } from './constants.js';\n\n/** Grouped display mask (BR-LUHN-007). */\nexport function applyCartaoCreditoMask(canonical: string): string {\n if (canonical.length < CARTAO_PAN_MIN_LENGTH || canonical.length > CARTAO_PAN_MAX_LENGTH) {\n throw new Error(`PAN must have between ${CARTAO_PAN_MIN_LENGTH} and ${CARTAO_PAN_MAX_LENGTH} digits to apply mask`);\n }\n\n if (canonical.length === 15) {\n return `${canonical.slice(0, 4)} ${canonical.slice(4, 10)} ${canonical.slice(10)}`;\n }\n\n const groups: string[] = [];\n for (let i = 0; i < canonical.length; i += 4) {\n groups.push(canonical.slice(i, i + 4));\n }\n return groups.join(' ');\n}\n","/**\n * Credit card PAN validation — Luhn / ISO/IEC 7812-1 Annex B.\n * @see docs/use-cases/UC-008-validate-cartao-credito.md\n */\nimport { stripCartaoCredito } from '../../strip/cartao-credito.js';\nimport type { CartaoCreditoValidationResult } from '../../types/validation-result.js';\nimport { brandCartaoCredito } from '../../types/validation-result.js';\nimport { detectCardBrand } from './detect-brand.js';\nimport { CARTAO_PAN_MAX_LENGTH, CARTAO_PAN_MIN_LENGTH } from './constants.js';\nimport { passesLuhn } from './luhn.js';\n\nexport {\n CARTAO_GOLDEN_AMEX,\n CARTAO_GOLDEN_LUHN_WALKTHROUGH,\n CARTAO_GOLDEN_MASTERCARD,\n CARTAO_GOLDEN_MIN_LENGTH,\n CARTAO_GOLDEN_VISA,\n CARTAO_GOLDEN_VISA_MASKED,\n CARTAO_IEC_SOURCE_URL,\n CARTAO_OFFICIAL_SOURCE_URL,\n CARTAO_PAN_MAX_LENGTH,\n CARTAO_PAN_MIN_LENGTH,\n} from './constants.js';\nexport type { CardBrand } from './constants.js';\nexport { detectCardBrand } from './detect-brand.js';\nexport { computeLuhnSum, passesLuhn } from './luhn.js';\nexport { applyCartaoCreditoMask } from './mask.js';\n\ntype FailedResult = Extract<CartaoCreditoValidationResult, { ok: false }>;\n\nfunction failure(code: FailedResult['code'], message: string): FailedResult {\n return { ok: false, code, message };\n}\n\nfunction hasRepeatedDigits(value: string): boolean {\n const first = value[0];\n for (let i = 1; i < value.length; i++) {\n if (value[i] !== first) {\n return false;\n }\n }\n return true;\n}\n\nfunction validateStructure(input: string, stripped: string): FailedResult | null {\n if (stripped.length === 0) {\n return failure('EMPTY_INPUT', 'Credit card PAN input is empty');\n }\n\n const withoutMask = input.replace(/[\\s-]/g, '');\n if (/[^0-9]/.test(withoutMask)) {\n return failure('INVALID_CHARACTER', 'Credit card PAN contains invalid characters');\n }\n\n if (stripped.length < CARTAO_PAN_MIN_LENGTH || stripped.length > CARTAO_PAN_MAX_LENGTH) {\n return failure(\n 'INVALID_LENGTH',\n `Credit card PAN must have between ${CARTAO_PAN_MIN_LENGTH} and ${CARTAO_PAN_MAX_LENGTH} digits after normalization`,\n );\n }\n\n if (hasRepeatedDigits(stripped)) {\n return failure('KNOWN_INVALID_PATTERN', 'Credit card PAN with all identical digits is invalid');\n }\n\n return null;\n}\n\nexport function isValidLuhn(input: string): boolean {\n const stripped = stripCartaoCredito(input);\n if (stripped.length < CARTAO_PAN_MIN_LENGTH || stripped.length > CARTAO_PAN_MAX_LENGTH) {\n return false;\n }\n const withoutMask = input.replace(/[\\s-]/g, '');\n if (/[^0-9]/.test(withoutMask)) {\n return false;\n }\n return passesLuhn(stripped);\n}\n\nexport function isValidCartaoCredito(input: string): boolean {\n return validateCartaoCredito(input).ok;\n}\n\nexport function validateCartaoCredito(input: string): CartaoCreditoValidationResult {\n const stripped = stripCartaoCredito(input);\n const structural = validateStructure(input, stripped);\n if (structural) {\n return structural;\n }\n\n if (!passesLuhn(stripped)) {\n return failure('INVALID_CHECK_DIGIT', 'Credit card PAN check digit is invalid');\n }\n\n const brand = detectCardBrand(stripped);\n return {\n ok: true,\n value: brandCartaoCredito(stripped),\n format: 'cartao-credito',\n brand,\n };\n}\n","import { applyCartaoCreditoMask } from '../core/cartao-credito/mask.js';\nimport { validateCartaoCredito } from '../core/cartao-credito/index.js';\nimport type { FormatResult } from '../types/validation-result.js';\n\nexport function formatCartaoCredito(input: string): FormatResult {\n const result = validateCartaoCredito(input);\n if (!result.ok) {\n return { ok: false, code: result.code, message: result.message };\n }\n return { ok: true, formatted: applyCartaoCreditoMask(result.value) };\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { validateCnpj, applyCnpjMask } from './chunk-M66MGLHE.js';
|
|
2
|
+
|
|
3
|
+
// src/format/cnpj.ts
|
|
4
|
+
function formatCnpj(input) {
|
|
5
|
+
const result = validateCnpj(input);
|
|
6
|
+
if (!result.ok) {
|
|
7
|
+
return { ok: false, code: result.code, message: result.message };
|
|
8
|
+
}
|
|
9
|
+
return { ok: true, formatted: applyCnpjMask(result.value) };
|
|
10
|
+
}
|
|
11
|
+
function formatCnpjNumeric(input) {
|
|
12
|
+
return formatCnpj(input);
|
|
13
|
+
}
|
|
14
|
+
function formatCnpjAlphanumeric(input) {
|
|
15
|
+
return formatCnpj(input);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { formatCnpj, formatCnpjAlphanumeric, formatCnpjNumeric };
|
|
19
|
+
//# sourceMappingURL=chunk-7FOWIH6F.js.map
|
|
20
|
+
//# sourceMappingURL=chunk-7FOWIH6F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/cnpj.ts"],"names":[],"mappings":";;;AAIO,SAAS,WAAW,KAAA,EAA6B;AACtD,EAAA,MAAM,MAAA,GAAS,aAAa,KAAK,CAAA;AACjC,EAAA,IAAI,CAAC,OAAO,EAAA,EAAI;AACd,IAAA,OAAO,EAAE,IAAI,KAAA,EAAO,IAAA,EAAM,OAAO,IAAA,EAAM,OAAA,EAAS,OAAO,OAAA,EAAQ;AAAA,EACjE;AACA,EAAA,OAAO,EAAE,EAAA,EAAI,IAAA,EAAM,WAAW,aAAA,CAAc,MAAA,CAAO,KAAK,CAAA,EAAE;AAC5D;AAEO,SAAS,kBAAkB,KAAA,EAA6B;AAC7D,EAAA,OAAO,WAAW,KAAK,CAAA;AACzB;AAEO,SAAS,uBAAuB,KAAA,EAA6B;AAClE,EAAA,OAAO,WAAW,KAAK,CAAA;AACzB","file":"chunk-7FOWIH6F.js","sourcesContent":["import { applyCnpjMask } from '../core/cnpj/mask.js';\nimport { validateCnpj } from '../core/cnpj/index.js';\nimport type { FormatResult } from '../types/validation-result.js';\n\nexport function formatCnpj(input: string): FormatResult {\n const result = validateCnpj(input);\n if (!result.ok) {\n return { ok: false, code: result.code, message: result.message };\n }\n return { ok: true, formatted: applyCnpjMask(result.value) };\n}\n\nexport function formatCnpjNumeric(input: string): FormatResult {\n return formatCnpj(input);\n}\n\nexport function formatCnpjAlphanumeric(input: string): FormatResult {\n return formatCnpj(input);\n}\n"]}
|