@br-validators/core 0.10.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/boleto.d.ts +113 -0
- package/dist/boleto.js +4 -0
- package/dist/boleto.js.map +1 -0
- package/dist/cartao-credito.d.ts +47 -0
- package/dist/cartao-credito.js +4 -0
- package/dist/cartao-credito.js.map +1 -0
- package/dist/cep.d.ts +20 -0
- package/dist/cep.js +7 -0
- package/dist/cep.js.map +1 -0
- package/dist/chunk-54DTXC6V.js +207 -0
- package/dist/chunk-54DTXC6V.js.map +1 -0
- package/dist/chunk-7FOWIH6F.js +20 -0
- package/dist/chunk-7FOWIH6F.js.map +1 -0
- package/dist/chunk-AKJHIJ5E.js +387 -0
- package/dist/chunk-AKJHIJ5E.js.map +1 -0
- package/dist/chunk-B2TDI3YS.js +23 -0
- package/dist/chunk-B2TDI3YS.js.map +1 -0
- package/dist/chunk-DKRM66US.js +35 -0
- package/dist/chunk-DKRM66US.js.map +1 -0
- package/dist/chunk-EB3G4IG6.js +8 -0
- package/dist/chunk-EB3G4IG6.js.map +1 -0
- package/dist/chunk-M66MGLHE.js +156 -0
- package/dist/chunk-M66MGLHE.js.map +1 -0
- package/dist/chunk-OWJ5HN4T.js +91 -0
- package/dist/chunk-OWJ5HN4T.js.map +1 -0
- package/dist/chunk-PBNVKDCF.js +82 -0
- package/dist/chunk-PBNVKDCF.js.map +1 -0
- package/dist/chunk-RMKTJQBB.js +61 -0
- package/dist/chunk-RMKTJQBB.js.map +1 -0
- package/dist/chunk-RZ2JG5PP.js +14 -0
- package/dist/chunk-RZ2JG5PP.js.map +1 -0
- package/dist/chunk-SE33CFGM.js +276 -0
- package/dist/chunk-SE33CFGM.js.map +1 -0
- package/dist/chunk-UCJPSJN5.js +8 -0
- package/dist/chunk-UCJPSJN5.js.map +1 -0
- package/dist/chunk-W6UXVWSR.js +13 -0
- package/dist/chunk-W6UXVWSR.js.map +1 -0
- package/dist/chunk-YY4M2YS6.js +115 -0
- package/dist/chunk-YY4M2YS6.js.map +1 -0
- package/dist/chunk-Z4F75QEC.js +1180 -0
- package/dist/chunk-Z4F75QEC.js.map +1 -0
- package/dist/cnpj.d.ts +37 -0
- package/dist/cnpj.js +7 -0
- package/dist/cnpj.js.map +1 -0
- package/dist/cpf.d.ts +20 -0
- package/dist/cpf.js +7 -0
- package/dist/cpf.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/inscricao-estadual.d.ts +57 -0
- package/dist/inscricao-estadual.js +4 -0
- package/dist/inscricao-estadual.js.map +1 -0
- package/dist/pis-pasep.d.ts +20 -0
- package/dist/pis-pasep.js +5 -0
- package/dist/pis-pasep.js.map +1 -0
- package/dist/pix-DP6jnwpN.d.ts +44 -0
- package/dist/pix.d.ts +11 -0
- package/dist/pix.js +9 -0
- package/dist/pix.js.map +1 -0
- package/dist/placa.d.ts +35 -0
- package/dist/placa.js +7 -0
- package/dist/placa.js.map +1 -0
- package/dist/validation-result-BK4qJuei.d.ts +101 -0
- package/package.json +91 -0
|
@@ -0,0 +1,1180 @@
|
|
|
1
|
+
import { brandInscricaoEstadual } from './chunk-DKRM66US.js';
|
|
2
|
+
|
|
3
|
+
// src/core/inscricao-estadual/constants.ts
|
|
4
|
+
var IE_SUPPORTED_UFS = [
|
|
5
|
+
"AC",
|
|
6
|
+
"AL",
|
|
7
|
+
"AM",
|
|
8
|
+
"AP",
|
|
9
|
+
"BA",
|
|
10
|
+
"CE",
|
|
11
|
+
"DF",
|
|
12
|
+
"ES",
|
|
13
|
+
"GO",
|
|
14
|
+
"MA",
|
|
15
|
+
"MG",
|
|
16
|
+
"MS",
|
|
17
|
+
"MT",
|
|
18
|
+
"PA",
|
|
19
|
+
"PB",
|
|
20
|
+
"PE",
|
|
21
|
+
"PI",
|
|
22
|
+
"PR",
|
|
23
|
+
"RJ",
|
|
24
|
+
"RN",
|
|
25
|
+
"RO",
|
|
26
|
+
"RR",
|
|
27
|
+
"RS",
|
|
28
|
+
"SC",
|
|
29
|
+
"SE",
|
|
30
|
+
"SP",
|
|
31
|
+
"TO"
|
|
32
|
+
];
|
|
33
|
+
var IE_OFFICIAL_SOURCE_URLS = {
|
|
34
|
+
AC: "https://sefaz.ac.gov.br/",
|
|
35
|
+
AL: "https://www.sefaz.al.gov.br/calculo",
|
|
36
|
+
AM: "https://www.sefaz.am.gov.br/",
|
|
37
|
+
AP: "https://www.sefaz.ap.gov.br/",
|
|
38
|
+
BA: "https://www.sefaz.ba.gov.br/inspetoria-eletronica/icms/cadastro/calculo-dv/",
|
|
39
|
+
CE: "https://www.sefaz.ce.gov.br/",
|
|
40
|
+
DF: "https://www.receita.fazenda.df.gov.br/",
|
|
41
|
+
ES: "https://sitenet.es.gov.br/sefaz/",
|
|
42
|
+
GO: "http://www.sefaz.go.gov.br/ServicosAFA/ece.html",
|
|
43
|
+
MA: "https://www.sefaz.ma.gov.br/",
|
|
44
|
+
MG: "https://www.fazenda.mg.gov.br/empresas/Cadastro/cadastro/consultapublica.html",
|
|
45
|
+
MS: "https://www.sefaz.ms.gov.br/",
|
|
46
|
+
MT: "https://app1.sefaz.mt.gov.br/Sistema/legislacao/legislacaotribut.nsf/709f9c981a9d9f468425671300482be0/2217ddcf7a9b7cea03258c6c007324ba?OpenDocument=",
|
|
47
|
+
PA: "https://www.sefa.pa.gov.br/",
|
|
48
|
+
PB: "https://www.receita.pb.gov.br/",
|
|
49
|
+
PE: "https://www.sefaz.pe.gov.br/",
|
|
50
|
+
PI: "https://www.sefaz.pi.gov.br/",
|
|
51
|
+
PR: "https://www.fazenda.pr.gov.br/Pagina/calculo-digito-verificador",
|
|
52
|
+
RJ: "https://portal.fazenda.rj.gov.br/cadastro/",
|
|
53
|
+
RN: "https://www.set.rn.gov.br/",
|
|
54
|
+
RO: "https://www.sefin.ro.gov.br/",
|
|
55
|
+
RR: "https://www.sefaz.rr.gov.br/",
|
|
56
|
+
RS: "https://www.sefaz.rs.gov.br/",
|
|
57
|
+
SC: "https://sat.sef.sc.gov.br/",
|
|
58
|
+
SE: "https://www.sefaz.se.gov.br/",
|
|
59
|
+
SP: "https://portal.fazenda.sp.gov.br/servicos/icms/Paginas/sintegra-rotina-consistencia.aspx",
|
|
60
|
+
TO: "https://www.sefaz.to.gov.br/"
|
|
61
|
+
};
|
|
62
|
+
var IE_AC_PREFIX = "01";
|
|
63
|
+
var IE_AL_PREFIX = "24";
|
|
64
|
+
var IE_AP_PREFIX = "03";
|
|
65
|
+
var IE_DF_PREFIX = "07";
|
|
66
|
+
var IE_GO_PREFIXES = ["10", "11", "15", "20"];
|
|
67
|
+
var IE_MA_PREFIX = "12";
|
|
68
|
+
var IE_MS_PREFIX = "28";
|
|
69
|
+
var IE_MT_PREFIX = "13";
|
|
70
|
+
var IE_PA_PREFIX = "15";
|
|
71
|
+
var IE_RN_PREFIX = "20";
|
|
72
|
+
var IE_RR_PREFIX = "24";
|
|
73
|
+
var IE_TO_LEGACY_PREFIXES = ["01", "02", "03", "99"];
|
|
74
|
+
var IE_SP_LENGTH = 12;
|
|
75
|
+
var IE_SP_DV1_WEIGHTS = [1, 3, 4, 5, 6, 7, 8, 10];
|
|
76
|
+
var IE_SP_DV2_WEIGHTS = [3, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
77
|
+
var IE_SP_GOLDEN = "110042490114";
|
|
78
|
+
var IE_SP_GOLDEN_MASKED = "110.042.490.114";
|
|
79
|
+
var IE_SP_OFFICIAL_SOURCE_URL = IE_OFFICIAL_SOURCE_URLS.SP;
|
|
80
|
+
var IE_MT_CANONICAL_LENGTH = 9;
|
|
81
|
+
var IE_MT_LEGACY_LENGTH = 11;
|
|
82
|
+
var IE_MT_GOLDEN_LEGACY = "00130000019";
|
|
83
|
+
var IE_MT_GOLDEN_CANONICAL = "130000019";
|
|
84
|
+
var IE_MT_OFFICIAL_SOURCE_URL = IE_OFFICIAL_SOURCE_URLS.MT;
|
|
85
|
+
var IE_DF_LENGTH = 13;
|
|
86
|
+
var IE_DF_DV1_WEIGHTS = [4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
87
|
+
var IE_DF_DV2_WEIGHTS = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
88
|
+
var IE_DF_GOLDEN = "0730000100109";
|
|
89
|
+
var IE_DF_GOLDEN_MASKED = "073.00001.001-09";
|
|
90
|
+
var IE_DF_OFFICIAL_SOURCE_URL = IE_OFFICIAL_SOURCE_URLS.DF;
|
|
91
|
+
|
|
92
|
+
// src/core/inscricao-estadual/ie-common.ts
|
|
93
|
+
function stripIeDigits(input) {
|
|
94
|
+
return input.replace(/\D/g, "");
|
|
95
|
+
}
|
|
96
|
+
function ieFailure(uf, code, message) {
|
|
97
|
+
return { ok: false, code, message, uf };
|
|
98
|
+
}
|
|
99
|
+
function ieEmptyInput(uf) {
|
|
100
|
+
return { ok: false, code: "EMPTY_INPUT", message: "Inscri\xE7\xE3o Estadual input is empty", uf };
|
|
101
|
+
}
|
|
102
|
+
function ieSuccess(stripped, uf) {
|
|
103
|
+
return {
|
|
104
|
+
ok: true,
|
|
105
|
+
value: brandInscricaoEstadual(stripped),
|
|
106
|
+
uf,
|
|
107
|
+
format: "inscricao-estadual"
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function checkTrimmedEmpty(trimmed, uf) {
|
|
111
|
+
if (trimmed.length === 0) {
|
|
112
|
+
return ieEmptyInput(uf);
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function checkDigitChars(trimmed, uf, pattern = /^[0-9.\-\s/]+$/) {
|
|
117
|
+
if (!pattern.test(trimmed)) {
|
|
118
|
+
return ieFailure(uf, "INVALID_CHARACTER", `${uf} Inscri\xE7\xE3o Estadual contains invalid characters`);
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/core/inscricao-estadual/modulo-ie.ts
|
|
124
|
+
function computeIeSpCheckDigit(digits, weights) {
|
|
125
|
+
let sum = 0;
|
|
126
|
+
for (let i = 0; i < weights.length; i++) {
|
|
127
|
+
sum += Number(digits[i]) * weights[i];
|
|
128
|
+
}
|
|
129
|
+
const remainder = sum % 11;
|
|
130
|
+
return remainder === 10 ? 0 : remainder % 10;
|
|
131
|
+
}
|
|
132
|
+
function computeIeMtCheckDigit(digits10) {
|
|
133
|
+
let sum = 0;
|
|
134
|
+
const weights = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
135
|
+
for (let i = 0; i < 10; i++) {
|
|
136
|
+
sum += Number(digits10[i]) * weights[i];
|
|
137
|
+
}
|
|
138
|
+
const remainder = sum % 11;
|
|
139
|
+
return remainder <= 1 ? 0 : 11 - remainder;
|
|
140
|
+
}
|
|
141
|
+
function computeIeDfCheckDigit(digits, weights, includeDv1 = false, dv1 = 0) {
|
|
142
|
+
let sum = 0;
|
|
143
|
+
const digitCount = includeDv1 ? 11 : digits.length;
|
|
144
|
+
for (let i = 0; i < digitCount; i++) {
|
|
145
|
+
sum += Number(digits[i]) * weights[i];
|
|
146
|
+
}
|
|
147
|
+
if (includeDv1) {
|
|
148
|
+
sum += dv1 * weights[11];
|
|
149
|
+
}
|
|
150
|
+
const remainder = sum % 11;
|
|
151
|
+
return remainder <= 1 ? 0 : 11 - remainder;
|
|
152
|
+
}
|
|
153
|
+
function computeIeCeCheckDigit(body8) {
|
|
154
|
+
let weight = 9;
|
|
155
|
+
let sum = 0;
|
|
156
|
+
for (let i = 0; i < 8; i++) {
|
|
157
|
+
sum += Number(body8[i]) * weight;
|
|
158
|
+
weight--;
|
|
159
|
+
}
|
|
160
|
+
const rest = sum % 11;
|
|
161
|
+
let digit = 11 - rest;
|
|
162
|
+
if (digit >= 10) {
|
|
163
|
+
digit = 0;
|
|
164
|
+
}
|
|
165
|
+
return digit;
|
|
166
|
+
}
|
|
167
|
+
function computeIeAlCheckDigit(body8) {
|
|
168
|
+
let weight = 9;
|
|
169
|
+
let sum = 0;
|
|
170
|
+
for (let i = 0; i < 8; i++) {
|
|
171
|
+
sum += Number(body8[i]) * weight;
|
|
172
|
+
weight--;
|
|
173
|
+
}
|
|
174
|
+
const product = sum * 10;
|
|
175
|
+
let digit = product - Math.floor(product / 11) * 11;
|
|
176
|
+
if (digit >= 10) {
|
|
177
|
+
digit = 0;
|
|
178
|
+
}
|
|
179
|
+
return digit;
|
|
180
|
+
}
|
|
181
|
+
function computeIeAmCheckDigit(body8) {
|
|
182
|
+
let weight = 9;
|
|
183
|
+
let sum = 0;
|
|
184
|
+
for (let i = 0; i < 8; i++) {
|
|
185
|
+
sum += Number(body8[i]) * weight;
|
|
186
|
+
weight--;
|
|
187
|
+
}
|
|
188
|
+
if (sum < 11) {
|
|
189
|
+
return 11 - sum;
|
|
190
|
+
}
|
|
191
|
+
const remainder = sum % 11;
|
|
192
|
+
let digit = 11 - remainder;
|
|
193
|
+
if (digit >= 10) {
|
|
194
|
+
digit = 0;
|
|
195
|
+
}
|
|
196
|
+
return digit;
|
|
197
|
+
}
|
|
198
|
+
function computeIePrStyleCheckDigit(body) {
|
|
199
|
+
let weight = body.length - 5;
|
|
200
|
+
let sum = 0;
|
|
201
|
+
for (let i = 0; i < body.length; i++) {
|
|
202
|
+
sum += Number(body[i]) * weight;
|
|
203
|
+
weight--;
|
|
204
|
+
if (weight === 1) {
|
|
205
|
+
weight = 7;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const rest = sum % 11;
|
|
209
|
+
let digit = 11 - rest;
|
|
210
|
+
if (digit >= 10) {
|
|
211
|
+
digit = 0;
|
|
212
|
+
}
|
|
213
|
+
return digit;
|
|
214
|
+
}
|
|
215
|
+
function computeIeAcCheckDigit(body) {
|
|
216
|
+
let weight = body.length - 7;
|
|
217
|
+
let sum = 0;
|
|
218
|
+
for (let i = 0; i < body.length; i++) {
|
|
219
|
+
sum += Number(body[i]) * weight;
|
|
220
|
+
weight--;
|
|
221
|
+
if (weight === 1) {
|
|
222
|
+
weight = 9;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const rest = sum % 11;
|
|
226
|
+
let digit = 11 - rest;
|
|
227
|
+
if (digit >= 10) {
|
|
228
|
+
digit = 0;
|
|
229
|
+
}
|
|
230
|
+
return digit;
|
|
231
|
+
}
|
|
232
|
+
function computeIeBaModule(ie) {
|
|
233
|
+
const refIndex = ie.length === 9 ? 1 : 0;
|
|
234
|
+
const refDigit = Number(ie[refIndex]);
|
|
235
|
+
const mod10Digits = [0, 1, 2, 3, 4, 5, 8];
|
|
236
|
+
return mod10Digits.includes(refDigit) ? 10 : 11;
|
|
237
|
+
}
|
|
238
|
+
function computeIeBaCheckDigit(body, mod) {
|
|
239
|
+
let weight = body.length + 1;
|
|
240
|
+
let sum = 0;
|
|
241
|
+
for (let i = 0; i < body.length; i++) {
|
|
242
|
+
sum += Number(body[i]) * weight;
|
|
243
|
+
weight--;
|
|
244
|
+
}
|
|
245
|
+
const rest = sum % mod;
|
|
246
|
+
let digit = mod - rest;
|
|
247
|
+
if (digit >= 10) {
|
|
248
|
+
digit = 0;
|
|
249
|
+
}
|
|
250
|
+
return digit;
|
|
251
|
+
}
|
|
252
|
+
function computeIePeCheckDigit(body) {
|
|
253
|
+
let weight = body.length + 1;
|
|
254
|
+
let sum = 0;
|
|
255
|
+
for (let i = 0; i < body.length; i++) {
|
|
256
|
+
sum += Number(body[i]) * weight;
|
|
257
|
+
weight--;
|
|
258
|
+
}
|
|
259
|
+
const rest = sum % 11;
|
|
260
|
+
let digit = 11 - rest;
|
|
261
|
+
if (digit >= 10) {
|
|
262
|
+
digit = 0;
|
|
263
|
+
}
|
|
264
|
+
return digit;
|
|
265
|
+
}
|
|
266
|
+
function computeIeCyclicMod11CheckDigit(body, startWeight, resetWeight) {
|
|
267
|
+
let weight = startWeight;
|
|
268
|
+
let sum = 0;
|
|
269
|
+
for (let i = 0; i < body.length; i++) {
|
|
270
|
+
sum += Number(body[i]) * weight;
|
|
271
|
+
weight--;
|
|
272
|
+
if (weight === 1) {
|
|
273
|
+
weight = resetWeight;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const rest = sum % 11;
|
|
277
|
+
let digit = 11 - rest;
|
|
278
|
+
if (digit >= 10) {
|
|
279
|
+
digit = 0;
|
|
280
|
+
}
|
|
281
|
+
return digit;
|
|
282
|
+
}
|
|
283
|
+
function computeIeRoCheckDigit(body) {
|
|
284
|
+
let weight = 6;
|
|
285
|
+
let sum = 0;
|
|
286
|
+
for (let i = 0; i < body.length; i++) {
|
|
287
|
+
sum += Number(body[i]) * weight;
|
|
288
|
+
weight--;
|
|
289
|
+
if (weight === 1) {
|
|
290
|
+
weight = 9;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const rest = sum % 11;
|
|
294
|
+
let digit = 11 - rest;
|
|
295
|
+
if (digit >= 10) {
|
|
296
|
+
digit -= 10;
|
|
297
|
+
}
|
|
298
|
+
return digit;
|
|
299
|
+
}
|
|
300
|
+
function computeIeGoCheckDigit(body8) {
|
|
301
|
+
let weight = 9;
|
|
302
|
+
let sum = 0;
|
|
303
|
+
for (let i = 0; i < 8; i++) {
|
|
304
|
+
sum += Number(body8[i]) * weight;
|
|
305
|
+
weight--;
|
|
306
|
+
}
|
|
307
|
+
const rest = sum % 11;
|
|
308
|
+
let digit = 11 - rest;
|
|
309
|
+
const bodyInt = Number(body8);
|
|
310
|
+
if (digit >= 10) {
|
|
311
|
+
if (digit === 11 && bodyInt >= 10103105 && bodyInt <= 10119997) {
|
|
312
|
+
digit = 1;
|
|
313
|
+
} else {
|
|
314
|
+
digit = 0;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return digit;
|
|
318
|
+
}
|
|
319
|
+
function computeIeApCheckDigit(body8) {
|
|
320
|
+
const bodyInt = Number(body8);
|
|
321
|
+
let p = 0;
|
|
322
|
+
let d = 0;
|
|
323
|
+
if (bodyInt >= 3000001 && bodyInt <= 3017e3) {
|
|
324
|
+
p = 5;
|
|
325
|
+
d = 0;
|
|
326
|
+
} else if (bodyInt >= 3017001 && bodyInt <= 3019022) {
|
|
327
|
+
p = 9;
|
|
328
|
+
d = 1;
|
|
329
|
+
}
|
|
330
|
+
let weight = 9;
|
|
331
|
+
let sum = p;
|
|
332
|
+
for (let i = 0; i < 8; i++) {
|
|
333
|
+
sum += Number(body8[i]) * weight;
|
|
334
|
+
weight--;
|
|
335
|
+
}
|
|
336
|
+
let digit = 11 - sum % 11;
|
|
337
|
+
if (digit === 10) {
|
|
338
|
+
digit = 0;
|
|
339
|
+
} else if (digit === 11) {
|
|
340
|
+
digit = d;
|
|
341
|
+
}
|
|
342
|
+
return digit;
|
|
343
|
+
}
|
|
344
|
+
function computeIeRrCheckDigit(body8) {
|
|
345
|
+
let weight = 1;
|
|
346
|
+
let sum = 0;
|
|
347
|
+
for (let i = 0; i < 8; i++) {
|
|
348
|
+
sum += Number(body8[i]) * weight;
|
|
349
|
+
weight++;
|
|
350
|
+
}
|
|
351
|
+
return sum % 9;
|
|
352
|
+
}
|
|
353
|
+
function computeIeToCheckDigit(body) {
|
|
354
|
+
let weight = 9;
|
|
355
|
+
let sum = 0;
|
|
356
|
+
for (let i = 0; i < body.length; i++) {
|
|
357
|
+
sum += Number(body[i]) * weight;
|
|
358
|
+
weight--;
|
|
359
|
+
}
|
|
360
|
+
const rest = sum % 11;
|
|
361
|
+
if (rest < 2) {
|
|
362
|
+
return 0;
|
|
363
|
+
}
|
|
364
|
+
return 11 - rest;
|
|
365
|
+
}
|
|
366
|
+
function computeIeMgFirstCheckDigit(body11) {
|
|
367
|
+
const bodyWithZero = `${body11.slice(0, 3)}0${body11.slice(3)}`;
|
|
368
|
+
let weightedSum = "";
|
|
369
|
+
for (let i = 0; i < bodyWithZero.length; i++) {
|
|
370
|
+
const w = (i + 1) % 2 === 0 ? 2 : 1;
|
|
371
|
+
weightedSum += (Number(bodyWithZero[i]) * w).toString();
|
|
372
|
+
}
|
|
373
|
+
let sum = 0;
|
|
374
|
+
for (let i = 0; i < weightedSum.length; i++) {
|
|
375
|
+
sum += Number(weightedSum[i]);
|
|
376
|
+
}
|
|
377
|
+
const lastDigit = Number(sum.toString().slice(-1));
|
|
378
|
+
return lastDigit === 0 ? 0 : 10 - lastDigit;
|
|
379
|
+
}
|
|
380
|
+
function computeIeMgSecondCheckDigit(body12) {
|
|
381
|
+
let weight = 3;
|
|
382
|
+
let sum = 0;
|
|
383
|
+
for (let i = 0; i < body12.length; i++) {
|
|
384
|
+
sum += Number(body12[i]) * weight;
|
|
385
|
+
weight--;
|
|
386
|
+
if (weight === 1) {
|
|
387
|
+
weight = 11;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
const rest = sum % 11;
|
|
391
|
+
let digit = 11 - rest;
|
|
392
|
+
if (digit >= 10) {
|
|
393
|
+
digit = 0;
|
|
394
|
+
}
|
|
395
|
+
return digit;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/core/inscricao-estadual/ac.ts
|
|
399
|
+
var UF = "AC";
|
|
400
|
+
var LENGTH = 13;
|
|
401
|
+
function stripIeAc(input) {
|
|
402
|
+
return stripIeDigits(input);
|
|
403
|
+
}
|
|
404
|
+
function validateIeAc(input) {
|
|
405
|
+
const trimmed = input.trim();
|
|
406
|
+
const empty = checkTrimmedEmpty(trimmed, UF);
|
|
407
|
+
if (empty) return empty;
|
|
408
|
+
const invalidChar = checkDigitChars(trimmed, UF);
|
|
409
|
+
if (invalidChar) return invalidChar;
|
|
410
|
+
const stripped = stripIeAc(trimmed);
|
|
411
|
+
if (stripped.length !== LENGTH) {
|
|
412
|
+
return ieFailure(UF, "INVALID_LENGTH", `AC Inscri\xE7\xE3o Estadual must have ${LENGTH} digits after normalization`);
|
|
413
|
+
}
|
|
414
|
+
if (!stripped.startsWith(IE_AC_PREFIX)) {
|
|
415
|
+
return ieFailure(UF, "UNSUPPORTED_FORMAT", "AC Inscri\xE7\xE3o Estadual must start with prefix 01");
|
|
416
|
+
}
|
|
417
|
+
const body = stripped.slice(0, 11);
|
|
418
|
+
const firstDig = computeIeAcCheckDigit(body);
|
|
419
|
+
const secondDig = computeIeAcCheckDigit(body + String(firstDig));
|
|
420
|
+
const checkDigits = `${firstDig}${secondDig}`;
|
|
421
|
+
if (stripped.slice(-2) !== checkDigits) {
|
|
422
|
+
return ieFailure(UF, "INVALID_CHECK_DIGIT", "AC Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
423
|
+
}
|
|
424
|
+
return ieSuccess(stripped, UF);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// src/core/inscricao-estadual/al.ts
|
|
428
|
+
var UF2 = "AL";
|
|
429
|
+
var LENGTH2 = 9;
|
|
430
|
+
function stripIeAl(input) {
|
|
431
|
+
return stripIeDigits(input);
|
|
432
|
+
}
|
|
433
|
+
function validateIeAl(input) {
|
|
434
|
+
const trimmed = input.trim();
|
|
435
|
+
const empty = checkTrimmedEmpty(trimmed, UF2);
|
|
436
|
+
if (empty) return empty;
|
|
437
|
+
const invalidChar = checkDigitChars(trimmed, UF2);
|
|
438
|
+
if (invalidChar) return invalidChar;
|
|
439
|
+
const stripped = stripIeAl(trimmed);
|
|
440
|
+
if (stripped.length !== LENGTH2) {
|
|
441
|
+
return ieFailure(UF2, "INVALID_LENGTH", `AL Inscri\xE7\xE3o Estadual must have ${LENGTH2} digits after normalization`);
|
|
442
|
+
}
|
|
443
|
+
if (!stripped.startsWith(IE_AL_PREFIX)) {
|
|
444
|
+
return ieFailure(UF2, "UNSUPPORTED_FORMAT", "AL Inscri\xE7\xE3o Estadual must start with prefix 24");
|
|
445
|
+
}
|
|
446
|
+
const body = stripped.slice(0, 8);
|
|
447
|
+
const expected = computeIeAlCheckDigit(body);
|
|
448
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
449
|
+
return ieFailure(UF2, "INVALID_CHECK_DIGIT", "AL Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
450
|
+
}
|
|
451
|
+
return ieSuccess(stripped, UF2);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// src/core/inscricao-estadual/am.ts
|
|
455
|
+
var UF3 = "AM";
|
|
456
|
+
var LENGTH3 = 9;
|
|
457
|
+
function stripIeAm(input) {
|
|
458
|
+
return stripIeDigits(input);
|
|
459
|
+
}
|
|
460
|
+
function validateIeAm(input) {
|
|
461
|
+
const trimmed = input.trim();
|
|
462
|
+
const empty = checkTrimmedEmpty(trimmed, UF3);
|
|
463
|
+
if (empty) return empty;
|
|
464
|
+
const invalidChar = checkDigitChars(trimmed, UF3);
|
|
465
|
+
if (invalidChar) return invalidChar;
|
|
466
|
+
const stripped = stripIeAm(trimmed);
|
|
467
|
+
if (stripped.length !== LENGTH3) {
|
|
468
|
+
return ieFailure(UF3, "INVALID_LENGTH", `AM Inscri\xE7\xE3o Estadual must have ${LENGTH3} digits after normalization`);
|
|
469
|
+
}
|
|
470
|
+
const body = stripped.slice(0, 8);
|
|
471
|
+
const expected = computeIeAmCheckDigit(body);
|
|
472
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
473
|
+
return ieFailure(UF3, "INVALID_CHECK_DIGIT", "AM Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
474
|
+
}
|
|
475
|
+
return ieSuccess(stripped, UF3);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/core/inscricao-estadual/ap.ts
|
|
479
|
+
var UF4 = "AP";
|
|
480
|
+
var LENGTH4 = 9;
|
|
481
|
+
function stripIeAp(input) {
|
|
482
|
+
return stripIeDigits(input);
|
|
483
|
+
}
|
|
484
|
+
function validateIeAp(input) {
|
|
485
|
+
const trimmed = input.trim();
|
|
486
|
+
const empty = checkTrimmedEmpty(trimmed, UF4);
|
|
487
|
+
if (empty) return empty;
|
|
488
|
+
const invalidChar = checkDigitChars(trimmed, UF4);
|
|
489
|
+
if (invalidChar) return invalidChar;
|
|
490
|
+
const stripped = stripIeAp(trimmed);
|
|
491
|
+
if (stripped.length !== LENGTH4) {
|
|
492
|
+
return ieFailure(UF4, "INVALID_LENGTH", `AP Inscri\xE7\xE3o Estadual must have ${LENGTH4} digits after normalization`);
|
|
493
|
+
}
|
|
494
|
+
if (!stripped.startsWith(IE_AP_PREFIX)) {
|
|
495
|
+
return ieFailure(UF4, "UNSUPPORTED_FORMAT", "AP Inscri\xE7\xE3o Estadual must start with prefix 03");
|
|
496
|
+
}
|
|
497
|
+
const body = stripped.slice(0, 8);
|
|
498
|
+
const expected = computeIeApCheckDigit(body);
|
|
499
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
500
|
+
return ieFailure(UF4, "INVALID_CHECK_DIGIT", "AP Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
501
|
+
}
|
|
502
|
+
return ieSuccess(stripped, UF4);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/core/inscricao-estadual/ba.ts
|
|
506
|
+
var UF5 = "BA";
|
|
507
|
+
function stripIeBa(input) {
|
|
508
|
+
return stripIeDigits(input);
|
|
509
|
+
}
|
|
510
|
+
function validateIeBa(input) {
|
|
511
|
+
const trimmed = input.trim();
|
|
512
|
+
const empty = checkTrimmedEmpty(trimmed, UF5);
|
|
513
|
+
if (empty) return empty;
|
|
514
|
+
const invalidChar = checkDigitChars(trimmed, UF5);
|
|
515
|
+
if (invalidChar) return invalidChar;
|
|
516
|
+
const stripped = stripIeBa(trimmed);
|
|
517
|
+
if (stripped.length !== 8 && stripped.length !== 9) {
|
|
518
|
+
return ieFailure(UF5, "INVALID_LENGTH", "BA Inscri\xE7\xE3o Estadual must have 8 or 9 digits after normalization");
|
|
519
|
+
}
|
|
520
|
+
const body = stripped.slice(0, stripped.length - 2);
|
|
521
|
+
const mod = computeIeBaModule(stripped);
|
|
522
|
+
const secondDig = computeIeBaCheckDigit(body, mod);
|
|
523
|
+
const firstDig = computeIeBaCheckDigit(body + String(secondDig), mod);
|
|
524
|
+
const checkDigits = `${firstDig}${secondDig}`;
|
|
525
|
+
if (stripped.slice(-2) !== checkDigits) {
|
|
526
|
+
return ieFailure(UF5, "INVALID_CHECK_DIGIT", "BA Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
527
|
+
}
|
|
528
|
+
return ieSuccess(stripped, UF5);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/core/inscricao-estadual/ce.ts
|
|
532
|
+
var UF6 = "CE";
|
|
533
|
+
var LENGTH5 = 9;
|
|
534
|
+
function stripIeCe(input) {
|
|
535
|
+
return stripIeDigits(input);
|
|
536
|
+
}
|
|
537
|
+
function validateIeCe(input) {
|
|
538
|
+
const trimmed = input.trim();
|
|
539
|
+
const empty = checkTrimmedEmpty(trimmed, UF6);
|
|
540
|
+
if (empty) return empty;
|
|
541
|
+
const invalidChar = checkDigitChars(trimmed, UF6);
|
|
542
|
+
if (invalidChar) return invalidChar;
|
|
543
|
+
const stripped = stripIeCe(trimmed);
|
|
544
|
+
if (stripped.length !== LENGTH5) {
|
|
545
|
+
return ieFailure(UF6, "INVALID_LENGTH", `CE Inscri\xE7\xE3o Estadual must have ${LENGTH5} digits after normalization`);
|
|
546
|
+
}
|
|
547
|
+
const body = stripped.slice(0, 8);
|
|
548
|
+
const expected = computeIeCeCheckDigit(body);
|
|
549
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
550
|
+
return ieFailure(UF6, "INVALID_CHECK_DIGIT", "CE Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
551
|
+
}
|
|
552
|
+
return ieSuccess(stripped, UF6);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/core/inscricao-estadual/df.ts
|
|
556
|
+
var DF_MASK_PATTERN = /^[0-9.-]+$/;
|
|
557
|
+
function failure(code, message) {
|
|
558
|
+
return { ok: false, code, message, uf: "DF" };
|
|
559
|
+
}
|
|
560
|
+
function stripIeDf(input) {
|
|
561
|
+
return input.replace(/\D/g, "");
|
|
562
|
+
}
|
|
563
|
+
function validateIeDf(input) {
|
|
564
|
+
const trimmed = input.trim();
|
|
565
|
+
if (trimmed.length === 0) {
|
|
566
|
+
return { ok: false, code: "EMPTY_INPUT", message: "Inscri\xE7\xE3o Estadual input is empty", uf: "DF" };
|
|
567
|
+
}
|
|
568
|
+
if (!DF_MASK_PATTERN.test(trimmed)) {
|
|
569
|
+
return failure("INVALID_CHARACTER", "DF Inscri\xE7\xE3o Estadual contains invalid characters");
|
|
570
|
+
}
|
|
571
|
+
const stripped = stripIeDf(trimmed);
|
|
572
|
+
if (stripped.length === 12) {
|
|
573
|
+
return failure("INVALID_LENGTH", "DF Inscri\xE7\xE3o Estadual legacy 12-digit format is not supported; use 13 digits");
|
|
574
|
+
}
|
|
575
|
+
if (stripped.length !== IE_DF_LENGTH) {
|
|
576
|
+
return failure("INVALID_LENGTH", `DF Inscri\xE7\xE3o Estadual must have ${IE_DF_LENGTH} digits after normalization`);
|
|
577
|
+
}
|
|
578
|
+
if (!stripped.startsWith(IE_DF_PREFIX)) {
|
|
579
|
+
return failure("UNSUPPORTED_FORMAT", "DF Inscri\xE7\xE3o Estadual must start with prefix 07");
|
|
580
|
+
}
|
|
581
|
+
const dv1 = computeIeDfCheckDigit(stripped.slice(0, 11), IE_DF_DV1_WEIGHTS);
|
|
582
|
+
const dv2 = computeIeDfCheckDigit(stripped.slice(0, 11), IE_DF_DV2_WEIGHTS, true, dv1);
|
|
583
|
+
if (Number(stripped.charAt(11)) !== dv1 || Number(stripped.charAt(12)) !== dv2) {
|
|
584
|
+
return failure("INVALID_CHECK_DIGIT", "DF Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
ok: true,
|
|
588
|
+
value: brandInscricaoEstadual(stripped),
|
|
589
|
+
uf: "DF",
|
|
590
|
+
format: "inscricao-estadual"
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// src/core/inscricao-estadual/es.ts
|
|
595
|
+
var UF7 = "ES";
|
|
596
|
+
function stripIeEs(input) {
|
|
597
|
+
return stripIeDigits(input);
|
|
598
|
+
}
|
|
599
|
+
function validateIeEs(input) {
|
|
600
|
+
const trimmed = input.trim();
|
|
601
|
+
const empty = checkTrimmedEmpty(trimmed, UF7);
|
|
602
|
+
if (empty) return empty;
|
|
603
|
+
const invalidChar = checkDigitChars(trimmed, UF7);
|
|
604
|
+
if (invalidChar) return invalidChar;
|
|
605
|
+
const ceResult = validateIeCe(stripIeEs(trimmed));
|
|
606
|
+
if (!ceResult.ok) {
|
|
607
|
+
return { ...ceResult, uf: UF7 };
|
|
608
|
+
}
|
|
609
|
+
return { ...ceResult, uf: UF7 };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// src/core/inscricao-estadual/go.ts
|
|
613
|
+
var UF8 = "GO";
|
|
614
|
+
var LENGTH6 = 9;
|
|
615
|
+
function stripIeGo(input) {
|
|
616
|
+
return stripIeDigits(input);
|
|
617
|
+
}
|
|
618
|
+
function validateIeGo(input) {
|
|
619
|
+
const trimmed = input.trim();
|
|
620
|
+
const empty = checkTrimmedEmpty(trimmed, UF8);
|
|
621
|
+
if (empty) return empty;
|
|
622
|
+
const invalidChar = checkDigitChars(trimmed, UF8);
|
|
623
|
+
if (invalidChar) return invalidChar;
|
|
624
|
+
const stripped = stripIeGo(trimmed);
|
|
625
|
+
if (stripped.length !== LENGTH6) {
|
|
626
|
+
return ieFailure(UF8, "INVALID_LENGTH", `GO Inscri\xE7\xE3o Estadual must have ${LENGTH6} digits after normalization`);
|
|
627
|
+
}
|
|
628
|
+
const prefix = stripped.slice(0, 2);
|
|
629
|
+
if (!IE_GO_PREFIXES.includes(prefix)) {
|
|
630
|
+
return ieFailure(UF8, "UNSUPPORTED_FORMAT", "GO Inscri\xE7\xE3o Estadual prefix is not supported");
|
|
631
|
+
}
|
|
632
|
+
const body = stripped.slice(0, 8);
|
|
633
|
+
const expected = computeIeGoCheckDigit(body);
|
|
634
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
635
|
+
return ieFailure(UF8, "INVALID_CHECK_DIGIT", "GO Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
636
|
+
}
|
|
637
|
+
return ieSuccess(stripped, UF8);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// src/core/inscricao-estadual/ma.ts
|
|
641
|
+
var UF9 = "MA";
|
|
642
|
+
function stripIeMa(input) {
|
|
643
|
+
return stripIeDigits(input);
|
|
644
|
+
}
|
|
645
|
+
function validateIeMa(input) {
|
|
646
|
+
const trimmed = input.trim();
|
|
647
|
+
const empty = checkTrimmedEmpty(trimmed, UF9);
|
|
648
|
+
if (empty) return empty;
|
|
649
|
+
const invalidChar = checkDigitChars(trimmed, UF9);
|
|
650
|
+
if (invalidChar) return invalidChar;
|
|
651
|
+
const stripped = stripIeMa(trimmed);
|
|
652
|
+
if (!stripped.startsWith(IE_MA_PREFIX)) {
|
|
653
|
+
return ieFailure(UF9, "UNSUPPORTED_FORMAT", "MA Inscri\xE7\xE3o Estadual must start with prefix 12");
|
|
654
|
+
}
|
|
655
|
+
const ceResult = validateIeCe(stripped);
|
|
656
|
+
if (!ceResult.ok) {
|
|
657
|
+
return { ...ceResult, uf: UF9 };
|
|
658
|
+
}
|
|
659
|
+
return { ...ceResult, uf: UF9 };
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/core/inscricao-estadual/mg.ts
|
|
663
|
+
var UF10 = "MG";
|
|
664
|
+
var LENGTH7 = 13;
|
|
665
|
+
function stripIeMg(input) {
|
|
666
|
+
return stripIeDigits(input);
|
|
667
|
+
}
|
|
668
|
+
function validateIeMg(input) {
|
|
669
|
+
const trimmed = input.trim();
|
|
670
|
+
const empty = checkTrimmedEmpty(trimmed, UF10);
|
|
671
|
+
if (empty) return empty;
|
|
672
|
+
const invalidChar = checkDigitChars(trimmed, UF10);
|
|
673
|
+
if (invalidChar) return invalidChar;
|
|
674
|
+
const stripped = stripIeMg(trimmed);
|
|
675
|
+
if (stripped.length !== LENGTH7) {
|
|
676
|
+
return ieFailure(UF10, "INVALID_LENGTH", `MG Inscri\xE7\xE3o Estadual must have ${LENGTH7} digits after normalization`);
|
|
677
|
+
}
|
|
678
|
+
const body = stripped.slice(0, 11);
|
|
679
|
+
const firstDig = computeIeMgFirstCheckDigit(body);
|
|
680
|
+
const secondDig = computeIeMgSecondCheckDigit(body + String(firstDig));
|
|
681
|
+
const checkDigits = `${firstDig}${secondDig}`;
|
|
682
|
+
if (stripped.slice(-2) !== checkDigits) {
|
|
683
|
+
return ieFailure(UF10, "INVALID_CHECK_DIGIT", "MG Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
684
|
+
}
|
|
685
|
+
return ieSuccess(stripped, UF10);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
// src/core/inscricao-estadual/ms.ts
|
|
689
|
+
var UF11 = "MS";
|
|
690
|
+
function stripIeMs(input) {
|
|
691
|
+
return stripIeDigits(input);
|
|
692
|
+
}
|
|
693
|
+
function validateIeMs(input) {
|
|
694
|
+
const trimmed = input.trim();
|
|
695
|
+
const empty = checkTrimmedEmpty(trimmed, UF11);
|
|
696
|
+
if (empty) return empty;
|
|
697
|
+
const invalidChar = checkDigitChars(trimmed, UF11);
|
|
698
|
+
if (invalidChar) return invalidChar;
|
|
699
|
+
const stripped = stripIeMs(trimmed);
|
|
700
|
+
if (!stripped.startsWith(IE_MS_PREFIX)) {
|
|
701
|
+
return ieFailure(UF11, "UNSUPPORTED_FORMAT", "MS Inscri\xE7\xE3o Estadual must start with prefix 28");
|
|
702
|
+
}
|
|
703
|
+
const ceResult = validateIeCe(stripped);
|
|
704
|
+
if (!ceResult.ok) {
|
|
705
|
+
return { ...ceResult, uf: UF11 };
|
|
706
|
+
}
|
|
707
|
+
return { ...ceResult, uf: UF11 };
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// src/core/inscricao-estadual/mt.ts
|
|
711
|
+
function failure2(code, message) {
|
|
712
|
+
return { ok: false, code, message, uf: "MT" };
|
|
713
|
+
}
|
|
714
|
+
function stripIeMt(input) {
|
|
715
|
+
return input.replace(/\D/g, "");
|
|
716
|
+
}
|
|
717
|
+
function normalizeMtToCanonical(padded11) {
|
|
718
|
+
const trimmed = padded11.replace(/^0+/, "");
|
|
719
|
+
return trimmed.length === IE_MT_CANONICAL_LENGTH ? trimmed : padded11.slice(-IE_MT_CANONICAL_LENGTH);
|
|
720
|
+
}
|
|
721
|
+
function validateIeMt(input) {
|
|
722
|
+
const trimmed = input.trim();
|
|
723
|
+
if (trimmed.length === 0) {
|
|
724
|
+
return { ok: false, code: "EMPTY_INPUT", message: "Inscri\xE7\xE3o Estadual input is empty", uf: "MT" };
|
|
725
|
+
}
|
|
726
|
+
if (/[^0-9.\-\s]/.test(trimmed)) {
|
|
727
|
+
return failure2("INVALID_CHARACTER", "MT Inscri\xE7\xE3o Estadual contains invalid characters");
|
|
728
|
+
}
|
|
729
|
+
const stripped = stripIeMt(trimmed);
|
|
730
|
+
if (stripped.length < IE_MT_CANONICAL_LENGTH || stripped.length > IE_MT_LEGACY_LENGTH) {
|
|
731
|
+
return failure2(
|
|
732
|
+
"INVALID_LENGTH",
|
|
733
|
+
`MT Inscri\xE7\xE3o Estadual must have ${IE_MT_CANONICAL_LENGTH} or ${IE_MT_LEGACY_LENGTH} digits after normalization`
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
const padded = stripped.length === IE_MT_LEGACY_LENGTH ? stripped : stripped.padStart(IE_MT_LEGACY_LENGTH, "0");
|
|
737
|
+
const canonical = normalizeMtToCanonical(padded);
|
|
738
|
+
if (!canonical.startsWith(IE_MT_PREFIX)) {
|
|
739
|
+
return failure2("UNSUPPORTED_FORMAT", "MT Inscri\xE7\xE3o Estadual must start with prefix 13");
|
|
740
|
+
}
|
|
741
|
+
const expectedDv = computeIeMtCheckDigit(padded.slice(0, 10));
|
|
742
|
+
if (Number(padded.charAt(10)) !== expectedDv) {
|
|
743
|
+
return failure2("INVALID_CHECK_DIGIT", "MT Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
ok: true,
|
|
747
|
+
value: brandInscricaoEstadual(canonical),
|
|
748
|
+
uf: "MT",
|
|
749
|
+
format: "inscricao-estadual"
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/core/inscricao-estadual/mask.ts
|
|
754
|
+
function applyIeSpMask(stripped) {
|
|
755
|
+
if (stripped.length !== IE_SP_LENGTH) {
|
|
756
|
+
throw new Error("SP IE must have exactly 12 digits to apply mask");
|
|
757
|
+
}
|
|
758
|
+
return `${stripped.slice(0, 3)}.${stripped.slice(3, 6)}.${stripped.slice(6, 9)}.${stripped.slice(9)}`;
|
|
759
|
+
}
|
|
760
|
+
function applyIeDfMask(stripped) {
|
|
761
|
+
if (stripped.length !== IE_DF_LENGTH) {
|
|
762
|
+
throw new Error("DF IE must have exactly 13 digits to apply mask");
|
|
763
|
+
}
|
|
764
|
+
return `${stripped.slice(0, 3)}.${stripped.slice(3, 8)}.${stripped.slice(8, 11)}-${stripped.slice(11)}`;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// src/core/inscricao-estadual/pa.ts
|
|
768
|
+
var UF12 = "PA";
|
|
769
|
+
function stripIePa(input) {
|
|
770
|
+
return stripIeDigits(input);
|
|
771
|
+
}
|
|
772
|
+
function validateIePa(input) {
|
|
773
|
+
const trimmed = input.trim();
|
|
774
|
+
const empty = checkTrimmedEmpty(trimmed, UF12);
|
|
775
|
+
if (empty) return empty;
|
|
776
|
+
const invalidChar = checkDigitChars(trimmed, UF12);
|
|
777
|
+
if (invalidChar) return invalidChar;
|
|
778
|
+
const stripped = stripIePa(trimmed);
|
|
779
|
+
if (!stripped.startsWith(IE_PA_PREFIX)) {
|
|
780
|
+
return ieFailure(UF12, "UNSUPPORTED_FORMAT", "PA Inscri\xE7\xE3o Estadual must start with prefix 15");
|
|
781
|
+
}
|
|
782
|
+
const ceResult = validateIeCe(stripped);
|
|
783
|
+
if (!ceResult.ok) {
|
|
784
|
+
return { ...ceResult, uf: UF12 };
|
|
785
|
+
}
|
|
786
|
+
return { ...ceResult, uf: UF12 };
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// src/core/inscricao-estadual/pb.ts
|
|
790
|
+
var UF13 = "PB";
|
|
791
|
+
function stripIePb(input) {
|
|
792
|
+
return stripIeDigits(input);
|
|
793
|
+
}
|
|
794
|
+
function validateIePb(input) {
|
|
795
|
+
const trimmed = input.trim();
|
|
796
|
+
const empty = checkTrimmedEmpty(trimmed, UF13);
|
|
797
|
+
if (empty) return empty;
|
|
798
|
+
const invalidChar = checkDigitChars(trimmed, UF13);
|
|
799
|
+
if (invalidChar) return invalidChar;
|
|
800
|
+
const ceResult = validateIeCe(stripIePb(trimmed));
|
|
801
|
+
if (!ceResult.ok) return { ...ceResult, uf: UF13 };
|
|
802
|
+
return { ...ceResult, uf: UF13 };
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// src/core/inscricao-estadual/pe.ts
|
|
806
|
+
var UF14 = "PE";
|
|
807
|
+
var LENGTH8 = 9;
|
|
808
|
+
function stripIePe(input) {
|
|
809
|
+
return stripIeDigits(input);
|
|
810
|
+
}
|
|
811
|
+
function validateIePe(input) {
|
|
812
|
+
const trimmed = input.trim();
|
|
813
|
+
const empty = checkTrimmedEmpty(trimmed, UF14);
|
|
814
|
+
if (empty) return empty;
|
|
815
|
+
const invalidChar = checkDigitChars(trimmed, UF14);
|
|
816
|
+
if (invalidChar) return invalidChar;
|
|
817
|
+
const stripped = stripIePe(trimmed);
|
|
818
|
+
if (stripped.length !== LENGTH8) {
|
|
819
|
+
return ieFailure(UF14, "INVALID_LENGTH", `PE Inscri\xE7\xE3o Estadual must have ${LENGTH8} digits after normalization`);
|
|
820
|
+
}
|
|
821
|
+
const body = stripped.slice(0, 7);
|
|
822
|
+
const firstDig = computeIePeCheckDigit(body);
|
|
823
|
+
const secondDig = computeIePeCheckDigit(body + String(firstDig));
|
|
824
|
+
const checkDigits = `${firstDig}${secondDig}`;
|
|
825
|
+
if (stripped.slice(-2) !== checkDigits) {
|
|
826
|
+
return ieFailure(UF14, "INVALID_CHECK_DIGIT", "PE Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
827
|
+
}
|
|
828
|
+
return ieSuccess(stripped, UF14);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// src/core/inscricao-estadual/pi.ts
|
|
832
|
+
var UF15 = "PI";
|
|
833
|
+
function stripIePi(input) {
|
|
834
|
+
return stripIeDigits(input);
|
|
835
|
+
}
|
|
836
|
+
function validateIePi(input) {
|
|
837
|
+
const trimmed = input.trim();
|
|
838
|
+
const empty = checkTrimmedEmpty(trimmed, UF15);
|
|
839
|
+
if (empty) return empty;
|
|
840
|
+
const invalidChar = checkDigitChars(trimmed, UF15);
|
|
841
|
+
if (invalidChar) return invalidChar;
|
|
842
|
+
const ceResult = validateIeCe(stripIePi(trimmed));
|
|
843
|
+
if (!ceResult.ok) return { ...ceResult, uf: UF15 };
|
|
844
|
+
return { ...ceResult, uf: UF15 };
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// src/core/inscricao-estadual/pr.ts
|
|
848
|
+
var UF16 = "PR";
|
|
849
|
+
var LENGTH9 = 10;
|
|
850
|
+
function stripIePr(input) {
|
|
851
|
+
return stripIeDigits(input);
|
|
852
|
+
}
|
|
853
|
+
function validateIePr(input) {
|
|
854
|
+
const trimmed = input.trim();
|
|
855
|
+
const empty = checkTrimmedEmpty(trimmed, UF16);
|
|
856
|
+
if (empty) return empty;
|
|
857
|
+
const invalidChar = checkDigitChars(trimmed, UF16);
|
|
858
|
+
if (invalidChar) return invalidChar;
|
|
859
|
+
const stripped = stripIePr(trimmed);
|
|
860
|
+
if (stripped.length !== LENGTH9) {
|
|
861
|
+
return ieFailure(UF16, "INVALID_LENGTH", `PR Inscri\xE7\xE3o Estadual must have ${LENGTH9} digits after normalization`);
|
|
862
|
+
}
|
|
863
|
+
const body = stripped.slice(0, 8);
|
|
864
|
+
const firstDig = computeIePrStyleCheckDigit(body);
|
|
865
|
+
const secondDig = computeIePrStyleCheckDigit(body + String(firstDig));
|
|
866
|
+
const checkDigits = `${firstDig}${secondDig}`;
|
|
867
|
+
if (stripped.slice(-2) !== checkDigits) {
|
|
868
|
+
return ieFailure(UF16, "INVALID_CHECK_DIGIT", "PR Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
869
|
+
}
|
|
870
|
+
return ieSuccess(stripped, UF16);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
// src/core/inscricao-estadual/rj.ts
|
|
874
|
+
var UF17 = "RJ";
|
|
875
|
+
var LENGTH10 = 8;
|
|
876
|
+
function stripIeRj(input) {
|
|
877
|
+
return stripIeDigits(input);
|
|
878
|
+
}
|
|
879
|
+
function validateIeRj(input) {
|
|
880
|
+
const trimmed = input.trim();
|
|
881
|
+
const empty = checkTrimmedEmpty(trimmed, UF17);
|
|
882
|
+
if (empty) return empty;
|
|
883
|
+
const invalidChar = checkDigitChars(trimmed, UF17);
|
|
884
|
+
if (invalidChar) return invalidChar;
|
|
885
|
+
const stripped = stripIeRj(trimmed);
|
|
886
|
+
if (stripped.length !== LENGTH10) {
|
|
887
|
+
return ieFailure(UF17, "INVALID_LENGTH", `RJ Inscri\xE7\xE3o Estadual must have ${LENGTH10} digits after normalization`);
|
|
888
|
+
}
|
|
889
|
+
const body = stripped.slice(0, 7);
|
|
890
|
+
const expected = computeIeCyclicMod11CheckDigit(body, 2, 7);
|
|
891
|
+
if (Number(stripped.charAt(7)) !== expected) {
|
|
892
|
+
return ieFailure(UF17, "INVALID_CHECK_DIGIT", "RJ Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
893
|
+
}
|
|
894
|
+
return ieSuccess(stripped, UF17);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/core/inscricao-estadual/rn.ts
|
|
898
|
+
var UF18 = "RN";
|
|
899
|
+
var LENGTH11 = 9;
|
|
900
|
+
var RN_WEIGHTS = [9, 8, 7, 6, 5, 4, 3, 2];
|
|
901
|
+
function stripIeRn(input) {
|
|
902
|
+
return stripIeDigits(input);
|
|
903
|
+
}
|
|
904
|
+
function computeRnCheckDigit(body8) {
|
|
905
|
+
let sum = 0;
|
|
906
|
+
for (let i = 0; i < 8; i++) {
|
|
907
|
+
sum += Number(body8[i]) * RN_WEIGHTS[i];
|
|
908
|
+
}
|
|
909
|
+
const mod = sum % 11;
|
|
910
|
+
return mod < 2 ? 0 : 11 - mod;
|
|
911
|
+
}
|
|
912
|
+
function validateIeRn(input) {
|
|
913
|
+
const trimmed = input.trim();
|
|
914
|
+
const empty = checkTrimmedEmpty(trimmed, UF18);
|
|
915
|
+
if (empty) return empty;
|
|
916
|
+
const invalidChar = checkDigitChars(trimmed, UF18);
|
|
917
|
+
if (invalidChar) return invalidChar;
|
|
918
|
+
const stripped = stripIeRn(trimmed);
|
|
919
|
+
if (stripped.length !== LENGTH11) {
|
|
920
|
+
return ieFailure(UF18, "INVALID_LENGTH", `RN Inscri\xE7\xE3o Estadual must have ${LENGTH11} digits after normalization`);
|
|
921
|
+
}
|
|
922
|
+
if (!stripped.startsWith(IE_RN_PREFIX)) {
|
|
923
|
+
return ieFailure(UF18, "UNSUPPORTED_FORMAT", "RN Inscri\xE7\xE3o Estadual must start with prefix 20");
|
|
924
|
+
}
|
|
925
|
+
const body = stripped.slice(0, 8);
|
|
926
|
+
const expected = computeRnCheckDigit(body);
|
|
927
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
928
|
+
return ieFailure(UF18, "INVALID_CHECK_DIGIT", "RN Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
929
|
+
}
|
|
930
|
+
return ieSuccess(stripped, UF18);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// src/core/inscricao-estadual/ro.ts
|
|
934
|
+
var UF19 = "RO";
|
|
935
|
+
var LENGTH12 = 14;
|
|
936
|
+
function stripIeRo(input) {
|
|
937
|
+
return stripIeDigits(input);
|
|
938
|
+
}
|
|
939
|
+
function validateIeRo(input) {
|
|
940
|
+
const trimmed = input.trim();
|
|
941
|
+
const empty = checkTrimmedEmpty(trimmed, UF19);
|
|
942
|
+
if (empty) return empty;
|
|
943
|
+
const invalidChar = checkDigitChars(trimmed, UF19);
|
|
944
|
+
if (invalidChar) return invalidChar;
|
|
945
|
+
const stripped = stripIeRo(trimmed);
|
|
946
|
+
if (stripped.length !== LENGTH12) {
|
|
947
|
+
return ieFailure(UF19, "INVALID_LENGTH", `RO Inscri\xE7\xE3o Estadual must have ${LENGTH12} digits after normalization`);
|
|
948
|
+
}
|
|
949
|
+
const body = stripped.slice(0, 13);
|
|
950
|
+
const expected = computeIeRoCheckDigit(body);
|
|
951
|
+
if (Number(stripped.charAt(13)) !== expected) {
|
|
952
|
+
return ieFailure(UF19, "INVALID_CHECK_DIGIT", "RO Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
953
|
+
}
|
|
954
|
+
return ieSuccess(stripped, UF19);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// src/core/inscricao-estadual/rr.ts
|
|
958
|
+
var UF20 = "RR";
|
|
959
|
+
var LENGTH13 = 9;
|
|
960
|
+
function stripIeRr(input) {
|
|
961
|
+
return stripIeDigits(input);
|
|
962
|
+
}
|
|
963
|
+
function validateIeRr(input) {
|
|
964
|
+
const trimmed = input.trim();
|
|
965
|
+
const empty = checkTrimmedEmpty(trimmed, UF20);
|
|
966
|
+
if (empty) return empty;
|
|
967
|
+
const invalidChar = checkDigitChars(trimmed, UF20);
|
|
968
|
+
if (invalidChar) return invalidChar;
|
|
969
|
+
const stripped = stripIeRr(trimmed);
|
|
970
|
+
if (stripped.length !== LENGTH13) {
|
|
971
|
+
return ieFailure(UF20, "INVALID_LENGTH", `RR Inscri\xE7\xE3o Estadual must have ${LENGTH13} digits after normalization`);
|
|
972
|
+
}
|
|
973
|
+
if (!stripped.startsWith(IE_RR_PREFIX)) {
|
|
974
|
+
return ieFailure(UF20, "UNSUPPORTED_FORMAT", "RR Inscri\xE7\xE3o Estadual must start with prefix 24");
|
|
975
|
+
}
|
|
976
|
+
const body = stripped.slice(0, 8);
|
|
977
|
+
const expected = computeIeRrCheckDigit(body);
|
|
978
|
+
if (Number(stripped.charAt(8)) !== expected) {
|
|
979
|
+
return ieFailure(UF20, "INVALID_CHECK_DIGIT", "RR Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
980
|
+
}
|
|
981
|
+
return ieSuccess(stripped, UF20);
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// src/core/inscricao-estadual/rs.ts
|
|
985
|
+
var UF21 = "RS";
|
|
986
|
+
var LENGTH14 = 10;
|
|
987
|
+
function stripIeRs(input) {
|
|
988
|
+
return stripIeDigits(input);
|
|
989
|
+
}
|
|
990
|
+
function validateIeRs(input) {
|
|
991
|
+
const trimmed = input.trim();
|
|
992
|
+
const empty = checkTrimmedEmpty(trimmed, UF21);
|
|
993
|
+
if (empty) return empty;
|
|
994
|
+
const invalidChar = checkDigitChars(trimmed, UF21, /^[0-9.\-\s/]+$/);
|
|
995
|
+
if (invalidChar) return invalidChar;
|
|
996
|
+
const stripped = stripIeRs(trimmed);
|
|
997
|
+
if (stripped.length !== LENGTH14) {
|
|
998
|
+
return ieFailure(UF21, "INVALID_LENGTH", `RS Inscri\xE7\xE3o Estadual must have ${LENGTH14} digits after normalization`);
|
|
999
|
+
}
|
|
1000
|
+
const body = stripped.slice(0, 9);
|
|
1001
|
+
const expected = computeIeCyclicMod11CheckDigit(body, 2, 9);
|
|
1002
|
+
if (Number(stripped.charAt(9)) !== expected) {
|
|
1003
|
+
return ieFailure(UF21, "INVALID_CHECK_DIGIT", "RS Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
1004
|
+
}
|
|
1005
|
+
return ieSuccess(stripped, UF21);
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/core/inscricao-estadual/sc.ts
|
|
1009
|
+
var UF22 = "SC";
|
|
1010
|
+
function stripIeSc(input) {
|
|
1011
|
+
return stripIeDigits(input);
|
|
1012
|
+
}
|
|
1013
|
+
function validateIeSc(input) {
|
|
1014
|
+
const trimmed = input.trim();
|
|
1015
|
+
const empty = checkTrimmedEmpty(trimmed, UF22);
|
|
1016
|
+
if (empty) return empty;
|
|
1017
|
+
const invalidChar = checkDigitChars(trimmed, UF22);
|
|
1018
|
+
if (invalidChar) return invalidChar;
|
|
1019
|
+
const ceResult = validateIeCe(stripIeSc(trimmed));
|
|
1020
|
+
if (!ceResult.ok) return { ...ceResult, uf: UF22 };
|
|
1021
|
+
return { ...ceResult, uf: UF22 };
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// src/core/inscricao-estadual/se.ts
|
|
1025
|
+
var UF23 = "SE";
|
|
1026
|
+
function stripIeSe(input) {
|
|
1027
|
+
return stripIeDigits(input);
|
|
1028
|
+
}
|
|
1029
|
+
function validateIeSe(input) {
|
|
1030
|
+
const trimmed = input.trim();
|
|
1031
|
+
const empty = checkTrimmedEmpty(trimmed, UF23);
|
|
1032
|
+
if (empty) return empty;
|
|
1033
|
+
const invalidChar = checkDigitChars(trimmed, UF23);
|
|
1034
|
+
if (invalidChar) return invalidChar;
|
|
1035
|
+
const ceResult = validateIeCe(stripIeSe(trimmed));
|
|
1036
|
+
if (!ceResult.ok) return { ...ceResult, uf: UF23 };
|
|
1037
|
+
return { ...ceResult, uf: UF23 };
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// src/core/inscricao-estadual/sp.ts
|
|
1041
|
+
var SP_MASK_PATTERN = /^[0-9.]+$/;
|
|
1042
|
+
function failure3(code, message) {
|
|
1043
|
+
return { ok: false, code, message, uf: "SP" };
|
|
1044
|
+
}
|
|
1045
|
+
function stripIeSp(input) {
|
|
1046
|
+
return input.replace(/\D/g, "");
|
|
1047
|
+
}
|
|
1048
|
+
function validateIeSp(input) {
|
|
1049
|
+
const trimmed = input.trim();
|
|
1050
|
+
if (trimmed.length === 0) {
|
|
1051
|
+
return { ok: false, code: "EMPTY_INPUT", message: "Inscri\xE7\xE3o Estadual input is empty", uf: "SP" };
|
|
1052
|
+
}
|
|
1053
|
+
if (/[Pp]/.test(trimmed)) {
|
|
1054
|
+
return failure3("UNSUPPORTED_FORMAT", "SP rural IE format (P\u2026) is not supported in v1");
|
|
1055
|
+
}
|
|
1056
|
+
if (!SP_MASK_PATTERN.test(trimmed)) {
|
|
1057
|
+
return failure3("INVALID_CHARACTER", "SP Inscri\xE7\xE3o Estadual contains invalid characters");
|
|
1058
|
+
}
|
|
1059
|
+
const stripped = stripIeSp(trimmed);
|
|
1060
|
+
if (stripped.length !== IE_SP_LENGTH) {
|
|
1061
|
+
return failure3("INVALID_LENGTH", `SP Inscri\xE7\xE3o Estadual must have ${IE_SP_LENGTH} digits after normalization`);
|
|
1062
|
+
}
|
|
1063
|
+
const dv1 = computeIeSpCheckDigit(stripped, IE_SP_DV1_WEIGHTS);
|
|
1064
|
+
const dv2 = computeIeSpCheckDigit(stripped, IE_SP_DV2_WEIGHTS);
|
|
1065
|
+
if (Number(stripped.charAt(8)) !== dv1 || Number(stripped.charAt(11)) !== dv2) {
|
|
1066
|
+
return failure3("INVALID_CHECK_DIGIT", "SP Inscri\xE7\xE3o Estadual check digits are invalid");
|
|
1067
|
+
}
|
|
1068
|
+
return {
|
|
1069
|
+
ok: true,
|
|
1070
|
+
value: brandInscricaoEstadual(stripped),
|
|
1071
|
+
uf: "SP",
|
|
1072
|
+
format: "inscricao-estadual"
|
|
1073
|
+
};
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// src/core/inscricao-estadual/to.ts
|
|
1077
|
+
var UF24 = "TO";
|
|
1078
|
+
function stripIeTo(input) {
|
|
1079
|
+
return stripIeDigits(input);
|
|
1080
|
+
}
|
|
1081
|
+
function validateIeTo(input) {
|
|
1082
|
+
const trimmed = input.trim();
|
|
1083
|
+
const empty = checkTrimmedEmpty(trimmed, UF24);
|
|
1084
|
+
if (empty) return empty;
|
|
1085
|
+
const invalidChar = checkDigitChars(trimmed, UF24);
|
|
1086
|
+
if (invalidChar) return invalidChar;
|
|
1087
|
+
const stripped = stripIeTo(trimmed);
|
|
1088
|
+
if (stripped.length !== 9 && stripped.length !== 11) {
|
|
1089
|
+
return ieFailure(UF24, "INVALID_LENGTH", "TO Inscri\xE7\xE3o Estadual must have 9 or 11 digits after normalization");
|
|
1090
|
+
}
|
|
1091
|
+
let body;
|
|
1092
|
+
if (stripped.length === 11) {
|
|
1093
|
+
const midPrefix = stripped.slice(2, 4);
|
|
1094
|
+
if (!IE_TO_LEGACY_PREFIXES.includes(midPrefix)) {
|
|
1095
|
+
return ieFailure(UF24, "UNSUPPORTED_FORMAT", "TO legacy 11-digit IE middle prefix is not supported");
|
|
1096
|
+
}
|
|
1097
|
+
body = stripped.slice(0, 2) + stripped.slice(4, 10);
|
|
1098
|
+
} else {
|
|
1099
|
+
body = stripped.slice(0, 8);
|
|
1100
|
+
}
|
|
1101
|
+
const expected = computeIeToCheckDigit(body);
|
|
1102
|
+
if (Number(stripped.slice(-1)) !== expected) {
|
|
1103
|
+
return ieFailure(UF24, "INVALID_CHECK_DIGIT", "TO Inscri\xE7\xE3o Estadual check digit is invalid");
|
|
1104
|
+
}
|
|
1105
|
+
return ieSuccess(stripped, UF24);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// src/core/inscricao-estadual/index.ts
|
|
1109
|
+
var VALIDATORS = {
|
|
1110
|
+
AC: validateIeAc,
|
|
1111
|
+
AL: validateIeAl,
|
|
1112
|
+
AM: validateIeAm,
|
|
1113
|
+
AP: validateIeAp,
|
|
1114
|
+
BA: validateIeBa,
|
|
1115
|
+
CE: validateIeCe,
|
|
1116
|
+
DF: validateIeDf,
|
|
1117
|
+
ES: validateIeEs,
|
|
1118
|
+
GO: validateIeGo,
|
|
1119
|
+
MA: validateIeMa,
|
|
1120
|
+
MG: validateIeMg,
|
|
1121
|
+
MS: validateIeMs,
|
|
1122
|
+
MT: validateIeMt,
|
|
1123
|
+
PA: validateIePa,
|
|
1124
|
+
PB: validateIePb,
|
|
1125
|
+
PE: validateIePe,
|
|
1126
|
+
PI: validateIePi,
|
|
1127
|
+
PR: validateIePr,
|
|
1128
|
+
RJ: validateIeRj,
|
|
1129
|
+
RN: validateIeRn,
|
|
1130
|
+
RO: validateIeRo,
|
|
1131
|
+
RR: validateIeRr,
|
|
1132
|
+
RS: validateIeRs,
|
|
1133
|
+
SC: validateIeSc,
|
|
1134
|
+
SE: validateIeSe,
|
|
1135
|
+
SP: validateIeSp,
|
|
1136
|
+
TO: validateIeTo
|
|
1137
|
+
};
|
|
1138
|
+
function failure4(code, message) {
|
|
1139
|
+
return { ok: false, code, message };
|
|
1140
|
+
}
|
|
1141
|
+
function getIeOfficialSourceUrl(uf) {
|
|
1142
|
+
return IE_OFFICIAL_SOURCE_URLS[uf];
|
|
1143
|
+
}
|
|
1144
|
+
function isSupportedUf(uf) {
|
|
1145
|
+
return uf !== void 0 && IE_SUPPORTED_UFS.includes(uf);
|
|
1146
|
+
}
|
|
1147
|
+
function stripInscricaoEstadual(input) {
|
|
1148
|
+
return input.replace(/\D/g, "");
|
|
1149
|
+
}
|
|
1150
|
+
function isValidInscricaoEstadual(input, options) {
|
|
1151
|
+
return validateInscricaoEstadual(input, options).ok;
|
|
1152
|
+
}
|
|
1153
|
+
function validateInscricaoEstadual(input, options) {
|
|
1154
|
+
if (!isSupportedUf(options.uf)) {
|
|
1155
|
+
return failure4("UNSUPPORTED_FORMAT", `UF ${String(options.uf)} is not supported`);
|
|
1156
|
+
}
|
|
1157
|
+
return VALIDATORS[options.uf](input);
|
|
1158
|
+
}
|
|
1159
|
+
function formatInscricaoEstadual(input, options) {
|
|
1160
|
+
const result = validateInscricaoEstadual(input, options);
|
|
1161
|
+
if (!result.ok) {
|
|
1162
|
+
return { ok: false, code: result.code, message: result.message };
|
|
1163
|
+
}
|
|
1164
|
+
try {
|
|
1165
|
+
if (result.uf === "SP") {
|
|
1166
|
+
return { ok: true, formatted: applyIeSpMask(result.value) };
|
|
1167
|
+
}
|
|
1168
|
+
if (result.uf === "DF") {
|
|
1169
|
+
return { ok: true, formatted: applyIeDfMask(result.value) };
|
|
1170
|
+
}
|
|
1171
|
+
return { ok: true, formatted: result.value };
|
|
1172
|
+
} catch (error) {
|
|
1173
|
+
const message = error instanceof Error ? error.message : "Failed to format Inscri\xE7\xE3o Estadual";
|
|
1174
|
+
return { ok: false, code: "UNSUPPORTED_FORMAT", message };
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
export { IE_DF_GOLDEN, IE_DF_GOLDEN_MASKED, IE_DF_LENGTH, IE_DF_OFFICIAL_SOURCE_URL, IE_MT_GOLDEN_CANONICAL, IE_MT_GOLDEN_LEGACY, IE_MT_OFFICIAL_SOURCE_URL, IE_OFFICIAL_SOURCE_URLS, IE_SP_GOLDEN, IE_SP_GOLDEN_MASKED, IE_SP_OFFICIAL_SOURCE_URL, IE_SUPPORTED_UFS, formatInscricaoEstadual, getIeOfficialSourceUrl, isValidInscricaoEstadual, stripInscricaoEstadual, validateIeDf, validateIeMt, validateIeSp, validateInscricaoEstadual };
|
|
1179
|
+
//# sourceMappingURL=chunk-Z4F75QEC.js.map
|
|
1180
|
+
//# sourceMappingURL=chunk-Z4F75QEC.js.map
|