@ts-typed/validators 0.1.0 → 0.1.2
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 +32 -0
- package/README.md +45 -9
- package/dist/br/cep.class.d.ts +6 -0
- package/dist/br/cep.class.d.ts.map +1 -1
- package/dist/br/cep.class.js +9 -0
- package/dist/br/cep.class.js.map +1 -1
- package/dist/br/cnh.class.d.ts +6 -0
- package/dist/br/cnh.class.d.ts.map +1 -1
- package/dist/br/cnh.class.js +9 -0
- package/dist/br/cnh.class.js.map +1 -1
- package/dist/br/cnpj.class.d.ts +12 -0
- package/dist/br/cnpj.class.d.ts.map +1 -1
- package/dist/br/cnpj.class.js +15 -0
- package/dist/br/cnpj.class.js.map +1 -1
- package/dist/br/cpf.class.d.ts +7 -0
- package/dist/br/cpf.class.d.ts.map +1 -1
- package/dist/br/cpf.class.js +10 -0
- package/dist/br/cpf.class.js.map +1 -1
- package/dist/br/pis.class.d.ts +7 -0
- package/dist/br/pis.class.d.ts.map +1 -1
- package/dist/br/pis.class.js +10 -0
- package/dist/br/pis.class.js.map +1 -1
- package/dist/br/placa.class.d.ts +7 -0
- package/dist/br/placa.class.d.ts.map +1 -1
- package/dist/br/placa.class.js +9 -0
- package/dist/br/placa.class.js.map +1 -1
- package/dist/global/credit-card.class.d.ts +20 -0
- package/dist/global/credit-card.class.d.ts.map +1 -0
- package/dist/global/credit-card.class.js +52 -0
- package/dist/global/credit-card.class.js.map +1 -0
- package/dist/global/email.class.d.ts +24 -0
- package/dist/global/email.class.d.ts.map +1 -0
- package/dist/global/email.class.js +42 -0
- package/dist/global/email.class.js.map +1 -0
- package/dist/global/full-name.class.d.ts +23 -0
- package/dist/global/full-name.class.d.ts.map +1 -0
- package/dist/global/full-name.class.js +44 -0
- package/dist/global/full-name.class.js.map +1 -0
- package/dist/global/index.d.ts +4 -0
- package/dist/global/index.d.ts.map +1 -0
- package/dist/global/index.js +10 -0
- package/dist/global/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,38 @@ All notable changes to `@ts-typed/validators` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.1.2] - 2026-10-18
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **`FullName` is no longer Brazil-specific.** Moved from `@ts-typed/validators/br` to a new `@ts-typed/validators/global` entry point (also re-exported from the package root). It no longer validates against `./br`'s exports — `require('@ts-typed/validators/br').FullName` is now `undefined`.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- A new `@ts-typed/validators/global` entry point for validators meant for universal/international use, exporting `FullName`, `Email`, and `CreditCard`.
|
|
16
|
+
- `Email`: validates `local-part@domain.tld` pragmatically (not full RFC 5322) — local part allows letters/digits/`._%+-`, domain allows letters/digits/hyphens/dots, must end in a 2+ letter TLD. Adds `.localPart()`, `.domain()`, and `.redact()` (keeps the local part's first character, masks the rest, shows the domain in full: `"ana@example.com"` -> `"a**@example.com"`).
|
|
17
|
+
- `CreditCard`: validates a payment card number with the Luhn checksum (network-agnostic, works across card networks worldwide). Accepts spaces/hyphens as separators; the cleaned value must be 12-19 digits and pass the Luhn check. Adds `.numbers()`, `.masked()` (last 4 digits shown, rest masked in groups of 4: `"4532015112830366"` -> `"**** **** **** 0366"`), and `.redact()` (same as `.masked()`).
|
|
18
|
+
|
|
19
|
+
## [0.1.1] - 2026-10-18
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- A new `FullName` validator: confirms a value looks like a plausible Brazilian full name (at least two words of letters — including accented characters, apostrophes, hyphens), with `.firstName()` (the first word) and `.lastName()` (everything after the first word).
|
|
24
|
+
- A `.redact()` privacy-masking method on every class except `CEP`'s own numeric-only predecessor behavior changed too (see below):
|
|
25
|
+
- `CPF`: `"123.456.789-09"` -> `"***.456.789-**"` (hide the first group and the check digits).
|
|
26
|
+
- `CNPJ`: hide the first group and the check digits (works for both the legacy numeric and alphanumeric formats).
|
|
27
|
+
- `PIS`/`Pasep`/`Nis`/`Nit`: hide the first group and the final check digit.
|
|
28
|
+
- `CNH`: hide the first 3 and last 2 of its 11 digits.
|
|
29
|
+
- `Placa`: show the 3-letter prefix, mask everything after it (`"ABC1234"`/`"ABC1D23"` -> `"ABC****"`).
|
|
30
|
+
- `CEP`: hide the first 5 digits (area/sector), show only the last 3 (`"12345-678"` -> `"*****-678"`).
|
|
31
|
+
- `FullName`: every word reduced to its first letter plus one asterisk per remaining character (`"Ana Maria Silva Santos"` -> `"A** M**** S**** S*****"`).
|
|
32
|
+
|
|
33
|
+
None of these formats are mandated by a single federal standard — Brazil has no unified rule for this (there's an open legislative proposal asking for one, because fragmented masks across institutions make them easier to reverse-engineer). `CPF`'s format matches a real, documented state transparency-portal convention; the others follow the same principle for consistency, not independent sourcing per document type. `CNPJ` identifies a legal entity, not a natural person — LGPD's personal-data protections don't apply to it the way they do to the others, so `.redact()` there is for API consistency, not a compliance requirement.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- Depends on `@ts-typed/compiler@0.1.22` (the version this package's own dependency was pinned to had fallen behind the app-level direct dependency in a real install, creating two separate `ValueObject`/`StrictTypeError` class instances and silently breaking `@Catch(StrictTypeError)` matching — caught via a real end-to-end demo, same root cause documented in `@ts-typed/nestjs`'s own CHANGELOG history).
|
|
38
|
+
|
|
7
39
|
## [0.1.0] - 2026-10-18
|
|
8
40
|
|
|
9
41
|
### Added
|
package/README.md
CHANGED
|
@@ -7,28 +7,34 @@ npm install @ts-typed/validators
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
|
-
import { CPF } from '@ts-typed/validators
|
|
10
|
+
import { CPF } from '@ts-typed/validators/br';
|
|
11
|
+
import { Email } from '@ts-typed/validators/global';
|
|
11
12
|
|
|
12
13
|
export class CreateUserDto {
|
|
13
|
-
public readonly cpf!: CPF;
|
|
14
|
+
public readonly cpf!: CPF; // Brazil-specific
|
|
15
|
+
public readonly email!: Email; // global
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
class UserService {
|
|
17
19
|
public create(dto: CreateUserDto) {
|
|
18
|
-
console.log(dto.cpf);
|
|
19
|
-
console.log(dto.cpf.masked());
|
|
20
|
-
console.log(dto.
|
|
20
|
+
console.log(dto.cpf); // "12345678909" (or however the client sent it)
|
|
21
|
+
console.log(dto.cpf.masked()); // "123.456.789-09"
|
|
22
|
+
console.log(dto.email.domain()); // "example.com"
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
With `@ts-typed/compiler`'s build step,
|
|
27
|
+
With `@ts-typed/compiler`'s build step, a raw string crossing a typed boundary auto-constructs into a validated instance the moment it's assigned — no manual `new` anywhere in application code, and an invalid value throws before `create()` ever runs.
|
|
26
28
|
|
|
27
29
|
Each class behaves like a string everywhere it matters (`console.log`, template literals, `JSON.stringify`, every native `String.prototype` method), while adding its own validation and formatting methods. See [`@ts-typed/compiler`'s README](https://github.com/ts-typed/compiler#readme) for the full `ValueObject`/auto-construction mechanism this package builds on.
|
|
28
30
|
|
|
29
|
-
##
|
|
31
|
+
## Entry points
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
- `@ts-typed/validators/br` — Brazil-specific document validators.
|
|
34
|
+
- `@ts-typed/validators/global` — validators meant for universal/international use.
|
|
35
|
+
- `@ts-typed/validators` (the bare package root) re-exports everything from both.
|
|
36
|
+
|
|
37
|
+
## Validators (Brazil) — `@ts-typed/validators/br`
|
|
32
38
|
|
|
33
39
|
| Class | Document | Check digit | Accepts |
|
|
34
40
|
|---|---|---|---|
|
|
@@ -39,10 +45,40 @@ Import from `@ts-typed/validators` or `@ts-typed/validators/br` (same exports, e
|
|
|
39
45
|
| `Placa` | Vehicle plate | Format only — no check digit exists | Legacy (`"ABC1234"`) or Mercosul (`"ABC1D23"`) |
|
|
40
46
|
| `CNH` | Driver's license number | Modulus 11 | `"03215478120"` |
|
|
41
47
|
|
|
42
|
-
Every class exposes `.numbers()` (the normalized, unformatted value) and, where there's a natural display format, `.masked()`. `CNH` has no standard formatted display form, so it only exposes `.numbers()`.
|
|
48
|
+
Every document class exposes `.numbers()` (the normalized, unformatted value) and, where there's a natural display format, `.masked()`. `CNH` has no standard formatted display form, so it only exposes `.numbers()`.
|
|
43
49
|
|
|
44
50
|
**`CEP` and `Placa` validate FORMAT only** — neither document type has a nationally standardized check digit, so these confirm shape (length/pattern), not that a specific number was actually issued.
|
|
45
51
|
|
|
52
|
+
## Validators (global) — `@ts-typed/validators/global`
|
|
53
|
+
|
|
54
|
+
| Class | What it validates | Notes |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `FullName` | A plausible full name (first + surname, any locale/script) | No check digit — plausibility only. `.firstName()`, `.lastName()`. |
|
|
57
|
+
| `Email` | `local-part@domain.tld` | Pragmatic format check, not full RFC 5322. `.localPart()`, `.domain()`. |
|
|
58
|
+
| `CreditCard` | A payment card number | Luhn checksum (network-agnostic). Accepts space/hyphen separators; 12-19 digits. `.numbers()`, `.masked()`. |
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { Email, CreditCard, FullName } from '@ts-typed/validators/global';
|
|
62
|
+
|
|
63
|
+
new Email('ana@example.com').domain(); // "example.com"
|
|
64
|
+
new CreditCard('4532 0151 1283 0366').masked(); // "**** **** **** 0366"
|
|
65
|
+
new FullName('Ana Maria Silva Santos').firstName(); // "Ana"
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Privacy masking (`.redact()`)
|
|
69
|
+
|
|
70
|
+
Every class — in both `/br` and `/global` — exposes `.redact()`, for displaying a value in a context where the full value shouldn't be shown (logs, public listings, support tooling):
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
new CPF('123.456.789-09').redact(); // "***.456.789-**"
|
|
74
|
+
new CEP('12345-678').redact(); // "*****-678"
|
|
75
|
+
new FullName('Ana Maria Silva Santos').redact(); // "A** M**** S**** S*****"
|
|
76
|
+
new Email('ana@example.com').redact(); // "a**@example.com"
|
|
77
|
+
new CreditCard('4532015112830366').redact(); // "**** **** **** 0366"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Brazil has no single federal standard for this (there's an open legislative proposal asking for one, precisely because different institutions using different masks makes a number easier to reconstruct by cross-referencing). `CPF`'s format matches a real, documented state transparency-portal convention; the rest follow the same principle for consistency, not independent sourcing per document type. `CNPJ` identifies a legal entity, not a natural person, so LGPD's personal-data rules don't apply to it the way they do the others — its `.redact()` exists for API consistency, not because redacting a CNPJ is commonly required.
|
|
81
|
+
|
|
46
82
|
## Why no `RG`
|
|
47
83
|
|
|
48
84
|
An RG (Registro Geral) has no nationally standardized check digit — the format and whether a check digit exists at all varies by issuing state, and many states have none. Shipping an `RG` class would mean pretending to validate something that can't actually be validated nationwide, so it's deliberately not included.
|
package/dist/br/cep.class.d.ts
CHANGED
|
@@ -12,5 +12,11 @@ export declare class CEP extends ValueObject {
|
|
|
12
12
|
masked(): string;
|
|
13
13
|
/** Digits only: `12345678`. */
|
|
14
14
|
numbers(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Hides the first 5 digits (the part that narrows a location down to a
|
|
17
|
+
* specific area/sector) and shows only the last 3 (the distribution
|
|
18
|
+
* digits): `"12345-678"` -> `"*****-678"`.
|
|
19
|
+
*/
|
|
20
|
+
redact(): string;
|
|
15
21
|
}
|
|
16
22
|
//# sourceMappingURL=cep.class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cep.class.d.ts","sourceRoot":"","sources":["../../src/br/cep.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,2CAA2C;IACpC,MAAM,IAAI,MAAM;IAKvB,+BAA+B;IACxB,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"cep.class.d.ts","sourceRoot":"","sources":["../../src/br/cep.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,2CAA2C;IACpC,MAAM,IAAI,MAAM;IAKvB,+BAA+B;IACxB,OAAO,IAAI,MAAM;IAIxB;;;;OAIG;IACI,MAAM,IAAI,MAAM;CAIxB"}
|
package/dist/br/cep.class.js
CHANGED
|
@@ -24,6 +24,15 @@ class CEP extends compiler_1.ValueObject {
|
|
|
24
24
|
numbers() {
|
|
25
25
|
return this.toString().replace(/[\s./-]/g, '');
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Hides the first 5 digits (the part that narrows a location down to a
|
|
29
|
+
* specific area/sector) and shows only the last 3 (the distribution
|
|
30
|
+
* digits): `"12345-678"` -> `"*****-678"`.
|
|
31
|
+
*/
|
|
32
|
+
redact() {
|
|
33
|
+
const d = this.numbers();
|
|
34
|
+
return `*****-${d.slice(5)}`;
|
|
35
|
+
}
|
|
27
36
|
}
|
|
28
37
|
exports.CEP = CEP;
|
|
29
38
|
//# sourceMappingURL=cep.class.js.map
|
package/dist/br/cep.class.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cep.class.js","sourceRoot":"","sources":["../../src/br/cep.class.ts"],"names":[],"mappings":";;;AA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,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IAED;;;;OAIG;IACI,MAAM;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAC/B,CAAC;CACF;AA7BD,kBA6BC"}
|
package/dist/br/cnh.class.d.ts
CHANGED
|
@@ -11,5 +11,11 @@ export declare class CNH extends ValueObject {
|
|
|
11
11
|
protected isValid(raw: string): boolean;
|
|
12
12
|
/** Digits only: `12345678901`. */
|
|
13
13
|
numbers(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Privacy-masked form: `***154781**`. Hides the first 3 and last 2 digits,
|
|
16
|
+
* showing the middle 6. The CNH has no official masking standard; this
|
|
17
|
+
* applies the same proportion as `CPF.redact()` for consistency.
|
|
18
|
+
*/
|
|
19
|
+
redact(): string;
|
|
14
20
|
}
|
|
15
21
|
//# sourceMappingURL=cnh.class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cnh.class.d.ts","sourceRoot":"","sources":["../../src/br/cnh.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,kCAAkC;IAC3B,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"cnh.class.d.ts","sourceRoot":"","sources":["../../src/br/cnh.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,kCAAkC;IAC3B,OAAO,IAAI,MAAM;IAIxB;;;;OAIG;IACI,MAAM,IAAI,MAAM;CAIxB"}
|
package/dist/br/cnh.class.js
CHANGED
|
@@ -20,6 +20,15 @@ class CNH extends compiler_1.ValueObject {
|
|
|
20
20
|
numbers() {
|
|
21
21
|
return this.toString().replace(/[\s./-]/g, '');
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Privacy-masked form: `***154781**`. Hides the first 3 and last 2 digits,
|
|
25
|
+
* showing the middle 6. The CNH has no official masking standard; this
|
|
26
|
+
* applies the same proportion as `CPF.redact()` for consistency.
|
|
27
|
+
*/
|
|
28
|
+
redact() {
|
|
29
|
+
const d = this.numbers();
|
|
30
|
+
return `***${d.slice(3, 9)}**`;
|
|
31
|
+
}
|
|
23
32
|
}
|
|
24
33
|
exports.CNH = CNH;
|
|
25
34
|
function isValidCNH(cleaned) {
|
package/dist/br/cnh.class.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cnh.class.js","sourceRoot":"","sources":["../../src/br/cnh.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;;GAMG;AACH,MAAa,GAAI,SAAQ,sBAAW;IAClC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,OAAO,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,kCAAkC;IAC3B,OAAO;QACZ,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"cnh.class.js","sourceRoot":"","sources":["../../src/br/cnh.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;;GAMG;AACH,MAAa,GAAI,SAAQ,sBAA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AC,CAAC,MAAM,CAAC;IACvC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM;QAAE,OAAO,KAAK,CAAC;IACvC,MAAM,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACnE,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC;AAC9B,CAAC"}
|
package/dist/br/cnpj.class.d.ts
CHANGED
|
@@ -17,5 +17,17 @@ export declare class CNPJ extends ValueObject {
|
|
|
17
17
|
masked(): string;
|
|
18
18
|
/** Normalized unformatted value, uppercased: `12ABC34501DE35`. */
|
|
19
19
|
numbers(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Privacy-masked display form: `**.ABC.345/01DE-**`. Hides the first
|
|
22
|
+
* 2-character group and the final 2 check digits.
|
|
23
|
+
*
|
|
24
|
+
* CNPJ identifies a LEGAL ENTITY (a company), not a natural person. LGPD's
|
|
25
|
+
* personal-data protections apply to pessoa física, so redacting a CNPJ is
|
|
26
|
+
* not a legal requirement the way it is for CPF. This method exists for API
|
|
27
|
+
* consistency with the other document classes, not because CNPJ redaction is
|
|
28
|
+
* commonly practiced or required. The masking pattern follows the same
|
|
29
|
+
* principle as `CPF.redact()`; it is not a CNPJ-specific federal standard.
|
|
30
|
+
*/
|
|
31
|
+
redact(): string;
|
|
20
32
|
}
|
|
21
33
|
//# sourceMappingURL=cnpj.class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cnpj.class.d.ts","sourceRoot":"","sources":["../../src/br/cnpj.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,qBAAa,IAAK,SAAQ,WAAW;gBAChB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,8EAA8E;IACvE,MAAM,IAAI,MAAM;IAKvB,kEAAkE;IAC3D,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"cnpj.class.d.ts","sourceRoot":"","sources":["../../src/br/cnpj.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,qBAAa,IAAK,SAAQ,WAAW;gBAChB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,8EAA8E;IACvE,MAAM,IAAI,MAAM;IAKvB,kEAAkE;IAC3D,OAAO,IAAI,MAAM;IAIxB;;;;;;;;;;OAUG;IACI,MAAM,IAAI,MAAM;CAIxB"}
|
package/dist/br/cnpj.class.js
CHANGED
|
@@ -29,6 +29,21 @@ class CNPJ extends compiler_1.ValueObject {
|
|
|
29
29
|
numbers() {
|
|
30
30
|
return normalize(this.toString());
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Privacy-masked display form: `**.ABC.345/01DE-**`. Hides the first
|
|
34
|
+
* 2-character group and the final 2 check digits.
|
|
35
|
+
*
|
|
36
|
+
* CNPJ identifies a LEGAL ENTITY (a company), not a natural person. LGPD's
|
|
37
|
+
* personal-data protections apply to pessoa física, so redacting a CNPJ is
|
|
38
|
+
* not a legal requirement the way it is for CPF. This method exists for API
|
|
39
|
+
* consistency with the other document classes, not because CNPJ redaction is
|
|
40
|
+
* commonly practiced or required. The masking pattern follows the same
|
|
41
|
+
* principle as `CPF.redact()`; it is not a CNPJ-specific federal standard.
|
|
42
|
+
*/
|
|
43
|
+
redact() {
|
|
44
|
+
const v = this.numbers();
|
|
45
|
+
return `**.${v.slice(2, 5)}.${v.slice(5, 8)}/${v.slice(8, 12)}-**`;
|
|
46
|
+
}
|
|
32
47
|
}
|
|
33
48
|
exports.CNPJ = CNPJ;
|
|
34
49
|
function normalize(raw) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cnpj.class.js","sourceRoot":"","sources":["../../src/br/cnpj.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;;;;;;GAUG;AACH,MAAa,IAAK,SAAQ,sBAAW;IACnC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,OAAO,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,8EAA8E;IACvE,MAAM;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;IAC/F,CAAC;IAED,kEAAkE;IAC3D,OAAO;QACZ,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"cnpj.class.js","sourceRoot":"","sources":["../../src/br/cnpj.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;;;;;;GAUG;AACH,MAAa,IAAK,SAAQ,sBAAW;IACnC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,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CAAC;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;IACjD,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/br/cpf.class.d.ts
CHANGED
|
@@ -9,5 +9,12 @@ export declare class CPF extends ValueObject {
|
|
|
9
9
|
masked(): string;
|
|
10
10
|
/** Digits only: `12345678901`. */
|
|
11
11
|
numbers(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Privacy-masked display form: `***.456.789-**`. Hides the first 3-digit
|
|
14
|
+
* group and the two check digits, showing the middle groups. This follows a
|
|
15
|
+
* convention used by at least one state's public transparency portal for
|
|
16
|
+
* CPF; it is a widely used practice, not a single federal standard.
|
|
17
|
+
*/
|
|
18
|
+
redact(): string;
|
|
12
19
|
}
|
|
13
20
|
//# sourceMappingURL=cpf.class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cpf.class.d.ts","sourceRoot":"","sources":["../../src/br/cpf.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKvC,gDAAgD;IACzC,MAAM,IAAI,MAAM;IAKvB,kCAAkC;IAC3B,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"cpf.class.d.ts","sourceRoot":"","sources":["../../src/br/cpf.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;GAEG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKvC,gDAAgD;IACzC,MAAM,IAAI,MAAM;IAKvB,kCAAkC;IAC3B,OAAO,IAAI,MAAM;IAIxB;;;;;OAKG;IACI,MAAM,IAAI,MAAM;CAIxB"}
|
package/dist/br/cpf.class.js
CHANGED
|
@@ -22,6 +22,16 @@ class CPF extends compiler_1.ValueObject {
|
|
|
22
22
|
numbers() {
|
|
23
23
|
return this.toString().replace(/[\s./-]/g, '');
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Privacy-masked display form: `***.456.789-**`. Hides the first 3-digit
|
|
27
|
+
* group and the two check digits, showing the middle groups. This follows a
|
|
28
|
+
* convention used by at least one state's public transparency portal for
|
|
29
|
+
* CPF; it is a widely used practice, not a single federal standard.
|
|
30
|
+
*/
|
|
31
|
+
redact() {
|
|
32
|
+
const d = this.numbers();
|
|
33
|
+
return `***.${d.slice(3, 6)}.${d.slice(6, 9)}-**`;
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
exports.CPF = CPF;
|
|
27
37
|
function isValidCPF(cleaned) {
|
package/dist/br/cpf.class.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cpf.class.js","sourceRoot":"","sources":["../../src/br/cpf.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;GAEG;AACH,MAAa,GAAI,SAAQ,sBAAW;IAClC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAC5C,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAED,gDAAgD;IACzC,MAAM;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAA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EAAE,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/br/pis.class.d.ts
CHANGED
|
@@ -11,6 +11,13 @@ export declare class PIS extends ValueObject {
|
|
|
11
11
|
masked(): string;
|
|
12
12
|
/** Digits only: `12065328705`. */
|
|
13
13
|
numbers(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Privacy-masked display form: `***.65328.70-*`. Hides the first 3-digit
|
|
16
|
+
* group and the final check digit, showing the middle portion. This applies
|
|
17
|
+
* the same proportional masking principle as `CPF.redact()`; it is not a
|
|
18
|
+
* PIS-specific federal standard.
|
|
19
|
+
*/
|
|
20
|
+
redact(): string;
|
|
14
21
|
}
|
|
15
22
|
export { PIS as Pasep, PIS as Nis, PIS as Nit };
|
|
16
23
|
//# sourceMappingURL=pis.class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pis.class.d.ts","sourceRoot":"","sources":["../../src/br/pis.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,gDAAgD;IACzC,MAAM,IAAI,MAAM;IAKvB,kCAAkC;IAC3B,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"pis.class.d.ts","sourceRoot":"","sources":["../../src/br/pis.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,GAAI,SAAQ,WAAW;gBACf,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,gDAAgD;IACzC,MAAM,IAAI,MAAM;IAKvB,kCAAkC;IAC3B,OAAO,IAAI,MAAM;IAIxB;;;;;OAKG;IACI,MAAM,IAAI,MAAM;CAIxB;AAED,OAAO,EAAE,GAAG,IAAI,KAAK,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,CAAC"}
|
package/dist/br/pis.class.js
CHANGED
|
@@ -23,6 +23,16 @@ class PIS extends compiler_1.ValueObject {
|
|
|
23
23
|
numbers() {
|
|
24
24
|
return this.toString().replace(/[\s./-]/g, '');
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Privacy-masked display form: `***.65328.70-*`. Hides the first 3-digit
|
|
28
|
+
* group and the final check digit, showing the middle portion. This applies
|
|
29
|
+
* the same proportional masking principle as `CPF.redact()`; it is not a
|
|
30
|
+
* PIS-specific federal standard.
|
|
31
|
+
*/
|
|
32
|
+
redact() {
|
|
33
|
+
const d = this.numbers();
|
|
34
|
+
return `***.${d.slice(3, 8)}.${d.slice(8, 10)}-*`;
|
|
35
|
+
}
|
|
26
36
|
}
|
|
27
37
|
exports.PIS = PIS;
|
|
28
38
|
exports.Pasep = PIS;
|
package/dist/br/pis.class.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pis.class.js","sourceRoot":"","sources":["../../src/br/pis.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;GAIG;AACH,MAAa,GAAI,SAAQ,sBAAW;IAClC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,OAAO,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,gDAAgD;IACzC,MAAM;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CA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AAC;CACF;AA9BD,kBA8BC;AAEe,oBAAK;AAAS,kBAAG;AAAS,kBAAG;AAE7C,SAAS,UAAU,CAAC,OAAe;IACjC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5E,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAClE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;IACzB,IAAI,EAAE,IAAI,EAAE;QAAE,EAAE,GAAG,CAAC,CAAC;IACrB,OAAO,EAAE,KAAK,MAAM,CAAC,EAAE,CAAC,CAAC;AAC3B,CAAC"}
|
package/dist/br/placa.class.d.ts
CHANGED
|
@@ -15,5 +15,12 @@ export declare class Placa extends ValueObject {
|
|
|
15
15
|
masked(): string;
|
|
16
16
|
/** Normalized uppercase value without separators: `ABC1234` or `ABC1D23`. */
|
|
17
17
|
numbers(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Privacy-masked form: `ABC****` for either format (legacy or Mercosul),
|
|
20
|
+
* with no separator. Shows the 3-letter prefix and masks the rest. This is a
|
|
21
|
+
* reasonable, consistent masking convention chosen for this library; it is
|
|
22
|
+
* not an official plate-specific standard.
|
|
23
|
+
*/
|
|
24
|
+
redact(): string;
|
|
18
25
|
}
|
|
19
26
|
//# sourceMappingURL=placa.class.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placa.class.d.ts","sourceRoot":"","sources":["../../src/br/placa.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD;;;;;;;;GAQG;AACH,qBAAa,KAAM,SAAQ,WAAW;gBACjB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKvC,2EAA2E;IACpE,MAAM,IAAI,MAAM;IAKvB,6EAA6E;IACtE,OAAO,IAAI,MAAM;
|
|
1
|
+
{"version":3,"file":"placa.class.d.ts","sourceRoot":"","sources":["../../src/br/placa.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD;;;;;;;;GAQG;AACH,qBAAa,KAAM,SAAQ,WAAW;gBACjB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKvC,2EAA2E;IACpE,MAAM,IAAI,MAAM;IAKvB,6EAA6E;IACtE,OAAO,IAAI,MAAM;IAIxB;;;;;OAKG;IACI,MAAM,IAAI,MAAM;CAGxB"}
|
package/dist/br/placa.class.js
CHANGED
|
@@ -30,6 +30,15 @@ class Placa extends compiler_1.ValueObject {
|
|
|
30
30
|
numbers() {
|
|
31
31
|
return normalize(this.toString());
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Privacy-masked form: `ABC****` for either format (legacy or Mercosul),
|
|
35
|
+
* with no separator. Shows the 3-letter prefix and masks the rest. This is a
|
|
36
|
+
* reasonable, consistent masking convention chosen for this library; it is
|
|
37
|
+
* not an official plate-specific standard.
|
|
38
|
+
*/
|
|
39
|
+
redact() {
|
|
40
|
+
return `${this.numbers().slice(0, 3)}****`;
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
43
|
exports.Placa = Placa;
|
|
35
44
|
function normalize(raw) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placa.class.js","sourceRoot":"","sources":["../../src/br/placa.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAa,KAAM,SAAQ,sBAAW;IACpC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,2EAA2E;IACpE,MAAM;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,6EAA6E;IACtE,OAAO;QACZ,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpC,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"placa.class.js","sourceRoot":"","sources":["../../src/br/placa.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD,MAAM,MAAM,GAAG,iBAAiB,CAAC;AACjC,MAAM,QAAQ,GAAG,wBAAwB,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAa,KAAM,SAAQ,sBAAW;IACpC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,2EAA2E;IACpE,MAAM;QACX,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED,6EAA6E;IACtE,OAAO;QACZ,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACI,MAAM;QACX,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC;IAC7C,CAAC;CACF;AA9BD,sBA8BC;AAED,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ValueObject } from '@ts-typed/compiler';
|
|
2
|
+
/**
|
|
3
|
+
* A payment card number, validated with the Luhn checksum: a network-agnostic
|
|
4
|
+
* check used by card numbers worldwide. Separators (spaces or hyphens) are
|
|
5
|
+
* accepted; the cleaned value must be 12 to 19 digits and pass the Luhn check.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CreditCard extends ValueObject {
|
|
8
|
+
constructor(raw: string);
|
|
9
|
+
protected isValid(raw: string): boolean;
|
|
10
|
+
/** Digits only, separators removed: `"4532 0151 1283 0366"` -> `"4532015112830366"`. */
|
|
11
|
+
numbers(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Card display form: only the last 4 digits are shown, the rest masked, in
|
|
14
|
+
* groups of 4: `"4532015112830366"` -> `"**** **** **** 0366"`.
|
|
15
|
+
*/
|
|
16
|
+
masked(): string;
|
|
17
|
+
/** Card display is already a redaction by convention, so this is the same as `masked()`. */
|
|
18
|
+
redact(): string;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=credit-card.class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-card.class.d.ts","sourceRoot":"","sources":["../../src/global/credit-card.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;GAIG;AACH,qBAAa,UAAW,SAAQ,WAAW;gBACtB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKvC,wFAAwF;IACjF,OAAO,IAAI,MAAM;IAIxB;;;OAGG;IACI,MAAM,IAAI,MAAM;IAMvB,4FAA4F;IACrF,MAAM,IAAI,MAAM;CAGxB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreditCard = void 0;
|
|
4
|
+
const compiler_1 = require("@ts-typed/compiler");
|
|
5
|
+
/**
|
|
6
|
+
* A payment card number, validated with the Luhn checksum: a network-agnostic
|
|
7
|
+
* check used by card numbers worldwide. Separators (spaces or hyphens) are
|
|
8
|
+
* accepted; the cleaned value must be 12 to 19 digits and pass the Luhn check.
|
|
9
|
+
*/
|
|
10
|
+
class CreditCard extends compiler_1.ValueObject {
|
|
11
|
+
constructor(raw) {
|
|
12
|
+
super(raw);
|
|
13
|
+
}
|
|
14
|
+
isValid(raw) {
|
|
15
|
+
const cleaned = raw.replace(/[\s-]/g, '');
|
|
16
|
+
return /^\d{12,19}$/.test(cleaned) && isValidLuhn(cleaned);
|
|
17
|
+
}
|
|
18
|
+
/** Digits only, separators removed: `"4532 0151 1283 0366"` -> `"4532015112830366"`. */
|
|
19
|
+
numbers() {
|
|
20
|
+
return this.toString().replace(/[\s-]/g, '');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Card display form: only the last 4 digits are shown, the rest masked, in
|
|
24
|
+
* groups of 4: `"4532015112830366"` -> `"**** **** **** 0366"`.
|
|
25
|
+
*/
|
|
26
|
+
masked() {
|
|
27
|
+
const digits = this.numbers();
|
|
28
|
+
const hidden = '*'.repeat(digits.length - 4).match(/.{1,4}/g) ?? [];
|
|
29
|
+
return [...hidden, digits.slice(-4)].join(' ');
|
|
30
|
+
}
|
|
31
|
+
/** Card display is already a redaction by convention, so this is the same as `masked()`. */
|
|
32
|
+
redact() {
|
|
33
|
+
return this.masked();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.CreditCard = CreditCard;
|
|
37
|
+
function isValidLuhn(digits) {
|
|
38
|
+
let sum = 0;
|
|
39
|
+
let shouldDouble = false;
|
|
40
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
41
|
+
let d = Number(digits[i]);
|
|
42
|
+
if (shouldDouble) {
|
|
43
|
+
d *= 2;
|
|
44
|
+
if (d > 9)
|
|
45
|
+
d -= 9;
|
|
46
|
+
}
|
|
47
|
+
sum += d;
|
|
48
|
+
shouldDouble = !shouldDouble;
|
|
49
|
+
}
|
|
50
|
+
return sum % 10 === 0;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=credit-card.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-card.class.js","sourceRoot":"","sources":["../../src/global/credit-card.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;GAIG;AACH,MAAa,UAAW,SAAQ,sBAAW;IACzC,YAAmB,GA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ACpB,CAAC;QACD,GAAG,IAAI,CAAC,CAAC;QACT,YAAY,GAAG,CAAC,YAAY,CAAC;IAC/B,CAAC;IACD,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ValueObject } from '@ts-typed/compiler';
|
|
2
|
+
/**
|
|
3
|
+
* An email address, validated pragmatically rather than against the full
|
|
4
|
+
* RFC 5322 grammar: `local-part@domain.tld`. The local part allows letters,
|
|
5
|
+
* digits and `. _ % + -`; the domain allows letters, digits, hyphens and dots,
|
|
6
|
+
* and must end in a TLD of at least two letters. This matches the format
|
|
7
|
+
* checks most real-world systems apply.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Email extends ValueObject {
|
|
10
|
+
constructor(raw: string);
|
|
11
|
+
protected isValid(raw: string): boolean;
|
|
12
|
+
/** Everything before the `@`: `"ana@example.com"` -> `"ana"`. */
|
|
13
|
+
localPart(): string;
|
|
14
|
+
/** Everything after the `@`: `"ana@example.com"` -> `"example.com"`. */
|
|
15
|
+
domain(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Privacy-masked display form: the first character of the local part is
|
|
18
|
+
* kept, the rest of it is masked, and the domain is shown in full:
|
|
19
|
+
* `"ana@example.com"` -> `"a**@example.com"`. A one-character local part
|
|
20
|
+
* has nothing to mask, so it is shown as-is: `"j@example.com"`.
|
|
21
|
+
*/
|
|
22
|
+
redact(): string;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=email.class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.class.d.ts","sourceRoot":"","sources":["../../src/global/email.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,KAAM,SAAQ,WAAW;gBACjB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIvC,iEAAiE;IAC1D,SAAS,IAAI,MAAM;IAK1B,wEAAwE;IACjE,MAAM,IAAI,MAAM;IAKvB;;;;;OAKG;IACI,MAAM,IAAI,MAAM;CAKxB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Email = void 0;
|
|
4
|
+
const compiler_1 = require("@ts-typed/compiler");
|
|
5
|
+
/**
|
|
6
|
+
* An email address, validated pragmatically rather than against the full
|
|
7
|
+
* RFC 5322 grammar: `local-part@domain.tld`. The local part allows letters,
|
|
8
|
+
* digits and `. _ % + -`; the domain allows letters, digits, hyphens and dots,
|
|
9
|
+
* and must end in a TLD of at least two letters. This matches the format
|
|
10
|
+
* checks most real-world systems apply.
|
|
11
|
+
*/
|
|
12
|
+
class Email extends compiler_1.ValueObject {
|
|
13
|
+
constructor(raw) {
|
|
14
|
+
super(raw);
|
|
15
|
+
}
|
|
16
|
+
isValid(raw) {
|
|
17
|
+
return /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(raw);
|
|
18
|
+
}
|
|
19
|
+
/** Everything before the `@`: `"ana@example.com"` -> `"ana"`. */
|
|
20
|
+
localPart() {
|
|
21
|
+
const value = this.toString();
|
|
22
|
+
return value.slice(0, value.indexOf('@'));
|
|
23
|
+
}
|
|
24
|
+
/** Everything after the `@`: `"ana@example.com"` -> `"example.com"`. */
|
|
25
|
+
domain() {
|
|
26
|
+
const value = this.toString();
|
|
27
|
+
return value.slice(value.indexOf('@') + 1);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Privacy-masked display form: the first character of the local part is
|
|
31
|
+
* kept, the rest of it is masked, and the domain is shown in full:
|
|
32
|
+
* `"ana@example.com"` -> `"a**@example.com"`. A one-character local part
|
|
33
|
+
* has nothing to mask, so it is shown as-is: `"j@example.com"`.
|
|
34
|
+
*/
|
|
35
|
+
redact() {
|
|
36
|
+
const local = this.localPart();
|
|
37
|
+
const masked = local.charAt(0) + '*'.repeat(Math.max(local.length - 1, 0));
|
|
38
|
+
return `${masked}@${this.domain()}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Email = Email;
|
|
42
|
+
//# sourceMappingURL=email.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.class.js","sourceRoot":"","sources":["../../src/global/email.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;;GAMG;AACH,MAAa,KAAM,SAAQ,sBAAW;IACpC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,OAAO,kDAAkD,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACtE,CAAC;IAED,iEAAiE;IAC1D,SAAS;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,wEAAwE;IACjE,MAAM;QACX,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,MAAM;QACX,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3E,OAAO,GAAG,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;IACtC,CAAC;CACF;AAhCD,sBAgCC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ValueObject } from '@ts-typed/compiler';
|
|
2
|
+
/**
|
|
3
|
+
* A Brazilian full name: at least a first name and a surname. There is no
|
|
4
|
+
* check digit for a name — `isValid` only confirms it looks like a plausible
|
|
5
|
+
* full name (at least two words, each made of letters — including accented
|
|
6
|
+
* Portuguese characters — apostrophes, or hyphens).
|
|
7
|
+
*/
|
|
8
|
+
export declare class FullName extends ValueObject {
|
|
9
|
+
constructor(raw: string);
|
|
10
|
+
protected isValid(raw: string): boolean;
|
|
11
|
+
/** The first word: `"Ana Maria Silva Santos"` -> `"Ana"`. */
|
|
12
|
+
firstName(): string;
|
|
13
|
+
/** Everything after the first word: `"Ana Maria Silva Santos"` -> `"Maria Silva Santos"`. */
|
|
14
|
+
lastName(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Every word reduced to its first letter plus an asterisk for each
|
|
17
|
+
* remaining character, so none of the name's content past the first
|
|
18
|
+
* letter of each word is shown: `"Ana Maria Silva Santos"` ->
|
|
19
|
+
* `"A** M**** S**** S*****"`.
|
|
20
|
+
*/
|
|
21
|
+
redact(): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=full-name.class.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"full-name.class.d.ts","sourceRoot":"","sources":["../../src/global/full-name.class.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;;;GAKG;AACH,qBAAa,QAAS,SAAQ,WAAW;gBACpB,GAAG,EAAE,MAAM;IAI9B,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAKvC,6DAA6D;IACtD,SAAS,IAAI,MAAM;IAI1B,6FAA6F;IACtF,QAAQ,IAAI,MAAM;IAIzB;;;;;OAKG;IACI,MAAM,IAAI,MAAM;CAMxB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FullName = void 0;
|
|
4
|
+
const compiler_1 = require("@ts-typed/compiler");
|
|
5
|
+
/**
|
|
6
|
+
* A Brazilian full name: at least a first name and a surname. There is no
|
|
7
|
+
* check digit for a name — `isValid` only confirms it looks like a plausible
|
|
8
|
+
* full name (at least two words, each made of letters — including accented
|
|
9
|
+
* Portuguese characters — apostrophes, or hyphens).
|
|
10
|
+
*/
|
|
11
|
+
class FullName extends compiler_1.ValueObject {
|
|
12
|
+
constructor(raw) {
|
|
13
|
+
super(raw);
|
|
14
|
+
}
|
|
15
|
+
isValid(raw) {
|
|
16
|
+
const words = normalize(raw).split(' ');
|
|
17
|
+
return words.length >= 2 && words.every((word) => /^[A-Za-zÀ-ÖØ-öø-ÿ'-]+$/.test(word));
|
|
18
|
+
}
|
|
19
|
+
/** The first word: `"Ana Maria Silva Santos"` -> `"Ana"`. */
|
|
20
|
+
firstName() {
|
|
21
|
+
return normalize(this.toString()).split(' ')[0];
|
|
22
|
+
}
|
|
23
|
+
/** Everything after the first word: `"Ana Maria Silva Santos"` -> `"Maria Silva Santos"`. */
|
|
24
|
+
lastName() {
|
|
25
|
+
return normalize(this.toString()).split(' ').slice(1).join(' ');
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Every word reduced to its first letter plus an asterisk for each
|
|
29
|
+
* remaining character, so none of the name's content past the first
|
|
30
|
+
* letter of each word is shown: `"Ana Maria Silva Santos"` ->
|
|
31
|
+
* `"A** M**** S**** S*****"`.
|
|
32
|
+
*/
|
|
33
|
+
redact() {
|
|
34
|
+
return normalize(this.toString())
|
|
35
|
+
.split(' ')
|
|
36
|
+
.map((word) => word.charAt(0) + '*'.repeat(word.length - 1))
|
|
37
|
+
.join(' ');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.FullName = FullName;
|
|
41
|
+
function normalize(raw) {
|
|
42
|
+
return raw.trim().replace(/\s+/g, ' ');
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=full-name.class.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"full-name.class.js","sourceRoot":"","sources":["../../src/global/full-name.class.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AAEjD;;;;;GAKG;AACH,MAAa,QAAS,SAAQ,sBAAW;IACvC,YAAmB,GAAW;QAC5B,KAAK,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAES,OAAO,CAAC,GAAW;QAC3B,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACzF,CAAC;IAED,6DAA6D;IACtD,SAAS;QACd,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,6FAA6F;IACtF,QAAQ;QACb,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACI,MAAM;QACX,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;aAC9B,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;aAC3D,IAAI,CAAC,GAAG,CAAC,CAAC;IACf,CAAC;CACF;AAhCD,4BAgCC;AAED,SAAS,SAAS,CAAC,GAAW;IAC5B,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/global/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreditCard = exports.Email = exports.FullName = void 0;
|
|
4
|
+
var full_name_class_1 = require("./full-name.class");
|
|
5
|
+
Object.defineProperty(exports, "FullName", { enumerable: true, get: function () { return full_name_class_1.FullName; } });
|
|
6
|
+
var email_class_1 = require("./email.class");
|
|
7
|
+
Object.defineProperty(exports, "Email", { enumerable: true, get: function () { return email_class_1.Email; } });
|
|
8
|
+
var credit_card_class_1 = require("./credit-card.class");
|
|
9
|
+
Object.defineProperty(exports, "CreditCard", { enumerable: true, get: function () { return credit_card_class_1.CreditCard; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/global/index.ts"],"names":[],"mappings":";;;AAAA,qDAA6C;AAApC,2GAAA,QAAQ,OAAA;AACjB,6CAAsC;AAA7B,oGAAA,KAAK,OAAA;AACd,yDAAiD;AAAxC,+GAAA,UAAU,OAAA"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,cAAc,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./br"), exports);
|
|
18
|
+
__exportStar(require("./global"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAqB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAqB;AACrB,2CAAyB"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-typed/validators",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"description": "Document/data validators built on @ts-typed/compiler's ValueObject
|
|
8
|
+
"description": "Document/data validators built on @ts-typed/compiler's ValueObject: locale-specific (Brazil) and global (Email, CreditCard, FullName) validators",
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"engines": {
|
|
11
11
|
"node": ">=22"
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
"require": "./dist/br/index.js",
|
|
24
24
|
"default": "./dist/br/index.js"
|
|
25
25
|
},
|
|
26
|
+
"./global": {
|
|
27
|
+
"types": "./dist/global/index.d.ts",
|
|
28
|
+
"require": "./dist/global/index.js",
|
|
29
|
+
"default": "./dist/global/index.js"
|
|
30
|
+
},
|
|
26
31
|
"./package.json": "./package.json"
|
|
27
32
|
},
|
|
28
33
|
"files": [
|
|
@@ -38,7 +43,7 @@
|
|
|
38
43
|
"test": "npm run build && node --test --test-concurrency=1"
|
|
39
44
|
},
|
|
40
45
|
"dependencies": {
|
|
41
|
-
"@ts-typed/compiler": "0.1.
|
|
46
|
+
"@ts-typed/compiler": "0.1.22"
|
|
42
47
|
},
|
|
43
48
|
"peerDependencies": {
|
|
44
49
|
"typescript": ">=5.9 <6"
|