@vtex/country-forms 1.0.1 → 1.2.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/CHANGELOG.md +45 -1
- package/README.md +2 -1
- package/dist/{BRA-PMVV6KOM.js → BRA-CWGYPPBD.js} +43 -27
- package/dist/BRA-CWGYPPBD.js.map +1 -0
- package/dist/{BRA-PCJDRSEF.mjs → BRA-JUHEOV7J.mjs} +3 -3
- package/dist/{BRA-PCJDRSEF.mjs.map → BRA-JUHEOV7J.mjs.map} +1 -1
- package/dist/{BRA-ZBZXE5II.mjs → BRA-R2DBJTZ2.mjs} +43 -27
- package/dist/BRA-R2DBJTZ2.mjs.map +1 -0
- package/dist/{BRA-WGCSNRCO.js → BRA-VIVRV7X7.js} +3 -3
- package/dist/{BRA-WGCSNRCO.js.map → BRA-VIVRV7X7.js.map} +1 -1
- package/dist/CAN-RDQPFPZU.mjs +127 -0
- package/dist/CAN-RDQPFPZU.mjs.map +1 -0
- package/dist/CAN-ZJQJFUW4.js +129 -0
- package/dist/CAN-ZJQJFUW4.js.map +1 -0
- package/dist/MEX-6CJCALY3.js +125 -0
- package/dist/MEX-6CJCALY3.js.map +1 -0
- package/dist/MEX-ZQL7ZS3G.mjs +123 -0
- package/dist/MEX-ZQL7ZS3G.mjs.map +1 -0
- package/dist/USA-2QW25XAI.mjs +128 -0
- package/dist/USA-2QW25XAI.mjs.map +1 -0
- package/dist/USA-MWP4SDGW.js +130 -0
- package/dist/USA-MWP4SDGW.js.map +1 -0
- package/dist/{bra-PZBWBUGB.js → bra-DQO5W7HB.js} +23 -31
- package/dist/bra-DQO5W7HB.js.map +1 -0
- package/dist/{bra-ZDFUVAXT.mjs → bra-MJUXI46I.mjs} +16 -27
- package/dist/bra-MJUXI46I.mjs.map +1 -0
- package/dist/can-3MOZIOGB.js +65 -0
- package/dist/can-3MOZIOGB.js.map +1 -0
- package/dist/can-DKTB2M6I.mjs +41 -0
- package/dist/can-DKTB2M6I.mjs.map +1 -0
- package/dist/can-LLWX4LC2.js +48 -0
- package/dist/can-LLWX4LC2.js.map +1 -0
- package/dist/can-OONXPDKH.mjs +59 -0
- package/dist/can-OONXPDKH.mjs.map +1 -0
- package/dist/chunk-B2XPLIJU.mjs +19 -0
- package/dist/chunk-B2XPLIJU.mjs.map +1 -0
- package/dist/{chunk-HKDTDE53.js → chunk-CFX5EF4R.js} +2 -2
- package/dist/{chunk-HKDTDE53.js.map → chunk-CFX5EF4R.js.map} +1 -1
- package/dist/{chunk-IVJED4TG.mjs → chunk-KWESVZKV.mjs} +2 -2
- package/dist/{chunk-IVJED4TG.mjs.map → chunk-KWESVZKV.mjs.map} +1 -1
- package/dist/chunk-ZQQPNXLP.js +21 -0
- package/dist/chunk-ZQQPNXLP.js.map +1 -0
- package/dist/common-E4IN3G46.mjs +4 -0
- package/dist/common-E4IN3G46.mjs.map +1 -0
- package/dist/common-LFDTUEMM.js +13 -0
- package/dist/common-LFDTUEMM.js.map +1 -0
- package/dist/{en-US-67K5REMQ.mjs → en-US-KHII5INO.mjs} +29 -14
- package/dist/en-US-KHII5INO.mjs.map +1 -0
- package/dist/{en-US-DXYSM6Q2.js → en-US-RCNO3BZC.js} +29 -14
- package/dist/en-US-RCNO3BZC.js.map +1 -0
- package/dist/{es-MX-UL5OL7HT.js → es-MX-IGOEW2P4.js} +28 -13
- package/dist/es-MX-IGOEW2P4.js.map +1 -0
- package/dist/{es-MX-2R6G2ZLS.mjs → es-MX-R24GRBU5.mjs} +28 -13
- package/dist/es-MX-R24GRBU5.mjs.map +1 -0
- package/dist/{fr-FR-GGR2M6TJ.mjs → fr-FR-N4WJAN23.mjs} +29 -14
- package/dist/fr-FR-N4WJAN23.mjs.map +1 -0
- package/dist/{fr-FR-LWA6B3MW.js → fr-FR-WZBI6O4O.js} +29 -14
- package/dist/fr-FR-WZBI6O4O.js.map +1 -0
- package/dist/index.d.mts +227 -11
- package/dist/index.d.ts +227 -11
- package/dist/index.js +127 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -44
- package/dist/index.mjs.map +1 -1
- package/dist/mex-AMEX6IHY.mjs +108 -0
- package/dist/mex-AMEX6IHY.mjs.map +1 -0
- package/dist/mex-DYWVMWB6.js +38 -0
- package/dist/mex-DYWVMWB6.js.map +1 -0
- package/dist/mex-VX3Y5I6I.mjs +33 -0
- package/dist/mex-VX3Y5I6I.mjs.map +1 -0
- package/dist/mex-Y56WV2L7.js +114 -0
- package/dist/mex-Y56WV2L7.js.map +1 -0
- package/dist/{pt-BR-KH6RW3HM.mjs → pt-BR-PIBP3JHL.mjs} +31 -13
- package/dist/pt-BR-PIBP3JHL.mjs.map +1 -0
- package/dist/{pt-BR-WVTTIEAH.js → pt-BR-ZDM55ITO.js} +31 -13
- package/dist/pt-BR-ZDM55ITO.js.map +1 -0
- package/dist/usa-AC7YPVS3.mjs +52 -0
- package/dist/usa-AC7YPVS3.mjs.map +1 -0
- package/dist/usa-B6NCCTF6.js +61 -0
- package/dist/usa-B6NCCTF6.js.map +1 -0
- package/dist/usa-LOOP7MRM.mjs +55 -0
- package/dist/usa-LOOP7MRM.mjs.map +1 -0
- package/dist/usa-OQ44AFEI.js +61 -0
- package/dist/usa-OQ44AFEI.js.map +1 -0
- package/package.json +1 -1
- package/dist/BRA-PMVV6KOM.js.map +0 -1
- package/dist/BRA-ZBZXE5II.mjs.map +0 -1
- package/dist/bra-PZBWBUGB.js.map +0 -1
- package/dist/bra-ZDFUVAXT.mjs.map +0 -1
- package/dist/can-7TMYDEJF.mjs +0 -17
- package/dist/can-7TMYDEJF.mjs.map +0 -1
- package/dist/can-B5ME2ZFN.js +0 -20
- package/dist/can-B5ME2ZFN.js.map +0 -1
- package/dist/can-BUKTOPLB.js +0 -21
- package/dist/can-BUKTOPLB.js.map +0 -1
- package/dist/can-SHRLPUU5.mjs +0 -19
- package/dist/can-SHRLPUU5.mjs.map +0 -1
- package/dist/en-US-67K5REMQ.mjs.map +0 -1
- package/dist/en-US-DXYSM6Q2.js.map +0 -1
- package/dist/es-MX-2R6G2ZLS.mjs.map +0 -1
- package/dist/es-MX-UL5OL7HT.js.map +0 -1
- package/dist/fr-FR-GGR2M6TJ.mjs.map +0 -1
- package/dist/fr-FR-LWA6B3MW.js.map +0 -1
- package/dist/mex-I3LUVYVC.mjs +0 -19
- package/dist/mex-I3LUVYVC.mjs.map +0 -1
- package/dist/mex-QT4CJZDD.js +0 -21
- package/dist/mex-QT4CJZDD.js.map +0 -1
- package/dist/pt-BR-KH6RW3HM.mjs.map +0 -1
- package/dist/pt-BR-WVTTIEAH.js.map +0 -1
- package/dist/usa-6PGU5UHS.mjs +0 -18
- package/dist/usa-6PGU5UHS.mjs.map +0 -1
- package/dist/usa-I7DK2CTL.mjs +0 -18
- package/dist/usa-I7DK2CTL.mjs.map +0 -1
- package/dist/usa-LFLDXKPA.js +0 -20
- package/dist/usa-LFLDXKPA.js.map +0 -1
- package/dist/usa-LXT6WW64.js +0 -21
- package/dist/usa-LXT6WW64.js.map +0 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/schemas/personal-data/USA.ts
|
|
4
|
+
var schema = {
|
|
5
|
+
id: "personal-data-USA",
|
|
6
|
+
country: "USA",
|
|
7
|
+
formType: "personal-data",
|
|
8
|
+
fields: [
|
|
9
|
+
{
|
|
10
|
+
name: "personType",
|
|
11
|
+
type: "radio-group",
|
|
12
|
+
label: "country-forms.personal-data.personType.label",
|
|
13
|
+
required: true,
|
|
14
|
+
options: [
|
|
15
|
+
{ value: "individual", displayValue: "country-forms.personal-data.personType.individual" },
|
|
16
|
+
{ value: "business", displayValue: "country-forms.personal-data.personType.business" }
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: "firstName",
|
|
21
|
+
type: "text",
|
|
22
|
+
label: "country-forms.personal-data.firstName.label",
|
|
23
|
+
required: true,
|
|
24
|
+
inputMode: "text",
|
|
25
|
+
maxLength: 200,
|
|
26
|
+
dependsOn: "personType",
|
|
27
|
+
conditionalLabel: {
|
|
28
|
+
individual: "country-forms.personal-data.firstName.label.individual",
|
|
29
|
+
business: "country-forms.personal-data.firstName.label.business"
|
|
30
|
+
},
|
|
31
|
+
validation: {
|
|
32
|
+
maxLength: { value: 200, message: "country-forms.validation.maxLength" }
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "lastName",
|
|
37
|
+
type: "text",
|
|
38
|
+
label: "country-forms.personal-data.lastName.label",
|
|
39
|
+
required: true,
|
|
40
|
+
inputMode: "text",
|
|
41
|
+
maxLength: 200,
|
|
42
|
+
conditionalVisibility: {
|
|
43
|
+
field: "personType",
|
|
44
|
+
operator: "equals",
|
|
45
|
+
value: "individual"
|
|
46
|
+
},
|
|
47
|
+
validation: {
|
|
48
|
+
maxLength: { value: 200, message: "country-forms.validation.maxLength" }
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "email",
|
|
53
|
+
type: "email",
|
|
54
|
+
label: "country-forms.personal-data.email.label",
|
|
55
|
+
required: true,
|
|
56
|
+
inputMode: "email",
|
|
57
|
+
validation: {
|
|
58
|
+
customValidator: "validateEmail"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "phone",
|
|
63
|
+
type: "text",
|
|
64
|
+
// 17 chars accommodates the longest accepted raw input, "+1 (201) 555-0123",
|
|
65
|
+
// so pasted country-code forms are not truncated before the mask normalizes
|
|
66
|
+
// them to the 14-char display "(201) 555-0123".
|
|
67
|
+
maxLength: 17,
|
|
68
|
+
label: "country-forms.personal-data.phone.label",
|
|
69
|
+
placeholder: "country-forms.personal-data.phone.placeholder.USA",
|
|
70
|
+
required: true,
|
|
71
|
+
inputMode: "tel",
|
|
72
|
+
formatRef: "formatPhoneUSA",
|
|
73
|
+
unformatRef: "unformatPhoneUSA",
|
|
74
|
+
validation: {
|
|
75
|
+
customValidator: "validatePhoneUSA"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "document",
|
|
80
|
+
type: "text",
|
|
81
|
+
label: "country-forms.personal-data.document.label",
|
|
82
|
+
required: false,
|
|
83
|
+
inputMode: "numeric",
|
|
84
|
+
// 11 = formatted SSN length ("123-45-6789"); EIN (10) fits within it.
|
|
85
|
+
maxLength: 11,
|
|
86
|
+
dependsOn: "personType",
|
|
87
|
+
conditionalLabel: {
|
|
88
|
+
individual: "country-forms.personal-data.ssn.label",
|
|
89
|
+
business: "country-forms.personal-data.ein.label"
|
|
90
|
+
},
|
|
91
|
+
conditionalPlaceholder: {
|
|
92
|
+
individual: "country-forms.personal-data.ssn.placeholder",
|
|
93
|
+
business: "country-forms.personal-data.ein.placeholder"
|
|
94
|
+
},
|
|
95
|
+
conditionalValidator: {
|
|
96
|
+
individual: "validateSSN",
|
|
97
|
+
business: "validateEIN"
|
|
98
|
+
},
|
|
99
|
+
conditionalFormatRef: {
|
|
100
|
+
individual: "formatSSN",
|
|
101
|
+
business: "formatEIN"
|
|
102
|
+
},
|
|
103
|
+
conditionalUnformatRef: {
|
|
104
|
+
individual: "unformatSSN",
|
|
105
|
+
business: "unformatEIN"
|
|
106
|
+
},
|
|
107
|
+
conditionalVisibility: {
|
|
108
|
+
field: "personType",
|
|
109
|
+
operator: "includes",
|
|
110
|
+
value: ["individual", "business"]
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "documentType",
|
|
115
|
+
type: "text",
|
|
116
|
+
label: "country-forms.personal-data.documentType.label",
|
|
117
|
+
required: false,
|
|
118
|
+
derivedFrom: "personType",
|
|
119
|
+
derivedValue: {
|
|
120
|
+
individual: "ssn",
|
|
121
|
+
business: "ein"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
]
|
|
125
|
+
};
|
|
126
|
+
var USA_default = schema;
|
|
127
|
+
|
|
128
|
+
module.exports = USA_default;
|
|
129
|
+
//# sourceMappingURL=USA-MWP4SDGW.js.map
|
|
130
|
+
//# sourceMappingURL=USA-MWP4SDGW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/schemas/personal-data/USA.ts"],"names":[],"mappings":";;;AAqCA,IAAM,MAAA,GAAS;AAAA,EACb,EAAA,EAAI,mBAAA;AAAA,EACJ,OAAA,EAAS,KAAA;AAAA,EACT,QAAA,EAAU,eAAA;AAAA,EACV,MAAA,EAAQ;AAAA,IACN;AAAA,MACE,IAAA,EAAM,YAAA;AAAA,MACN,IAAA,EAAM,aAAA;AAAA,MACN,KAAA,EAAO,8CAAA;AAAA,MACP,QAAA,EAAU,IAAA;AAAA,MACV,OAAA,EAAS;AAAA,QACP,EAAE,KAAA,EAAO,YAAA,EAAc,YAAA,EAAc,mDAAA,EAAoD;AAAA,QACzF,EAAE,KAAA,EAAO,UAAA,EAAY,YAAA,EAAc,iDAAA;AAAkD;AACvF,KACF;AAAA,IACA;AAAA,MACE,IAAA,EAAM,WAAA;AAAA,MACN,IAAA,EAAM,MAAA;AAAA,MACN,KAAA,EAAO,6CAAA;AAAA,MACP,QAAA,EAAU,IAAA;AAAA,MACV,SAAA,EAAW,MAAA;AAAA,MACX,SAAA,EAAW,GAAA;AAAA,MACX,SAAA,EAAW,YAAA;AAAA,MACX,gBAAA,EAAkB;AAAA,QAChB,UAAA,EAAY,wDAAA;AAAA,QACZ,QAAA,EAAU;AAAA,OACZ;AAAA,MACA,UAAA,EAAY;AAAA,QACV,SAAA,EAAW,EAAE,KAAA,EAAO,GAAA,EAAK,SAAS,oCAAA;AAAqC;AACzE,KACF;AAAA,IACA;AAAA,MACE,IAAA,EAAM,UAAA;AAAA,MACN,IAAA,EAAM,MAAA;AAAA,MACN,KAAA,EAAO,4CAAA;AAAA,MACP,QAAA,EAAU,IAAA;AAAA,MACV,SAAA,EAAW,MAAA;AAAA,MACX,SAAA,EAAW,GAAA;AAAA,MACX,qBAAA,EAAuB;AAAA,Q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;AAAA,QACZ,QAAA,EAAU;AAAA,OACZ;AAAA,MACA,oBAAA,EAAsB;AAAA,QACpB,UAAA,EAAY,WAAA;AAAA,QACZ,QAAA,EAAU;AAAA,OACZ;AAAA,MACA,sBAAA,EAAwB;AAAA,QACtB,UAAA,EAAY,aAAA;AAAA,QACZ,QAAA,EAAU;AAAA,OACZ;AAAA,MACA,qBAAA,EAAuB;AAAA,QACrB,KAAA,EAAO,YAAA;AAAA,QACP,QAAA,EAAU,UAAA;AAAA,QACV,KAAA,EAAO,CAAC,YAAA,EAAc,UAAU;AAAA;AAClC,KACF;AAAA,IACA;AAAA,MACE,IAAA,EAAM,cAAA;AAAA,MACN,IAAA,EAAM,MAAA;AAAA,MACN,KAAA,EAAO,gDAAA;AAAA,MACP,QAAA,EAAU,KAAA;AAAA,MACV,WAAA,EAAa,YAAA;AAAA,MACb,YAAA,EAAc;AAAA,QACZ,UAAA,EAAY,KAAA;AAAA,QACZ,QAAA,EAAU;AAAA;AACZ;AACF;AAEJ,CAAA;AAEA,IAAO,WAAA,GAAQ","file":"USA-MWP4SDGW.js","sourcesContent":["/**\n * Personal-data schema for the United States (USA).\n *\n * Field order: personType → firstName → lastName → email → phone → document → documentType\n *\n * `personType` drives conditional visibility:\n * - `\"individual\"` → `lastName`, `document` (as SSN) visible\n * - `\"business\"` → `document` (as EIN) visible; `lastName` hidden\n *\n * `firstName` uses `conditionalLabel` keyed by `personType`:\n * - `\"individual\"` → \"First name\"\n * - `\"business\"` → \"Company name\"\n *\n * `lastName` is only visible for individuals (hidden for businesses).\n *\n * ## Document model (API-aligned)\n *\n * The tax/identity document is collected through a single `document` field plus a\n * derived `documentType` field, mirroring the `{ document, documentType }` shape\n * used by VTEX profile APIs. `document` validates/masks conditionally on\n * `personType` (SSN for individuals, EIN for businesses); `documentType` is\n * data-only and follows `personType` automatically (`ssn` / `ein`).\n *\n * `document` is **optional** (`required: false`): many US flows (e.g. checkout)\n * do not collect a tax/identity document. It is still format-validated *when\n * filled* (an invalid SSN/EIN is rejected; an empty one is accepted). Consumers\n * that need it mandatory can override `required` in their own schema layer.\n *\n * Email: `jane.doe@example.com` — validated by `validateEmail` (shared).\n * Phone: `(201) 555-0123` — validated by `validatePhoneUSA`, masked by `formatPhoneUSA`/`unformatPhoneUSA`.\n * Document (individual): `123-45-6789` — `validateSSN`, masked by `formatSSN`/`unformatSSN`.\n * Document (business): `12-3456789` — `validateEIN`, masked by `formatEIN`/`unformatEIN`.\n *\n * Required rule modules: `rules/validators/common`, `rules/validators/usa`, `rules/masks/usa`\n */\nimport type { FormSchema } from '../../types'\n\nconst schema = {\n id: 'personal-data-USA',\n country: 'USA',\n formType: 'personal-data',\n fields: [\n {\n name: 'personType',\n type: 'radio-group',\n label: 'country-forms.personal-data.personType.label',\n required: true,\n options: [\n { value: 'individual', displayValue: 'country-forms.personal-data.personType.individual' },\n { value: 'business', displayValue: 'country-forms.personal-data.personType.business' },\n ],\n },\n {\n name: 'firstName',\n type: 'text',\n label: 'country-forms.personal-data.firstName.label',\n required: true,\n inputMode: 'text',\n maxLength: 200,\n dependsOn: 'personType',\n conditionalLabel: {\n individual: 'country-forms.personal-data.firstName.label.individual',\n business: 'country-forms.personal-data.firstName.label.business',\n },\n validation: {\n maxLength: { value: 200, message: 'country-forms.validation.maxLength' },\n },\n },\n {\n name: 'lastName',\n type: 'text',\n label: 'country-forms.personal-data.lastName.label',\n required: true,\n inputMode: 'text',\n maxLength: 200,\n conditionalVisibility: {\n field: 'personType',\n operator: 'equals',\n value: 'individual',\n },\n validation: {\n maxLength: { value: 200, message: 'country-forms.validation.maxLength' },\n },\n },\n {\n name: 'email',\n type: 'email',\n label: 'country-forms.personal-data.email.label',\n required: true,\n inputMode: 'email',\n validation: {\n customValidator: 'validateEmail',\n },\n },\n {\n name: 'phone',\n type: 'text',\n // 17 chars accommodates the longest accepted raw input, \"+1 (201) 555-0123\",\n // so pasted country-code forms are not truncated before the mask normalizes\n // them to the 14-char display \"(201) 555-0123\".\n maxLength: 17,\n label: 'country-forms.personal-data.phone.label',\n placeholder: 'country-forms.personal-data.phone.placeholder.USA',\n required: true,\n inputMode: 'tel',\n formatRef: 'formatPhoneUSA',\n unformatRef: 'unformatPhoneUSA',\n validation: {\n customValidator: 'validatePhoneUSA',\n },\n },\n {\n name: 'document',\n type: 'text',\n label: 'country-forms.personal-data.document.label',\n required: false,\n inputMode: 'numeric',\n // 11 = formatted SSN length (\"123-45-6789\"); EIN (10) fits within it.\n maxLength: 11,\n dependsOn: 'personType',\n conditionalLabel: {\n individual: 'country-forms.personal-data.ssn.label',\n business: 'country-forms.personal-data.ein.label',\n },\n conditionalPlaceholder: {\n individual: 'country-forms.personal-data.ssn.placeholder',\n business: 'country-forms.personal-data.ein.placeholder',\n },\n conditionalValidator: {\n individual: 'validateSSN',\n business: 'validateEIN',\n },\n conditionalFormatRef: {\n individual: 'formatSSN',\n business: 'formatEIN',\n },\n conditionalUnformatRef: {\n individual: 'unformatSSN',\n business: 'unformatEIN',\n },\n conditionalVisibility: {\n field: 'personType',\n operator: 'includes',\n value: ['individual', 'business'],\n },\n },\n {\n name: 'documentType',\n type: 'text',\n label: 'country-forms.personal-data.documentType.label',\n required: false,\n derivedFrom: 'personType',\n derivedValue: {\n individual: 'ssn',\n business: 'ein',\n },\n },\n ],\n} satisfies FormSchema\n\nexport default schema\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZQQPNXLP_js = require('./chunk-ZQQPNXLP.js');
|
|
4
|
+
var chunkCFX5EF4R_js = require('./chunk-CFX5EF4R.js');
|
|
4
5
|
|
|
5
6
|
// src/rules/validators/bra.ts
|
|
6
7
|
function validateCEP(value) {
|
|
@@ -9,43 +10,32 @@ function validateCEP(value) {
|
|
|
9
10
|
if (new Set(digits).size === 1) return "country-forms.validation.postalCode.BRA";
|
|
10
11
|
return true;
|
|
11
12
|
}
|
|
12
|
-
function validateEmail(value) {
|
|
13
|
-
const email = value.trim();
|
|
14
|
-
if (!email) {
|
|
15
|
-
return "country-forms.validation.email";
|
|
16
|
-
}
|
|
17
|
-
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)+$/;
|
|
18
|
-
if (!emailRegex.test(email)) {
|
|
19
|
-
return "country-forms.validation.email";
|
|
20
|
-
}
|
|
21
|
-
return true;
|
|
22
|
-
}
|
|
23
13
|
function validatePhoneBRA(value) {
|
|
24
14
|
const phoneRegex = /^(?:(?:(?:\+|)55)|)(?:0|)(?:11|12|13|14|15|16|17|18|19|21|22|24|27|28|31|32|33|34|35|36|37|38|41|42|43|44|45|46|47|48|49|51|52|53|54|55|61|62|63|64|65|66|67|68|69|71|72|73|74|75|77|78|79|81|82|83|84|85|86|87|88|89|91|92|93|94|95|96|97|98|99)(?:9\d{8}|[1-8]\d{7})$/;
|
|
25
15
|
const phone = value.replace(/\D/g, "");
|
|
26
16
|
if (!phoneRegex.test(phone)) {
|
|
27
|
-
return "country-forms.validation.
|
|
17
|
+
return "country-forms.validation.invalid";
|
|
28
18
|
}
|
|
29
19
|
return true;
|
|
30
20
|
}
|
|
31
21
|
function validateCPF(value) {
|
|
32
22
|
const digits = value.replace(/\D/g, "");
|
|
33
|
-
if (digits.length !== 11) return "country-forms.validation.
|
|
34
|
-
if (new Set(digits).size === 1) return "country-forms.validation.
|
|
23
|
+
if (digits.length !== 11) return "country-forms.validation.invalid";
|
|
24
|
+
if (new Set(digits).size === 1) return "country-forms.validation.invalid";
|
|
35
25
|
let sum = 0;
|
|
36
26
|
for (let i = 0; i < 9; i++) {
|
|
37
27
|
sum += Number(digits[i]) * (10 - i);
|
|
38
28
|
}
|
|
39
29
|
let remainder = sum * 10 % 11;
|
|
40
30
|
if (remainder === 10) remainder = 0;
|
|
41
|
-
if (remainder !== Number(digits[9])) return "country-forms.validation.
|
|
31
|
+
if (remainder !== Number(digits[9])) return "country-forms.validation.invalid";
|
|
42
32
|
sum = 0;
|
|
43
33
|
for (let i = 0; i < 10; i++) {
|
|
44
34
|
sum += Number(digits[i]) * (11 - i);
|
|
45
35
|
}
|
|
46
36
|
remainder = sum * 10 % 11;
|
|
47
37
|
if (remainder === 10) remainder = 0;
|
|
48
|
-
if (remainder !== Number(digits[10])) return "country-forms.validation.
|
|
38
|
+
if (remainder !== Number(digits[10])) return "country-forms.validation.invalid";
|
|
49
39
|
return true;
|
|
50
40
|
}
|
|
51
41
|
var CNPJ_TOTAL_LENGTH = 14;
|
|
@@ -67,30 +57,32 @@ function calculateCnpjCheckDigit(prefix) {
|
|
|
67
57
|
return remainder < 2 ? 0 : CNPJ_MODULUS - remainder;
|
|
68
58
|
}
|
|
69
59
|
function validateCNPJ(value) {
|
|
70
|
-
if (!value || !value.trim()) return "country-forms.validation.
|
|
60
|
+
if (!value || !value.trim()) return "country-forms.validation.invalid";
|
|
71
61
|
const cleaned = value.trim().toUpperCase().replace(CNPJ_CLEAN_REGEX, "");
|
|
72
|
-
if (cleaned.length !== CNPJ_TOTAL_LENGTH) return "country-forms.validation.
|
|
73
|
-
if (!CNPJ_FORMAT_REGEX.test(cleaned)) return "country-forms.validation.
|
|
74
|
-
if (CNPJ_ALL_ZEROS_REGEX.test(cleaned)) return "country-forms.validation.
|
|
62
|
+
if (cleaned.length !== CNPJ_TOTAL_LENGTH) return "country-forms.validation.invalid";
|
|
63
|
+
if (!CNPJ_FORMAT_REGEX.test(cleaned)) return "country-forms.validation.invalid";
|
|
64
|
+
if (CNPJ_ALL_ZEROS_REGEX.test(cleaned)) return "country-forms.validation.invalid";
|
|
75
65
|
const base = cleaned.slice(0, CNPJ_BASE_LENGTH);
|
|
76
66
|
const providedCheck1 = Number(cleaned[CNPJ_BASE_LENGTH]);
|
|
77
67
|
const providedCheck2 = Number(cleaned[CNPJ_BASE_LENGTH + 1]);
|
|
78
68
|
const expectedCheck1 = calculateCnpjCheckDigit(base);
|
|
79
|
-
if (providedCheck1 !== expectedCheck1) return "country-forms.validation.
|
|
69
|
+
if (providedCheck1 !== expectedCheck1) return "country-forms.validation.invalid";
|
|
80
70
|
const expectedCheck2 = calculateCnpjCheckDigit(base + expectedCheck1);
|
|
81
|
-
if (providedCheck2 !== expectedCheck2) return "country-forms.validation.
|
|
71
|
+
if (providedCheck2 !== expectedCheck2) return "country-forms.validation.invalid";
|
|
82
72
|
return true;
|
|
83
73
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
chunkHKDTDE53_js.registerValidator("validateCNPJ", validateCNPJ);
|
|
74
|
+
chunkCFX5EF4R_js.registerValidator("validateCEP", validateCEP);
|
|
75
|
+
chunkCFX5EF4R_js.registerValidator("validatePhoneBRA", validatePhoneBRA);
|
|
76
|
+
chunkCFX5EF4R_js.registerValidator("validateCPF", validateCPF);
|
|
77
|
+
chunkCFX5EF4R_js.registerValidator("validateCNPJ", validateCNPJ);
|
|
89
78
|
|
|
79
|
+
Object.defineProperty(exports, "validateEmail", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () { return chunkZQQPNXLP_js.validateEmail; }
|
|
82
|
+
});
|
|
90
83
|
exports.validateCEP = validateCEP;
|
|
91
84
|
exports.validateCNPJ = validateCNPJ;
|
|
92
85
|
exports.validateCPF = validateCPF;
|
|
93
|
-
exports.validateEmail = validateEmail;
|
|
94
86
|
exports.validatePhoneBRA = validatePhoneBRA;
|
|
95
|
-
//# sourceMappingURL=bra-
|
|
96
|
-
//# sourceMappingURL=bra-
|
|
87
|
+
//# sourceMappingURL=bra-DQO5W7HB.js.map
|
|
88
|
+
//# sourceMappingURL=bra-DQO5W7HB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/validators/bra.ts"],"names":["registerValidator"],"mappings":";;;;;;AAmCO,SAAS,YAAY,KAAA,EAAiC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AAW,CAAA;AAC5CA,kCAAA,CAAkB,gBAAgB,YAAY,CAAA","file":"bra-DQO5W7HB.js","sourcesContent":["/**\n * @module rules/validators/bra\n *\n * Synchronous validators for Brazilian address and personal-data fields.\n * Importing this module registers all validators in the shared registry.\n *\n * Registered refs:\n * - `\"validateCEP\"` — Brazilian postal code format\n * - `\"validatePhoneBRA\"` — Brazilian landline and mobile phone numbers\n * - `\"validateCPF\"` — Brazilian individual taxpayer ID (CPF) with check digits\n * - `\"validateCNPJ\"` — Brazilian company taxpayer ID (CNPJ), numeric or alphanumeric (SERPRO 2024+)\n *\n * The country-agnostic `\"validateEmail\"` validator lives in\n * `rules/validators/common` and is re-exported here for backward compatibility.\n */\n\nimport { registerValidator } from './index'\n\n// Re-exported for convenience; the shared email validator is registered by the\n// common module (importing this file evaluates `./common`, registering it too).\nexport { validateEmail } from './common'\n\n// ── CEP ───────────────────────────────────────────────────────────────────────\n\n/**\n * Validates a Brazilian CEP (Código de Endereçamento Postal).\n *\n * Accepts both masked (\"01310-100\") and unmasked (\"01310100\") forms.\n * Rules:\n * - Must contain exactly 8 digits after stripping non-digits.\n * - All identical digits are invalid (e.g. `\"00000000\"`, `\"11111111\"`).\n *\n * @param value - The CEP string to validate (with or without mask)\n * @returns `true` if valid, or an i18n error key string when invalid\n */\nexport function validateCEP(value: string): boolean | string {\n const digits = value.replace(/\\D/g, '')\n\n // Must contain exactly 8 digits\n if (digits.length !== 8) return 'country-forms.validation.postalCode.BRA'\n // Must not be all the same digit\n if (new Set(digits).size === 1) return 'country-forms.validation.postalCode.BRA'\n\n return true\n}\n\n// ── Phone ──────────────────────────────────────────────────────────────────────\n\n/**\n * Validates a Brazilian phone number.\n *\n * Accepts masked (`\"(11) 99999-9999\"`) and unmasked (`\"11999999999\"`) forms,\n * as well as numbers prefixed with the country code `+55` or trunk prefix `0`.\n * Non-digit characters are stripped before validation.\n *\n * Rules:\n * - Area code (DDD) must be a valid 2-digit Brazilian DDD (11-99, with gaps).\n * - Mobile numbers: 9 + 8 digits (total 11 digits after DDD).\n * - Landline numbers: [1-8] + 7 digits (total 10 digits after DDD).\n *\n * @param value - Phone string to validate (with or without mask, country code, or trunk prefix)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validatePhoneBRA(value: string): boolean | string {\n const phoneRegex = /^(?:(?:(?:\\+|)55)|)(?:0|)(?:11|12|13|14|15|16|17|18|19|21|22|24|27|28|31|32|33|34|35|36|37|38|41|42|43|44|45|46|47|48|49|51|52|53|54|55|61|62|63|64|65|66|67|68|69|71|72|73|74|75|77|78|79|81|82|83|84|85|86|87|88|89|91|92|93|94|95|96|97|98|99)(?:9\\d{8}|[1-8]\\d{7})$/\n const phone = value.replace(/\\D/g, '')\n if (!phoneRegex.test(phone)) {\n return 'country-forms.validation.invalid'\n }\n return true\n}\n\n// ── CPF ───────────────────────────────────────────────────────────────────────\n\n/**\n * Validates a Brazilian CPF (Cadastro de Pessoas Físicas).\n *\n * Accepts masked (`\"123.456.789-09\"`) and unmasked (`\"12345678909\"`) forms.\n * Rules:\n * - Must contain exactly 11 digits after stripping non-digits.\n * - All identical digits are invalid (e.g. `\"000.000.000-00\"`).\n * - Check digits (positions 10 and 11) must satisfy the Receita Federal algorithm.\n *\n * @param value - CPF string to validate (with or without mask)\n * @returns `true` when valid, or an i18n error key string when invalid\n * @see https://www.macoratti.net/alg_cpf.htm\n */\nexport function validateCPF(value: string): boolean | string {\n const digits = value.replace(/\\D/g, '')\n\n if (digits.length !== 11) return 'country-forms.validation.invalid'\n if (new Set(digits).size === 1) return 'country-forms.validation.invalid'\n\n let sum = 0\n for (let i = 0; i < 9; i++) {\n sum += Number(digits[i]) * (10 - i)\n }\n let remainder = (sum * 10) % 11\n if (remainder === 10) remainder = 0\n if (remainder !== Number(digits[9])) return 'country-forms.validation.invalid'\n\n sum = 0\n for (let i = 0; i < 10; i++) {\n sum += Number(digits[i]) * (11 - i)\n }\n remainder = (sum * 10) % 11\n if (remainder === 10) remainder = 0\n if (remainder !== Number(digits[10])) return 'country-forms.validation.invalid'\n\n return true\n}\n\n// ── CNPJ ──────────────────────────────────────────────────────────────────────\n\nconst CNPJ_TOTAL_LENGTH = 14\nconst CNPJ_BASE_LENGTH = 12\nconst CNPJ_MODULUS = 11\nconst CNPJ_BASE_CHAR_CODE = '0'.charCodeAt(0)\n\n// Shared 13-element weight table. The first check digit uses the last 12 weights\n// (over the 12-character base); the second check digit uses all 13 weights\n// (over base + first check digit). This mirrors the SERPRO reference algorithm.\nconst CNPJ_WEIGHTS = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] as const\n\nconst CNPJ_CLEAN_REGEX = /[./\\-\\s]/g\nconst CNPJ_FORMAT_REGEX = /^[A-Z0-9]{12}[0-9]{2}$/\nconst CNPJ_ALL_ZEROS_REGEX = /^0+$/\n\n/**\n * Computes a CNPJ check digit for the given alphanumeric prefix using the\n * SERPRO algorithm. Each character contributes `charCode - '0'` to the\n * weighted sum: digits `0-9` map to `0-9`, letters `A-Z` map to `17-42`.\n *\n * @internal\n */\nfunction calculateCnpjCheckDigit(prefix: string): number {\n const offset = CNPJ_WEIGHTS.length - prefix.length\n let sum = 0\n for (let i = 0; i < prefix.length; i++) {\n const charValue = prefix.charCodeAt(i) - CNPJ_BASE_CHAR_CODE\n sum += charValue * (CNPJ_WEIGHTS[offset + i] as number)\n }\n const remainder = sum % CNPJ_MODULUS\n return remainder < 2 ? 0 : CNPJ_MODULUS - remainder\n}\n\n/**\n * Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica).\n *\n * Supports both the legacy numeric format and the new alphanumeric format\n * announced by the Receita Federal (Instrução Normativa RFB 2.229/2024,\n * effective for new registrations from July 2026 onward). Numeric CNPJs\n * already issued remain valid — they are a strict subset of the new format.\n *\n * Accepted inputs:\n * - Masked numeric: `\"11.222.333/0001-81\"`\n * - Unmasked numeric: `\"11222333000181\"`\n * - Masked alphanumeric: `\"12.ABC.345/01DE-35\"`\n * - Unmasked alphanumeric: `\"12ABC34501DE35\"`\n *\n * Lowercase letters are accepted and normalized to uppercase.\n *\n * Rules:\n * - After stripping separators (`.`, `/`, `-`, whitespace), the string must be\n * exactly 14 characters long.\n * - The first 12 characters (base) must be alphanumeric uppercase (`A-Z`, `0-9`).\n * - The last 2 characters (check digits) must be numeric (`0-9`).\n * - All-zeros input is invalid (e.g. `\"00000000000000\"`).\n * - Check digits must satisfy the SERPRO algorithm: each character contributes\n * `charCode - '0'.charCode` to a weighted sum modulo 11.\n *\n * @param value - CNPJ string to validate (with or without mask, numeric or alphanumeric)\n * @returns `true` when valid, or an i18n error key string when invalid\n * @see https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico\n */\nexport function validateCNPJ(value: string): boolean | string {\n if (!value || !value.trim()) return 'country-forms.validation.invalid'\n\n const cleaned = value.trim().toUpperCase().replace(CNPJ_CLEAN_REGEX, '')\n\n if (cleaned.length !== CNPJ_TOTAL_LENGTH) return 'country-forms.validation.invalid'\n if (!CNPJ_FORMAT_REGEX.test(cleaned)) return 'country-forms.validation.invalid'\n if (CNPJ_ALL_ZEROS_REGEX.test(cleaned)) return 'country-forms.validation.invalid'\n\n const base = cleaned.slice(0, CNPJ_BASE_LENGTH)\n const providedCheck1 = Number(cleaned[CNPJ_BASE_LENGTH])\n const providedCheck2 = Number(cleaned[CNPJ_BASE_LENGTH + 1])\n\n const expectedCheck1 = calculateCnpjCheckDigit(base)\n if (providedCheck1 !== expectedCheck1) return 'country-forms.validation.invalid'\n\n const expectedCheck2 = calculateCnpjCheckDigit(base + expectedCheck1)\n if (providedCheck2 !== expectedCheck2) return 'country-forms.validation.invalid'\n\n return true\n}\n\nregisterValidator('validateCEP', validateCEP)\nregisterValidator('validatePhoneBRA', validatePhoneBRA)\nregisterValidator('validateCPF', validateCPF)\nregisterValidator('validateCNPJ', validateCNPJ)\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
export { validateEmail } from './chunk-B2XPLIJU.mjs';
|
|
2
|
+
import { registerValidator } from './chunk-KWESVZKV.mjs';
|
|
2
3
|
|
|
3
4
|
// src/rules/validators/bra.ts
|
|
4
5
|
function validateCEP(value) {
|
|
@@ -7,43 +8,32 @@ function validateCEP(value) {
|
|
|
7
8
|
if (new Set(digits).size === 1) return "country-forms.validation.postalCode.BRA";
|
|
8
9
|
return true;
|
|
9
10
|
}
|
|
10
|
-
function validateEmail(value) {
|
|
11
|
-
const email = value.trim();
|
|
12
|
-
if (!email) {
|
|
13
|
-
return "country-forms.validation.email";
|
|
14
|
-
}
|
|
15
|
-
const emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)+$/;
|
|
16
|
-
if (!emailRegex.test(email)) {
|
|
17
|
-
return "country-forms.validation.email";
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
11
|
function validatePhoneBRA(value) {
|
|
22
12
|
const phoneRegex = /^(?:(?:(?:\+|)55)|)(?:0|)(?:11|12|13|14|15|16|17|18|19|21|22|24|27|28|31|32|33|34|35|36|37|38|41|42|43|44|45|46|47|48|49|51|52|53|54|55|61|62|63|64|65|66|67|68|69|71|72|73|74|75|77|78|79|81|82|83|84|85|86|87|88|89|91|92|93|94|95|96|97|98|99)(?:9\d{8}|[1-8]\d{7})$/;
|
|
23
13
|
const phone = value.replace(/\D/g, "");
|
|
24
14
|
if (!phoneRegex.test(phone)) {
|
|
25
|
-
return "country-forms.validation.
|
|
15
|
+
return "country-forms.validation.invalid";
|
|
26
16
|
}
|
|
27
17
|
return true;
|
|
28
18
|
}
|
|
29
19
|
function validateCPF(value) {
|
|
30
20
|
const digits = value.replace(/\D/g, "");
|
|
31
|
-
if (digits.length !== 11) return "country-forms.validation.
|
|
32
|
-
if (new Set(digits).size === 1) return "country-forms.validation.
|
|
21
|
+
if (digits.length !== 11) return "country-forms.validation.invalid";
|
|
22
|
+
if (new Set(digits).size === 1) return "country-forms.validation.invalid";
|
|
33
23
|
let sum = 0;
|
|
34
24
|
for (let i = 0; i < 9; i++) {
|
|
35
25
|
sum += Number(digits[i]) * (10 - i);
|
|
36
26
|
}
|
|
37
27
|
let remainder = sum * 10 % 11;
|
|
38
28
|
if (remainder === 10) remainder = 0;
|
|
39
|
-
if (remainder !== Number(digits[9])) return "country-forms.validation.
|
|
29
|
+
if (remainder !== Number(digits[9])) return "country-forms.validation.invalid";
|
|
40
30
|
sum = 0;
|
|
41
31
|
for (let i = 0; i < 10; i++) {
|
|
42
32
|
sum += Number(digits[i]) * (11 - i);
|
|
43
33
|
}
|
|
44
34
|
remainder = sum * 10 % 11;
|
|
45
35
|
if (remainder === 10) remainder = 0;
|
|
46
|
-
if (remainder !== Number(digits[10])) return "country-forms.validation.
|
|
36
|
+
if (remainder !== Number(digits[10])) return "country-forms.validation.invalid";
|
|
47
37
|
return true;
|
|
48
38
|
}
|
|
49
39
|
var CNPJ_TOTAL_LENGTH = 14;
|
|
@@ -65,26 +55,25 @@ function calculateCnpjCheckDigit(prefix) {
|
|
|
65
55
|
return remainder < 2 ? 0 : CNPJ_MODULUS - remainder;
|
|
66
56
|
}
|
|
67
57
|
function validateCNPJ(value) {
|
|
68
|
-
if (!value || !value.trim()) return "country-forms.validation.
|
|
58
|
+
if (!value || !value.trim()) return "country-forms.validation.invalid";
|
|
69
59
|
const cleaned = value.trim().toUpperCase().replace(CNPJ_CLEAN_REGEX, "");
|
|
70
|
-
if (cleaned.length !== CNPJ_TOTAL_LENGTH) return "country-forms.validation.
|
|
71
|
-
if (!CNPJ_FORMAT_REGEX.test(cleaned)) return "country-forms.validation.
|
|
72
|
-
if (CNPJ_ALL_ZEROS_REGEX.test(cleaned)) return "country-forms.validation.
|
|
60
|
+
if (cleaned.length !== CNPJ_TOTAL_LENGTH) return "country-forms.validation.invalid";
|
|
61
|
+
if (!CNPJ_FORMAT_REGEX.test(cleaned)) return "country-forms.validation.invalid";
|
|
62
|
+
if (CNPJ_ALL_ZEROS_REGEX.test(cleaned)) return "country-forms.validation.invalid";
|
|
73
63
|
const base = cleaned.slice(0, CNPJ_BASE_LENGTH);
|
|
74
64
|
const providedCheck1 = Number(cleaned[CNPJ_BASE_LENGTH]);
|
|
75
65
|
const providedCheck2 = Number(cleaned[CNPJ_BASE_LENGTH + 1]);
|
|
76
66
|
const expectedCheck1 = calculateCnpjCheckDigit(base);
|
|
77
|
-
if (providedCheck1 !== expectedCheck1) return "country-forms.validation.
|
|
67
|
+
if (providedCheck1 !== expectedCheck1) return "country-forms.validation.invalid";
|
|
78
68
|
const expectedCheck2 = calculateCnpjCheckDigit(base + expectedCheck1);
|
|
79
|
-
if (providedCheck2 !== expectedCheck2) return "country-forms.validation.
|
|
69
|
+
if (providedCheck2 !== expectedCheck2) return "country-forms.validation.invalid";
|
|
80
70
|
return true;
|
|
81
71
|
}
|
|
82
72
|
registerValidator("validateCEP", validateCEP);
|
|
83
|
-
registerValidator("validateEmail", validateEmail);
|
|
84
73
|
registerValidator("validatePhoneBRA", validatePhoneBRA);
|
|
85
74
|
registerValidator("validateCPF", validateCPF);
|
|
86
75
|
registerValidator("validateCNPJ", validateCNPJ);
|
|
87
76
|
|
|
88
|
-
export { validateCEP, validateCNPJ, validateCPF,
|
|
89
|
-
//# sourceMappingURL=bra-
|
|
90
|
-
//# sourceMappingURL=bra-
|
|
77
|
+
export { validateCEP, validateCNPJ, validateCPF, validatePhoneBRA };
|
|
78
|
+
//# sourceMappingURL=bra-MJUXI46I.mjs.map
|
|
79
|
+
//# sourceMappingURL=bra-MJUXI46I.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/validators/bra.ts"],"names":[],"mappings":";;;;AAmCO,SAAS,YAAY,KAAA,EAAiC;AAC3D,EAAA,MAAM,MAAA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kB,gBAAgB,YAAY,CAAA","file":"bra-MJUXI46I.mjs","sourcesContent":["/**\n * @module rules/validators/bra\n *\n * Synchronous validators for Brazilian address and personal-data fields.\n * Importing this module registers all validators in the shared registry.\n *\n * Registered refs:\n * - `\"validateCEP\"` — Brazilian postal code format\n * - `\"validatePhoneBRA\"` — Brazilian landline and mobile phone numbers\n * - `\"validateCPF\"` — Brazilian individual taxpayer ID (CPF) with check digits\n * - `\"validateCNPJ\"` — Brazilian company taxpayer ID (CNPJ), numeric or alphanumeric (SERPRO 2024+)\n *\n * The country-agnostic `\"validateEmail\"` validator lives in\n * `rules/validators/common` and is re-exported here for backward compatibility.\n */\n\nimport { registerValidator } from './index'\n\n// Re-exported for convenience; the shared email validator is registered by the\n// common module (importing this file evaluates `./common`, registering it too).\nexport { validateEmail } from './common'\n\n// ── CEP ───────────────────────────────────────────────────────────────────────\n\n/**\n * Validates a Brazilian CEP (Código de Endereçamento Postal).\n *\n * Accepts both masked (\"01310-100\") and unmasked (\"01310100\") forms.\n * Rules:\n * - Must contain exactly 8 digits after stripping non-digits.\n * - All identical digits are invalid (e.g. `\"00000000\"`, `\"11111111\"`).\n *\n * @param value - The CEP string to validate (with or without mask)\n * @returns `true` if valid, or an i18n error key string when invalid\n */\nexport function validateCEP(value: string): boolean | string {\n const digits = value.replace(/\\D/g, '')\n\n // Must contain exactly 8 digits\n if (digits.length !== 8) return 'country-forms.validation.postalCode.BRA'\n // Must not be all the same digit\n if (new Set(digits).size === 1) return 'country-forms.validation.postalCode.BRA'\n\n return true\n}\n\n// ── Phone ──────────────────────────────────────────────────────────────────────\n\n/**\n * Validates a Brazilian phone number.\n *\n * Accepts masked (`\"(11) 99999-9999\"`) and unmasked (`\"11999999999\"`) forms,\n * as well as numbers prefixed with the country code `+55` or trunk prefix `0`.\n * Non-digit characters are stripped before validation.\n *\n * Rules:\n * - Area code (DDD) must be a valid 2-digit Brazilian DDD (11-99, with gaps).\n * - Mobile numbers: 9 + 8 digits (total 11 digits after DDD).\n * - Landline numbers: [1-8] + 7 digits (total 10 digits after DDD).\n *\n * @param value - Phone string to validate (with or without mask, country code, or trunk prefix)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validatePhoneBRA(value: string): boolean | string {\n const phoneRegex = /^(?:(?:(?:\\+|)55)|)(?:0|)(?:11|12|13|14|15|16|17|18|19|21|22|24|27|28|31|32|33|34|35|36|37|38|41|42|43|44|45|46|47|48|49|51|52|53|54|55|61|62|63|64|65|66|67|68|69|71|72|73|74|75|77|78|79|81|82|83|84|85|86|87|88|89|91|92|93|94|95|96|97|98|99)(?:9\\d{8}|[1-8]\\d{7})$/\n const phone = value.replace(/\\D/g, '')\n if (!phoneRegex.test(phone)) {\n return 'country-forms.validation.invalid'\n }\n return true\n}\n\n// ── CPF ───────────────────────────────────────────────────────────────────────\n\n/**\n * Validates a Brazilian CPF (Cadastro de Pessoas Físicas).\n *\n * Accepts masked (`\"123.456.789-09\"`) and unmasked (`\"12345678909\"`) forms.\n * Rules:\n * - Must contain exactly 11 digits after stripping non-digits.\n * - All identical digits are invalid (e.g. `\"000.000.000-00\"`).\n * - Check digits (positions 10 and 11) must satisfy the Receita Federal algorithm.\n *\n * @param value - CPF string to validate (with or without mask)\n * @returns `true` when valid, or an i18n error key string when invalid\n * @see https://www.macoratti.net/alg_cpf.htm\n */\nexport function validateCPF(value: string): boolean | string {\n const digits = value.replace(/\\D/g, '')\n\n if (digits.length !== 11) return 'country-forms.validation.invalid'\n if (new Set(digits).size === 1) return 'country-forms.validation.invalid'\n\n let sum = 0\n for (let i = 0; i < 9; i++) {\n sum += Number(digits[i]) * (10 - i)\n }\n let remainder = (sum * 10) % 11\n if (remainder === 10) remainder = 0\n if (remainder !== Number(digits[9])) return 'country-forms.validation.invalid'\n\n sum = 0\n for (let i = 0; i < 10; i++) {\n sum += Number(digits[i]) * (11 - i)\n }\n remainder = (sum * 10) % 11\n if (remainder === 10) remainder = 0\n if (remainder !== Number(digits[10])) return 'country-forms.validation.invalid'\n\n return true\n}\n\n// ── CNPJ ──────────────────────────────────────────────────────────────────────\n\nconst CNPJ_TOTAL_LENGTH = 14\nconst CNPJ_BASE_LENGTH = 12\nconst CNPJ_MODULUS = 11\nconst CNPJ_BASE_CHAR_CODE = '0'.charCodeAt(0)\n\n// Shared 13-element weight table. The first check digit uses the last 12 weights\n// (over the 12-character base); the second check digit uses all 13 weights\n// (over base + first check digit). This mirrors the SERPRO reference algorithm.\nconst CNPJ_WEIGHTS = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2] as const\n\nconst CNPJ_CLEAN_REGEX = /[./\\-\\s]/g\nconst CNPJ_FORMAT_REGEX = /^[A-Z0-9]{12}[0-9]{2}$/\nconst CNPJ_ALL_ZEROS_REGEX = /^0+$/\n\n/**\n * Computes a CNPJ check digit for the given alphanumeric prefix using the\n * SERPRO algorithm. Each character contributes `charCode - '0'` to the\n * weighted sum: digits `0-9` map to `0-9`, letters `A-Z` map to `17-42`.\n *\n * @internal\n */\nfunction calculateCnpjCheckDigit(prefix: string): number {\n const offset = CNPJ_WEIGHTS.length - prefix.length\n let sum = 0\n for (let i = 0; i < prefix.length; i++) {\n const charValue = prefix.charCodeAt(i) - CNPJ_BASE_CHAR_CODE\n sum += charValue * (CNPJ_WEIGHTS[offset + i] as number)\n }\n const remainder = sum % CNPJ_MODULUS\n return remainder < 2 ? 0 : CNPJ_MODULUS - remainder\n}\n\n/**\n * Validates a Brazilian CNPJ (Cadastro Nacional da Pessoa Jurídica).\n *\n * Supports both the legacy numeric format and the new alphanumeric format\n * announced by the Receita Federal (Instrução Normativa RFB 2.229/2024,\n * effective for new registrations from July 2026 onward). Numeric CNPJs\n * already issued remain valid — they are a strict subset of the new format.\n *\n * Accepted inputs:\n * - Masked numeric: `\"11.222.333/0001-81\"`\n * - Unmasked numeric: `\"11222333000181\"`\n * - Masked alphanumeric: `\"12.ABC.345/01DE-35\"`\n * - Unmasked alphanumeric: `\"12ABC34501DE35\"`\n *\n * Lowercase letters are accepted and normalized to uppercase.\n *\n * Rules:\n * - After stripping separators (`.`, `/`, `-`, whitespace), the string must be\n * exactly 14 characters long.\n * - The first 12 characters (base) must be alphanumeric uppercase (`A-Z`, `0-9`).\n * - The last 2 characters (check digits) must be numeric (`0-9`).\n * - All-zeros input is invalid (e.g. `\"00000000000000\"`).\n * - Check digits must satisfy the SERPRO algorithm: each character contributes\n * `charCode - '0'.charCode` to a weighted sum modulo 11.\n *\n * @param value - CNPJ string to validate (with or without mask, numeric or alphanumeric)\n * @returns `true` when valid, or an i18n error key string when invalid\n * @see https://www.gov.br/receitafederal/pt-br/acesso-a-informacao/acoes-e-programas/programas-e-atividades/cnpj-alfanumerico\n */\nexport function validateCNPJ(value: string): boolean | string {\n if (!value || !value.trim()) return 'country-forms.validation.invalid'\n\n const cleaned = value.trim().toUpperCase().replace(CNPJ_CLEAN_REGEX, '')\n\n if (cleaned.length !== CNPJ_TOTAL_LENGTH) return 'country-forms.validation.invalid'\n if (!CNPJ_FORMAT_REGEX.test(cleaned)) return 'country-forms.validation.invalid'\n if (CNPJ_ALL_ZEROS_REGEX.test(cleaned)) return 'country-forms.validation.invalid'\n\n const base = cleaned.slice(0, CNPJ_BASE_LENGTH)\n const providedCheck1 = Number(cleaned[CNPJ_BASE_LENGTH])\n const providedCheck2 = Number(cleaned[CNPJ_BASE_LENGTH + 1])\n\n const expectedCheck1 = calculateCnpjCheckDigit(base)\n if (providedCheck1 !== expectedCheck1) return 'country-forms.validation.invalid'\n\n const expectedCheck2 = calculateCnpjCheckDigit(base + expectedCheck1)\n if (providedCheck2 !== expectedCheck2) return 'country-forms.validation.invalid'\n\n return true\n}\n\nregisterValidator('validateCEP', validateCEP)\nregisterValidator('validatePhoneBRA', validatePhoneBRA)\nregisterValidator('validateCPF', validateCPF)\nregisterValidator('validateCNPJ', validateCNPJ)\n"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkCFX5EF4R_js = require('./chunk-CFX5EF4R.js');
|
|
4
|
+
|
|
5
|
+
// src/rules/validators/can.ts
|
|
6
|
+
var INVALID_FSA_FIRST_LETTERS = /* @__PURE__ */ new Set(["D", "F", "I", "O", "Q", "U", "W"]);
|
|
7
|
+
function validatePostalCodeCAN(value) {
|
|
8
|
+
const normalized = value.replace(/\s+/g, "").toUpperCase();
|
|
9
|
+
if (!/^[A-Z]\d[A-Z]\d[A-Z]\d$/.test(normalized)) {
|
|
10
|
+
return "country-forms.validation.postalCode.CAN";
|
|
11
|
+
}
|
|
12
|
+
if (INVALID_FSA_FIRST_LETTERS.has(normalized[0])) {
|
|
13
|
+
return "country-forms.validation.postalCode.CAN";
|
|
14
|
+
}
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
var PHONE_CAN_REGEX = /^[2-9]\d{2}[2-9]\d{6}$/;
|
|
18
|
+
function unformatPhoneCANDigits(value) {
|
|
19
|
+
const digits = value.replace(/\D/g, "");
|
|
20
|
+
if (digits.length > 10 && digits.startsWith("1")) {
|
|
21
|
+
return digits.slice(1);
|
|
22
|
+
}
|
|
23
|
+
return digits;
|
|
24
|
+
}
|
|
25
|
+
function validatePhoneCAN(value) {
|
|
26
|
+
const phone = unformatPhoneCANDigits(value);
|
|
27
|
+
if (!PHONE_CAN_REGEX.test(phone)) {
|
|
28
|
+
return "country-forms.validation.invalid";
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
function validateSIN(value) {
|
|
33
|
+
const digits = value.replace(/\D/g, "");
|
|
34
|
+
if (digits.length !== 9) return "country-forms.validation.invalid";
|
|
35
|
+
if (/^0+$/.test(digits)) return "country-forms.validation.invalid";
|
|
36
|
+
let sum = 0;
|
|
37
|
+
for (let i = 0; i < 9; i++) {
|
|
38
|
+
let n = Number(digits[i]);
|
|
39
|
+
if (i % 2 === 1) {
|
|
40
|
+
n *= 2;
|
|
41
|
+
if (n > 9) n -= 9;
|
|
42
|
+
}
|
|
43
|
+
sum += n;
|
|
44
|
+
}
|
|
45
|
+
if (sum % 10 !== 0) return "country-forms.validation.invalid";
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
function validateBN(value) {
|
|
49
|
+
const digits = value.replace(/\D/g, "");
|
|
50
|
+
if (digits.length !== 9) return "country-forms.validation.invalid";
|
|
51
|
+
if (/^0+$/.test(digits)) return "country-forms.validation.invalid";
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
chunkCFX5EF4R_js.registerValidator("validatePostalCodeCAN", validatePostalCodeCAN);
|
|
55
|
+
chunkCFX5EF4R_js.registerValidator("validatePhoneCAN", validatePhoneCAN);
|
|
56
|
+
chunkCFX5EF4R_js.registerValidator("validateSIN", validateSIN);
|
|
57
|
+
chunkCFX5EF4R_js.registerValidator("validateBN", validateBN);
|
|
58
|
+
|
|
59
|
+
exports.unformatPhoneCANDigits = unformatPhoneCANDigits;
|
|
60
|
+
exports.validateBN = validateBN;
|
|
61
|
+
exports.validatePhoneCAN = validatePhoneCAN;
|
|
62
|
+
exports.validatePostalCodeCAN = validatePostalCodeCAN;
|
|
63
|
+
exports.validateSIN = validateSIN;
|
|
64
|
+
//# sourceMappingURL=can-3MOZIOGB.js.map
|
|
65
|
+
//# sourceMappingURL=can-3MOZIOGB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/validators/can.ts"],"names":["registerValidator"],"mappings":";;;;;AAmBA,IAAM,yBAAA,mBAA4B,IAAI,GAAA,CAAI,CAAC,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AActE,SAAS,sBAAsB,KAAA,EAAiC;AACrE,EAAA,MAAM,aAAa,KAAA,CAAM,OAAA,CAAQ,MAAA,EAAQ,EAAE,EAAE,WAAA,EAAY;AAEzD,EAAA,IAAI,CAAC,yBAAA,CAA0B,IAAA,CAAK,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MAAM,CAAA,EAAG;AACf,MAAA,CAAA,IAAK,CAAA;AACL,MAAA,IAAI,CAAA,GAAI,GAAG,CAAA,IAAK,CAAA;AAAA,IAClB;AACA,IAAA,GAAA,IAAO,CAAA;AAAA,EACT;AAEA,EAAA,IAAI,GAAA,GAAM,EAAA,KAAO,CAAA,EAAG,OAAO,kCAAA;AAE3B,EAAA,OAAO,IAAA;AACT;AAkBO,SAAS,WAAW,KAAA,EAAiC;AAC1D,EAAA,MAAM,MAAA,GAAS,KAAA,CAAM,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAA;AAEtC,EAAA,IAAI,MAAA,CAAO,MAAA,KAAW,CAAA,EAAG,OAAO,kCAAA;AAChC,EAAA,IAAI,MAAA,CAAO,IAAA,CAAK,MAAM,CAAA,EAAG,OAAO,kCAAA;AAEhC,EAAA,OAAO,IAAA;AACT;AAEAA,kCAAA,CAAkB,yBAAyB,qBAAqB,CAAA;AAChEA,kCAAA,CAAkB,oBAAoB,gBAAgB,CAAA;AACtDA,kCAAA,CAAkB,eAAe,WAAW,CAAA;AAC5CA,kCAAA,CAAkB,cAAc,UAAU,CAAA","file":"can-3MOZIOGB.js","sourcesContent":["/**\n * @module rules/validators/can\n *\n * Synchronous validators for Canadian address and personal-data fields.\n * Importing this module registers all validators in the shared registry.\n *\n * Registered refs:\n * - `\"validatePostalCodeCAN\"` — Canadian postal code format and FSA validation\n * - `\"validatePhoneCAN\"` — Canadian/NANP phone number (10 digits, optional `+1`)\n * - `\"validateSIN\"` — Social Insurance Number (9 digits + Luhn check)\n * - `\"validateBN\"` — Business Number (9 digits, structural)\n */\n\nimport { registerValidator } from './index'\n\n/**\n * First characters not assigned in Canadian FSA (Forward Sortation Area) codes.\n * @see https://en.wikipedia.org/wiki/Postal_codes_in_Canada#Components_of_a_postal_code\n */\nconst INVALID_FSA_FIRST_LETTERS = new Set(['D', 'F', 'I', 'O', 'Q', 'U', 'W'])\n\n/**\n * Validates a Canadian postal code.\n *\n * Accepts spaced (`\"K1A 0A9\"`) and unspaced (`\"K1A0A9\"`) forms; case-insensitive.\n *\n * Rules:\n * - Format must be A1A 1A1 (alternating letter-digit-letter space digit-letter-digit).\n * - First character (FSA leader) cannot be D, F, I, O, Q, U, or W.\n *\n * @param value - Postal code string to validate (with or without mask, e.g. `\"K1A 0A9\"` or `\"K1A0A9\"`)\n * @returns `true` when valid, or an i18n error key string when invalid\n */\nexport function validatePostalCodeCAN(value: string): boolean | string {\n const normalized = value.replace(/\\s+/g, '').toUpperCase()\n\n if (!/^[A-Z]\\d[A-Z]\\d[A-Z]\\d$/.test(normalized)) {\n return 'country-forms.validation.postalCode.CAN'\n }\n\n if (INVALID_FSA_FIRST_LETTERS.has(normalized[0] as string)) {\n return 'country-forms.validation.postalCode.CAN'\n }\n\n return true\n}\n\n/**\n * Structural NANP phone check: 10 digits where neither the area code nor the\n * central-office (exchange) code may start with 0 or 1 (`[2-9]`). Applied to the\n * digits-only string after stripping the optional `+1` country code\n * (see {@link unformatPhoneCANDigits}).\n *\n * We validate the NANP *structure* on purpose instead of an allowlist of known\n * Canadian area codes. A hardcoded allowlist silently rejects valid numbers from\n * regions whose area codes the CNA/NANPA allocated after the list was written,\n * with no actionable error and no mechanism to flag the staleness — blocking\n * legitimate submissions in production. Structural validation accepts any future\n * allocation while still rejecting the impossible `0xx`/`1xx` ranges. Canada\n * shares the NANP with the US, so US-format numbers also pass; that trade-off is\n * acceptable for a phone field and far safer operationally than silent rejection.\n */\nconst PHONE_CAN_REGEX = /^[2-9]\\d{2}[2-9]\\d{6}$/\n\n/**\n * Strips non-digits and the optional leading `1` country code, returning the\n * 10-digit national number when possible.\n *\n * NOTE: this mirrors `unformatPhoneCAN` in `rules/masks/can.ts` by design. The\n * duplication is intentional: validators and masks are independent modules that\n * load separately (a consumer can import one without the other, preserving\n * tree-shaking and module isolation). Validators must NOT import from masks, so\n * the small amount of shared logic is copied rather than shared. It is exported\n * so a cross-module test can assert that both copies stay in sync — keep both\n * implementations identical if the unformat rule changes.\n */\nexport function unformatPhoneCANDigits(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('1')) {\n return digits.slice(1)\n }\n return digits\n}\n\n/**\n * Validates a Canadian phone number (North American Numbering Plan).\n *\n * Accepts masked (`\"613-555-0123\"`) and unmasked (`\"6135550123\"`) forms, as\n * well as numbers prefixed with the country code `+1` / `1`. Non-digit\n * characters are stripped before validation.\n *\n * Rules:\n * - After stripping the optional country code, the number must be 10 digits.\n * - NANP structure: neither the area code nor the exchange code may begin with\n * `0` or `1` (see {@link PHONE_CAN_REGEX} for why this replaces an allowlist).\n *\n * @param value - Phone string to validate (with or without mask or `+1` prefix)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validatePhoneCAN(value: string): boolean | string {\n const phone = unformatPhoneCANDigits(value)\n if (!PHONE_CAN_REGEX.test(phone)) {\n return 'country-forms.validation.invalid'\n }\n return true\n}\n\n/**\n * Validates a Canadian Social Insurance Number (SIN).\n *\n * Accepts masked (`\"046-454-286\"`) and unmasked (`\"046454286\"`) forms.\n * Rules:\n * - Exactly 9 digits after stripping non-digits.\n * - All-zeros input is invalid.\n * - Must pass the Luhn checksum (the official SIN check-digit algorithm).\n *\n * @param value - SIN string to validate (with or without mask)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validateSIN(value: string): boolean | string {\n const digits = value.replace(/\\D/g, '')\n\n if (digits.length !== 9) return 'country-forms.validation.invalid'\n if (/^0+$/.test(digits)) return 'country-forms.validation.invalid'\n\n // Luhn checksum: double every second digit (0-indexed odd positions).\n let sum = 0\n for (let i = 0; i < 9; i++) {\n let n = Number(digits[i])\n if (i % 2 === 1) {\n n *= 2\n if (n > 9) n -= 9\n }\n sum += n\n }\n\n if (sum % 10 !== 0) return 'country-forms.validation.invalid'\n\n return true\n}\n\n/**\n * Validates a Canadian Business Number (BN).\n *\n * Accepts unmasked 9-digit forms (`\"123456789\"`).\n * Rules:\n * - Exactly 9 digits after stripping non-digits.\n * - All-zeros input is invalid.\n *\n * Limitation: this is a **structural** check only. The CRA assigns the 9-digit\n * BN with its own internal logic, but it cannot be fully verified without an\n * external lookup, so we intentionally do not validate beyond length/all-zeros\n * to avoid false negatives for legitimate numbers.\n *\n * @param value - BN string to validate (with or without separators)\n * @returns `true` when valid, or the i18n error key `\"country-forms.validation.invalid\"` when invalid\n */\nexport function validateBN(value: string): boolean | string {\n const digits = value.replace(/\\D/g, '')\n\n if (digits.length !== 9) return 'country-forms.validation.invalid'\n if (/^0+$/.test(digits)) return 'country-forms.validation.invalid'\n\n return true\n}\n\nregisterValidator('validatePostalCodeCAN', validatePostalCodeCAN)\nregisterValidator('validatePhoneCAN', validatePhoneCAN)\nregisterValidator('validateSIN', validateSIN)\nregisterValidator('validateBN', validateBN)\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { registerMask } from './chunk-BMZHOWIP.mjs';
|
|
2
|
+
|
|
3
|
+
// src/rules/masks/can.ts
|
|
4
|
+
function formatPostalCodeCAN(value) {
|
|
5
|
+
const normalized = value.replace(/\s+/g, "").toUpperCase().slice(0, 6);
|
|
6
|
+
if (normalized.length !== 6) return value.toUpperCase();
|
|
7
|
+
return `${normalized.slice(0, 3)} ${normalized.slice(3)}`;
|
|
8
|
+
}
|
|
9
|
+
function unformatPostalCodeCAN(value) {
|
|
10
|
+
return value.replace(/\s+/g, "").toUpperCase();
|
|
11
|
+
}
|
|
12
|
+
function formatPhoneCAN(value) {
|
|
13
|
+
const phone = unformatPhoneCAN(value);
|
|
14
|
+
if (phone.length !== 10) return phone;
|
|
15
|
+
return `${phone.slice(0, 3)}-${phone.slice(3, 6)}-${phone.slice(6)}`;
|
|
16
|
+
}
|
|
17
|
+
function unformatPhoneCAN(value) {
|
|
18
|
+
const digits = value.replace(/\D/g, "");
|
|
19
|
+
if (digits.length > 10 && digits.startsWith("1")) {
|
|
20
|
+
return digits.slice(1);
|
|
21
|
+
}
|
|
22
|
+
return digits;
|
|
23
|
+
}
|
|
24
|
+
function formatSIN(value) {
|
|
25
|
+
const digits = value.replace(/\D/g, "");
|
|
26
|
+
if (digits.length !== 9) return digits;
|
|
27
|
+
return `${digits.slice(0, 3)}-${digits.slice(3, 6)}-${digits.slice(6)}`;
|
|
28
|
+
}
|
|
29
|
+
function unformatSIN(value) {
|
|
30
|
+
return value.replace(/\D/g, "");
|
|
31
|
+
}
|
|
32
|
+
registerMask("formatPostalCodeCAN", formatPostalCodeCAN);
|
|
33
|
+
registerMask("unformatPostalCodeCAN", unformatPostalCodeCAN);
|
|
34
|
+
registerMask("formatPhoneCAN", formatPhoneCAN);
|
|
35
|
+
registerMask("unformatPhoneCAN", unformatPhoneCAN);
|
|
36
|
+
registerMask("formatSIN", formatSIN);
|
|
37
|
+
registerMask("unformatSIN", unformatSIN);
|
|
38
|
+
|
|
39
|
+
export { formatPhoneCAN, formatPostalCodeCAN, formatSIN, unformatPhoneCAN, unformatPostalCodeCAN, unformatSIN };
|
|
40
|
+
//# sourceMappingURL=can-DKTB2M6I.mjs.map
|
|
41
|
+
//# sourceMappingURL=can-DKTB2M6I.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/masks/can.ts"],"names":[],"mappings":";;;AA4BO,SAAS,oBAAoB,KAAA,EAAuB;AACzD,EAAA,MAAM,UAAA,GAAa,KAAA,CAAM,OAAA,CAAQ,MAAA,EAAQ,EAAE,EAAE,WAAA,EAAY,CAAE,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AAErE,EAAA,IAAI,UAAA,CAAW,MAAA,KAAW,CAAA,EAAG,OAAO,MAAM,WAAA,EAAY;AAEtD,EAAA,OAAO,CAAA,EAAG,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,UAAA,CAAW,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AACzD;AAUO,SAAS,sBAAsB,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AE,CAAA;AAChC;AAEA,YAAA,CAAa,uBAAuB,mBAAmB,CAAA;AACvD,YAAA,CAAa,yBAAyB,qBAAqB,CAAA;AAC3D,YAAA,CAAa,kBAAkB,cAAc,CAAA;AAC7C,YAAA,CAAa,oBAAoB,gBAAgB,CAAA;AACjD,YAAA,CAAa,aAAa,SAAS,CAAA;AACnC,YAAA,CAAa,eAAe,WAAW,CAAA","file":"can-DKTB2M6I.mjs","sourcesContent":["/**\n * @module rules/masks/can\n *\n * Format/unformat functions for Canadian address and personal-data fields.\n * Importing this module registers all masks in the shared registry.\n *\n * Registered refs:\n * - `\"formatPostalCodeCAN\"` — normalizes to uppercase `\"A1A 1A1\"` with space\n * - `\"unformatPostalCodeCAN\"` — strips space, returns uppercase `\"A1A1A1\"`\n * - `\"formatPhoneCAN\"` / `\"unformatPhoneCAN\"` — Canadian phone (999-999-9999)\n * - `\"formatSIN\"` / `\"unformatSIN\"` — Social Insurance Number (999-999-999)\n */\n\nimport { registerMask } from './index'\n\n/**\n * Formats a Canadian postal code for display with a space separator.\n * Normalizes to uppercase and truncates to at most 6 non-space characters.\n *\n * `\"k1a0a9\"` → `\"K1A 0A9\"`\n * `\"K1A 0A9\"` → `\"K1A 0A9\"` (idempotent)\n *\n * Returns the input uppercased but otherwise unchanged when it does not\n * contain exactly 6 non-space characters after truncation (e.g. partial input during typing).\n *\n * @param value - Raw or partially formatted postal code\n * @returns Display string in `\"A1A 1A1\"` format\n */\nexport function formatPostalCodeCAN(value: string): string {\n const normalized = value.replace(/\\s+/g, '').toUpperCase().slice(0, 6)\n\n if (normalized.length !== 6) return value.toUpperCase()\n\n return `${normalized.slice(0, 3)} ${normalized.slice(3)}`\n}\n\n/**\n * Strips the space from a Canadian postal code and normalizes to uppercase.\n *\n * `\"K1A 0A9\"` → `\"K1A0A9\"`\n *\n * @param value - Display-formatted postal code\n * @returns Raw string suitable for API submission\n */\nexport function unformatPostalCodeCAN(value: string): string {\n return value.replace(/\\s+/g, '').toUpperCase()\n}\n\n// ── Phone ──────────────────────────────────────────────────────────────────────\n\n/**\n * Formats a raw Canadian phone string for display.\n *\n * - Strips non-digits and a leading `1` country code (when more than 10 digits)\n * - 10 digits → `\"613-555-0123\"`\n * - Otherwise returns the digits-only input unchanged (partial input while typing)\n *\n * @param value - Raw or partially formatted Canadian phone string\n * @returns Display string in `999-999-9999` format\n */\nexport function formatPhoneCAN(value: string): string {\n const phone = unformatPhoneCAN(value)\n if (phone.length !== 10) return phone\n return `${phone.slice(0, 3)}-${phone.slice(3, 6)}-${phone.slice(6)}`\n}\n\n/**\n * `\"613-555-0123\"` → `\"6135550123\"`\n *\n * Strips all non-digit characters. A leading country code `\"1\"` is stripped\n * only when the remainder still has at least 10 digits.\n *\n * @param value - Display-formatted Canadian phone string\n * @returns Raw digit-only string without the country code\n */\nexport function unformatPhoneCAN(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('1')) {\n return digits.slice(1)\n }\n return digits\n}\n\n// ── SIN ──────────────────────────────────────────────────────────────────────\n\n/**\n * `\"046454286\"` → `\"046-454-286\"`\n *\n * Returns the digits-only string unchanged when it does not have exactly 9\n * digits (partial input while typing, or an over-long paste). It does **not**\n * truncate extra digits — silently dropping characters would hide invalid input\n * from the user. This matches {@link formatPhoneCAN}, which also leaves\n * wrong-length input untouched.\n *\n * @param value - Raw or partially formatted SIN string\n * @returns Display string in `999-999-999` format\n */\nexport function formatSIN(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length !== 9) return digits\n return `${digits.slice(0, 3)}-${digits.slice(3, 6)}-${digits.slice(6)}`\n}\n\n/**\n * `\"046-454-286\"` → `\"046454286\"`\n *\n * @param value - Display-formatted SIN string\n * @returns Raw digit-only string suitable for API submission\n */\nexport function unformatSIN(value: string): string {\n return value.replace(/\\D/g, '')\n}\n\nregisterMask('formatPostalCodeCAN', formatPostalCodeCAN)\nregisterMask('unformatPostalCodeCAN', unformatPostalCodeCAN)\nregisterMask('formatPhoneCAN', formatPhoneCAN)\nregisterMask('unformatPhoneCAN', unformatPhoneCAN)\nregisterMask('formatSIN', formatSIN)\nregisterMask('unformatSIN', unformatSIN)\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBQPGLWMB_js = require('./chunk-BQPGLWMB.js');
|
|
4
|
+
|
|
5
|
+
// src/rules/masks/can.ts
|
|
6
|
+
function formatPostalCodeCAN(value) {
|
|
7
|
+
const normalized = value.replace(/\s+/g, "").toUpperCase().slice(0, 6);
|
|
8
|
+
if (normalized.length !== 6) return value.toUpperCase();
|
|
9
|
+
return `${normalized.slice(0, 3)} ${normalized.slice(3)}`;
|
|
10
|
+
}
|
|
11
|
+
function unformatPostalCodeCAN(value) {
|
|
12
|
+
return value.replace(/\s+/g, "").toUpperCase();
|
|
13
|
+
}
|
|
14
|
+
function formatPhoneCAN(value) {
|
|
15
|
+
const phone = unformatPhoneCAN(value);
|
|
16
|
+
if (phone.length !== 10) return phone;
|
|
17
|
+
return `${phone.slice(0, 3)}-${phone.slice(3, 6)}-${phone.slice(6)}`;
|
|
18
|
+
}
|
|
19
|
+
function unformatPhoneCAN(value) {
|
|
20
|
+
const digits = value.replace(/\D/g, "");
|
|
21
|
+
if (digits.length > 10 && digits.startsWith("1")) {
|
|
22
|
+
return digits.slice(1);
|
|
23
|
+
}
|
|
24
|
+
return digits;
|
|
25
|
+
}
|
|
26
|
+
function formatSIN(value) {
|
|
27
|
+
const digits = value.replace(/\D/g, "");
|
|
28
|
+
if (digits.length !== 9) return digits;
|
|
29
|
+
return `${digits.slice(0, 3)}-${digits.slice(3, 6)}-${digits.slice(6)}`;
|
|
30
|
+
}
|
|
31
|
+
function unformatSIN(value) {
|
|
32
|
+
return value.replace(/\D/g, "");
|
|
33
|
+
}
|
|
34
|
+
chunkBQPGLWMB_js.registerMask("formatPostalCodeCAN", formatPostalCodeCAN);
|
|
35
|
+
chunkBQPGLWMB_js.registerMask("unformatPostalCodeCAN", unformatPostalCodeCAN);
|
|
36
|
+
chunkBQPGLWMB_js.registerMask("formatPhoneCAN", formatPhoneCAN);
|
|
37
|
+
chunkBQPGLWMB_js.registerMask("unformatPhoneCAN", unformatPhoneCAN);
|
|
38
|
+
chunkBQPGLWMB_js.registerMask("formatSIN", formatSIN);
|
|
39
|
+
chunkBQPGLWMB_js.registerMask("unformatSIN", unformatSIN);
|
|
40
|
+
|
|
41
|
+
exports.formatPhoneCAN = formatPhoneCAN;
|
|
42
|
+
exports.formatPostalCodeCAN = formatPostalCodeCAN;
|
|
43
|
+
exports.formatSIN = formatSIN;
|
|
44
|
+
exports.unformatPhoneCAN = unformatPhoneCAN;
|
|
45
|
+
exports.unformatPostalCodeCAN = unformatPostalCodeCAN;
|
|
46
|
+
exports.unformatSIN = unformatSIN;
|
|
47
|
+
//# sourceMappingURL=can-LLWX4LC2.js.map
|
|
48
|
+
//# sourceMappingURL=can-LLWX4LC2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/rules/masks/can.ts"],"names":["registerMask"],"mappings":";;;;;AA4BO,SAAS,oBAAoB,KAAA,EAAuB;AACzD,EAAA,MAAM,UAAA,GAAa,KAAA,CAAM,OAAA,CAAQ,MAAA,EAAQ,EAAE,EAAE,WAAA,EAAY,CAAE,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AAErE,EAAA,IAAI,UAAA,CAAW,MAAA,KAAW,CAAA,EAAG,OAAO,MAAM,WAAA,EAAY;AAEtD,EAAA,OAAO,CAAA,EAAG,UAAA,CAAW,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,UAAA,CAAW,KAAA,CAAM,CAAC,CAAC,CAAA,CAAA;AACzD;AAUO,SAAS,sBAAsB,KAAA,EAAuB;AAC3D,EAAA,OAAO,KAAA,CAAM,OAAA,CAAQ,MAAA,EAAQ,EAAE,EAAE,WAAA,EAAY;AAC/C;AAcO,SAAS,eAAe,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Aa,kBAAkB,cAAc,CAAA;AAC7CA,6BAAA,CAAa,oBAAoB,gBAAgB,CAAA;AACjDA,6BAAA,CAAa,aAAa,SAAS,CAAA;AACnCA,6BAAA,CAAa,eAAe,WAAW,CAAA","file":"can-LLWX4LC2.js","sourcesContent":["/**\n * @module rules/masks/can\n *\n * Format/unformat functions for Canadian address and personal-data fields.\n * Importing this module registers all masks in the shared registry.\n *\n * Registered refs:\n * - `\"formatPostalCodeCAN\"` — normalizes to uppercase `\"A1A 1A1\"` with space\n * - `\"unformatPostalCodeCAN\"` — strips space, returns uppercase `\"A1A1A1\"`\n * - `\"formatPhoneCAN\"` / `\"unformatPhoneCAN\"` — Canadian phone (999-999-9999)\n * - `\"formatSIN\"` / `\"unformatSIN\"` — Social Insurance Number (999-999-999)\n */\n\nimport { registerMask } from './index'\n\n/**\n * Formats a Canadian postal code for display with a space separator.\n * Normalizes to uppercase and truncates to at most 6 non-space characters.\n *\n * `\"k1a0a9\"` → `\"K1A 0A9\"`\n * `\"K1A 0A9\"` → `\"K1A 0A9\"` (idempotent)\n *\n * Returns the input uppercased but otherwise unchanged when it does not\n * contain exactly 6 non-space characters after truncation (e.g. partial input during typing).\n *\n * @param value - Raw or partially formatted postal code\n * @returns Display string in `\"A1A 1A1\"` format\n */\nexport function formatPostalCodeCAN(value: string): string {\n const normalized = value.replace(/\\s+/g, '').toUpperCase().slice(0, 6)\n\n if (normalized.length !== 6) return value.toUpperCase()\n\n return `${normalized.slice(0, 3)} ${normalized.slice(3)}`\n}\n\n/**\n * Strips the space from a Canadian postal code and normalizes to uppercase.\n *\n * `\"K1A 0A9\"` → `\"K1A0A9\"`\n *\n * @param value - Display-formatted postal code\n * @returns Raw string suitable for API submission\n */\nexport function unformatPostalCodeCAN(value: string): string {\n return value.replace(/\\s+/g, '').toUpperCase()\n}\n\n// ── Phone ──────────────────────────────────────────────────────────────────────\n\n/**\n * Formats a raw Canadian phone string for display.\n *\n * - Strips non-digits and a leading `1` country code (when more than 10 digits)\n * - 10 digits → `\"613-555-0123\"`\n * - Otherwise returns the digits-only input unchanged (partial input while typing)\n *\n * @param value - Raw or partially formatted Canadian phone string\n * @returns Display string in `999-999-9999` format\n */\nexport function formatPhoneCAN(value: string): string {\n const phone = unformatPhoneCAN(value)\n if (phone.length !== 10) return phone\n return `${phone.slice(0, 3)}-${phone.slice(3, 6)}-${phone.slice(6)}`\n}\n\n/**\n * `\"613-555-0123\"` → `\"6135550123\"`\n *\n * Strips all non-digit characters. A leading country code `\"1\"` is stripped\n * only when the remainder still has at least 10 digits.\n *\n * @param value - Display-formatted Canadian phone string\n * @returns Raw digit-only string without the country code\n */\nexport function unformatPhoneCAN(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length > 10 && digits.startsWith('1')) {\n return digits.slice(1)\n }\n return digits\n}\n\n// ── SIN ──────────────────────────────────────────────────────────────────────\n\n/**\n * `\"046454286\"` → `\"046-454-286\"`\n *\n * Returns the digits-only string unchanged when it does not have exactly 9\n * digits (partial input while typing, or an over-long paste). It does **not**\n * truncate extra digits — silently dropping characters would hide invalid input\n * from the user. This matches {@link formatPhoneCAN}, which also leaves\n * wrong-length input untouched.\n *\n * @param value - Raw or partially formatted SIN string\n * @returns Display string in `999-999-999` format\n */\nexport function formatSIN(value: string): string {\n const digits = value.replace(/\\D/g, '')\n if (digits.length !== 9) return digits\n return `${digits.slice(0, 3)}-${digits.slice(3, 6)}-${digits.slice(6)}`\n}\n\n/**\n * `\"046-454-286\"` → `\"046454286\"`\n *\n * @param value - Display-formatted SIN string\n * @returns Raw digit-only string suitable for API submission\n */\nexport function unformatSIN(value: string): string {\n return value.replace(/\\D/g, '')\n}\n\nregisterMask('formatPostalCodeCAN', formatPostalCodeCAN)\nregisterMask('unformatPostalCodeCAN', unformatPostalCodeCAN)\nregisterMask('formatPhoneCAN', formatPhoneCAN)\nregisterMask('unformatPhoneCAN', unformatPhoneCAN)\nregisterMask('formatSIN', formatSIN)\nregisterMask('unformatSIN', unformatSIN)\n"]}
|