@br-validators/cli 1.3.0 → 1.6.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/README.md +65 -1
- package/dist/index.js +1233 -101
- package/dist/run-captured.js +1188 -31
- package/package.json +2 -2
package/dist/run-captured.js
CHANGED
|
@@ -6,13 +6,767 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/constants.ts
|
|
9
|
-
var SUPPORTED_TYPES = ["cnpj", "cpf", "cep", "telefone", "cnh", "renavam", "titulo-eleitor", "nfe-chave", "brcode", "placa", "pis-pasep", "pix", "boleto", "cartao", "ie"];
|
|
9
|
+
var SUPPORTED_TYPES = ["cnpj", "cpf", "cep", "telefone", "cnh", "renavam", "titulo-eleitor", "processo-judicial", "rg", "nfe-chave", "brcode", "placa", "pis-pasep", "pix", "boleto", "cartao", "ie"];
|
|
10
10
|
var EXIT = {
|
|
11
11
|
OK: 0,
|
|
12
12
|
INVALID: 1,
|
|
13
13
|
USAGE: 2
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
// src/commands/reference-lookup/registry.ts
|
|
17
|
+
import {
|
|
18
|
+
CEST_DATA_VERSION,
|
|
19
|
+
getCestPorCodigo
|
|
20
|
+
} from "@br-validators/core/cest";
|
|
21
|
+
import {
|
|
22
|
+
INCOTERMS_DATA_VERSION,
|
|
23
|
+
getIncotermPorCodigo
|
|
24
|
+
} from "@br-validators/core/incoterms";
|
|
25
|
+
import {
|
|
26
|
+
MOEDAS_DATA_VERSION,
|
|
27
|
+
getMoedaPorCodigo
|
|
28
|
+
} from "@br-validators/core/moedas";
|
|
29
|
+
import {
|
|
30
|
+
NATUREZA_JURIDICA_DATA_VERSION,
|
|
31
|
+
getNaturezaJuridicaPorCodigo
|
|
32
|
+
} from "@br-validators/core/natureza-juridica";
|
|
33
|
+
import { NBS_DATA_VERSION, getNbsPorCodigo } from "@br-validators/core/nbs";
|
|
34
|
+
import {
|
|
35
|
+
PAISES_BACEN_DATA_VERSION,
|
|
36
|
+
getPaisPorCodigoBacen
|
|
37
|
+
} from "@br-validators/core/paises-bacen";
|
|
38
|
+
import {
|
|
39
|
+
AEROPORTOS_DATA_VERSION,
|
|
40
|
+
getAeroportoPorIata,
|
|
41
|
+
getAeroportoPorIcao
|
|
42
|
+
} from "@br-validators/core/aeroportos";
|
|
43
|
+
import { PORTOS_DATA_VERSION, getPortoPorCodigo } from "@br-validators/core/portos";
|
|
44
|
+
import {
|
|
45
|
+
CNAES_DATA_VERSION,
|
|
46
|
+
getCnaePorCodigo
|
|
47
|
+
} from "@br-validators/core/cnaes";
|
|
48
|
+
import {
|
|
49
|
+
CFOP_DATA_VERSION,
|
|
50
|
+
getCfopPorCodigo
|
|
51
|
+
} from "@br-validators/core/cfop";
|
|
52
|
+
import { NCM_DATA_VERSION, getNcmPorCodigo } from "@br-validators/core/ncm";
|
|
53
|
+
import { CBO_DATA_VERSION, getCboPorCodigo } from "@br-validators/core/cbo";
|
|
54
|
+
var REFERENCE_LOOKUP_COMMANDS = [
|
|
55
|
+
"natureza-juridica",
|
|
56
|
+
"nbs",
|
|
57
|
+
"cest",
|
|
58
|
+
"cnae",
|
|
59
|
+
"cfop",
|
|
60
|
+
"ncm",
|
|
61
|
+
"cbo",
|
|
62
|
+
"moedas",
|
|
63
|
+
"paises-bacen",
|
|
64
|
+
"incoterms",
|
|
65
|
+
"portos",
|
|
66
|
+
"aeroportos"
|
|
67
|
+
];
|
|
68
|
+
var REFERENCE_SEARCH_COMMANDS = ["cnae", "cfop", "ncm", "cbo"];
|
|
69
|
+
function lookupAeroporto(input) {
|
|
70
|
+
const normalized = input.trim().toUpperCase();
|
|
71
|
+
if (/^[A-Z0-9]{3}$/.test(normalized)) {
|
|
72
|
+
return getAeroportoPorIata(normalized);
|
|
73
|
+
}
|
|
74
|
+
if (/^[A-Z]{4}$/.test(normalized)) {
|
|
75
|
+
return getAeroportoPorIcao(normalized);
|
|
76
|
+
}
|
|
77
|
+
return void 0;
|
|
78
|
+
}
|
|
79
|
+
var REFERENCE_LOOKUP_MODULES = {
|
|
80
|
+
"natureza-juridica": {
|
|
81
|
+
command: "natureza-juridica",
|
|
82
|
+
description: "RFB legal nature codes \u2014 offline lookup",
|
|
83
|
+
resultKey: "naturezaJuridica",
|
|
84
|
+
capturadoEm: NATUREZA_JURIDICA_DATA_VERSION.capturadoEm,
|
|
85
|
+
lookup: (input) => getNaturezaJuridicaPorCodigo(input),
|
|
86
|
+
formatHuman: (result) => {
|
|
87
|
+
const row = result;
|
|
88
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
nbs: {
|
|
92
|
+
command: "nbs",
|
|
93
|
+
description: "NFSe NBS service codes \u2014 offline lookup",
|
|
94
|
+
resultKey: "nbs",
|
|
95
|
+
capturadoEm: NBS_DATA_VERSION.capturadoEm,
|
|
96
|
+
lookup: (input) => getNbsPorCodigo(input),
|
|
97
|
+
formatHuman: (result) => {
|
|
98
|
+
const row = result;
|
|
99
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
cest: {
|
|
103
|
+
command: "cest",
|
|
104
|
+
description: "CONFAZ CEST ST codes \u2014 offline lookup",
|
|
105
|
+
resultKey: "cest",
|
|
106
|
+
capturadoEm: CEST_DATA_VERSION.capturadoEm,
|
|
107
|
+
lookup: (input) => getCestPorCodigo(input),
|
|
108
|
+
formatHuman: (result) => {
|
|
109
|
+
const row = result;
|
|
110
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
cnae: {
|
|
114
|
+
command: "cnae",
|
|
115
|
+
description: "IBGE CNAE 2.3 subclasses \u2014 offline lookup",
|
|
116
|
+
resultKey: "cnae",
|
|
117
|
+
capturadoEm: CNAES_DATA_VERSION.capturadoEm,
|
|
118
|
+
lookup: (input) => getCnaePorCodigo(input),
|
|
119
|
+
formatHuman: (result) => {
|
|
120
|
+
const row = result;
|
|
121
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
cfop: {
|
|
125
|
+
command: "cfop",
|
|
126
|
+
description: "CONFAZ CFOP fiscal operations \u2014 offline lookup",
|
|
127
|
+
resultKey: "cfop",
|
|
128
|
+
capturadoEm: CFOP_DATA_VERSION.capturadoEm,
|
|
129
|
+
lookup: (input) => getCfopPorCodigo(input),
|
|
130
|
+
formatHuman: (result) => {
|
|
131
|
+
const row = result;
|
|
132
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
ncm: {
|
|
136
|
+
command: "ncm",
|
|
137
|
+
description: "Siscomex NCM Mercosur codes \u2014 offline lookup",
|
|
138
|
+
resultKey: "ncm",
|
|
139
|
+
capturadoEm: NCM_DATA_VERSION.capturadoEm,
|
|
140
|
+
lookup: (input) => getNcmPorCodigo(input),
|
|
141
|
+
formatHuman: (result) => {
|
|
142
|
+
const row = result;
|
|
143
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
cbo: {
|
|
147
|
+
command: "cbo",
|
|
148
|
+
description: "MTE CBO 2002 occupations \u2014 offline lookup",
|
|
149
|
+
resultKey: "cbo",
|
|
150
|
+
capturadoEm: CBO_DATA_VERSION.capturadoEm,
|
|
151
|
+
lookup: (input) => getCboPorCodigo(input),
|
|
152
|
+
formatHuman: (result) => {
|
|
153
|
+
const row = result;
|
|
154
|
+
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
moedas: {
|
|
158
|
+
command: "moedas",
|
|
159
|
+
description: "ISO 4217 + Bacen PTAX currencies \u2014 offline lookup",
|
|
160
|
+
resultKey: "moeda",
|
|
161
|
+
capturadoEm: MOEDAS_DATA_VERSION.capturadoEm,
|
|
162
|
+
lookup: (input) => getMoedaPorCodigo(input),
|
|
163
|
+
formatHuman: (result) => {
|
|
164
|
+
const row = result;
|
|
165
|
+
const symbol = row.simbolo ?? "\u2014";
|
|
166
|
+
return `${row.codigo} \u2014 ${row.nome} (${symbol})`;
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"paises-bacen": {
|
|
170
|
+
command: "paises-bacen",
|
|
171
|
+
description: "NF-e Bacen country codes \u2014 offline lookup",
|
|
172
|
+
resultKey: "pais",
|
|
173
|
+
capturadoEm: PAISES_BACEN_DATA_VERSION.capturadoEm,
|
|
174
|
+
lookup: (input) => getPaisPorCodigoBacen(input),
|
|
175
|
+
formatHuman: (result) => {
|
|
176
|
+
const row = result;
|
|
177
|
+
return `${row.codigo} \u2014 ${row.nome}`;
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
incoterms: {
|
|
181
|
+
command: "incoterms",
|
|
182
|
+
description: "ICC Incoterms 2020 \u2014 offline lookup",
|
|
183
|
+
resultKey: "incoterm",
|
|
184
|
+
capturadoEm: INCOTERMS_DATA_VERSION.capturadoEm,
|
|
185
|
+
lookup: (input) => getIncotermPorCodigo(input),
|
|
186
|
+
formatHuman: (result) => {
|
|
187
|
+
const row = result;
|
|
188
|
+
return `${row.codigo} \u2014 ${row.nome} (${row.edicao})`;
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
portos: {
|
|
192
|
+
command: "portos",
|
|
193
|
+
description: "ANTAQ port installations \u2014 offline lookup",
|
|
194
|
+
resultKey: "porto",
|
|
195
|
+
capturadoEm: PORTOS_DATA_VERSION.capturadoEm,
|
|
196
|
+
lookup: (input) => getPortoPorCodigo(input),
|
|
197
|
+
formatHuman: (result) => {
|
|
198
|
+
const row = result;
|
|
199
|
+
return `${row.codigo} \u2014 ${row.nome} (${row.uf})`;
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
aeroportos: {
|
|
203
|
+
command: "aeroportos",
|
|
204
|
+
description: "ANAC public aerodromos \u2014 offline lookup by IATA or ICAO",
|
|
205
|
+
resultKey: "aeroporto",
|
|
206
|
+
capturadoEm: AEROPORTOS_DATA_VERSION.capturadoEm,
|
|
207
|
+
lookup: lookupAeroporto,
|
|
208
|
+
formatHuman: (result) => {
|
|
209
|
+
const row = result;
|
|
210
|
+
const iata = row.iata ?? "\u2014";
|
|
211
|
+
return `${iata}/${row.icao} \u2014 ${row.nome} (${row.uf})`;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
function isReferenceLookupCommand(value) {
|
|
216
|
+
return REFERENCE_LOOKUP_COMMANDS.includes(value);
|
|
217
|
+
}
|
|
218
|
+
function isReferenceSearchCommand(value) {
|
|
219
|
+
return REFERENCE_SEARCH_COMMANDS.includes(value);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/commands/bancos/list.ts
|
|
223
|
+
import { BANCOS_DATA_VERSION as BANCOS_DATA_VERSION2, getBancos } from "@br-validators/core/bancos";
|
|
224
|
+
|
|
225
|
+
// src/commands/bancos/lookup.ts
|
|
226
|
+
import {
|
|
227
|
+
BANCOS_DATA_VERSION,
|
|
228
|
+
getBancoPorCodigo,
|
|
229
|
+
getBancoPorIspb
|
|
230
|
+
} from "@br-validators/core/bancos";
|
|
231
|
+
function normalizeBancosLookupInput(raw) {
|
|
232
|
+
const digits = raw.replace(/\D/g, "");
|
|
233
|
+
if (digits.length === 8) {
|
|
234
|
+
return { kind: "ispb", value: digits.padStart(8, "0") };
|
|
235
|
+
}
|
|
236
|
+
if (digits.length >= 1 && digits.length <= 3) {
|
|
237
|
+
return { kind: "codigo", value: digits.padStart(3, "0").slice(-3) };
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
function lookupBanco(raw) {
|
|
242
|
+
const normalized = normalizeBancosLookupInput(raw);
|
|
243
|
+
if (!normalized) {
|
|
244
|
+
return void 0;
|
|
245
|
+
}
|
|
246
|
+
return normalized.kind === "ispb" ? getBancoPorIspb(normalized.value) : getBancoPorCodigo(normalized.value);
|
|
247
|
+
}
|
|
248
|
+
function formatBancoHuman(banco) {
|
|
249
|
+
return `${banco.codigo} \u2014 ${banco.nome} (ISPB ${banco.ispb})`;
|
|
250
|
+
}
|
|
251
|
+
function runBancosLookupCommand(input, options, io = { stdout: [], stderr: [] }) {
|
|
252
|
+
const normalized = normalizeBancosLookupInput(input);
|
|
253
|
+
if (!normalized) {
|
|
254
|
+
io.stderr.push("Invalid bank code or ISPB. Use 3-digit COMPE (e.g. 001) or 8-digit ISPB.");
|
|
255
|
+
return EXIT.USAGE;
|
|
256
|
+
}
|
|
257
|
+
const banco = lookupBanco(input);
|
|
258
|
+
if (!banco) {
|
|
259
|
+
io.stderr.push(`Bank not found: ${input}`);
|
|
260
|
+
return EXIT.INVALID;
|
|
261
|
+
}
|
|
262
|
+
if (options.json) {
|
|
263
|
+
const payload = { ok: true, banco };
|
|
264
|
+
if (options.verbose) {
|
|
265
|
+
payload.capturadoEm = BANCOS_DATA_VERSION.capturadoEm;
|
|
266
|
+
}
|
|
267
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
268
|
+
return EXIT.OK;
|
|
269
|
+
}
|
|
270
|
+
io.stdout.push(formatBancoHuman(banco));
|
|
271
|
+
if (options.verbose) {
|
|
272
|
+
io.stdout.push(`capturadoEm: ${BANCOS_DATA_VERSION.capturadoEm}`);
|
|
273
|
+
}
|
|
274
|
+
return EXIT.OK;
|
|
275
|
+
}
|
|
276
|
+
function runBancosLookup(value, options, io = { stdout: [], stderr: [] }) {
|
|
277
|
+
if (!value?.trim()) {
|
|
278
|
+
io.stderr.push("Missing bank code or ISPB. Pass COMPE (001) or ISPB (8 digits).");
|
|
279
|
+
return EXIT.USAGE;
|
|
280
|
+
}
|
|
281
|
+
return runBancosLookupCommand(value.trim(), options, io);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/commands/bancos/list.ts
|
|
285
|
+
function sliceBancos(limit) {
|
|
286
|
+
const all = getBancos();
|
|
287
|
+
if (limit === void 0 || !Number.isFinite(limit) || limit <= 0) {
|
|
288
|
+
return all;
|
|
289
|
+
}
|
|
290
|
+
return all.slice(0, limit);
|
|
291
|
+
}
|
|
292
|
+
function runBancosListCommand(options, io = { stdout: [], stderr: [] }) {
|
|
293
|
+
const bancos = sliceBancos(options.limit);
|
|
294
|
+
if (options.json) {
|
|
295
|
+
const payload = {
|
|
296
|
+
ok: true,
|
|
297
|
+
total: bancos.length,
|
|
298
|
+
bancos
|
|
299
|
+
};
|
|
300
|
+
if (options.verbose) {
|
|
301
|
+
payload.capturadoEm = BANCOS_DATA_VERSION2.capturadoEm;
|
|
302
|
+
}
|
|
303
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
304
|
+
return EXIT.OK;
|
|
305
|
+
}
|
|
306
|
+
for (const banco of bancos) {
|
|
307
|
+
io.stdout.push(formatBancoHuman(banco));
|
|
308
|
+
}
|
|
309
|
+
if (options.verbose) {
|
|
310
|
+
io.stdout.push(`capturadoEm: ${BANCOS_DATA_VERSION2.capturadoEm}`);
|
|
311
|
+
}
|
|
312
|
+
return EXIT.OK;
|
|
313
|
+
}
|
|
314
|
+
function runBancosList(options, io = { stdout: [], stderr: [] }) {
|
|
315
|
+
return runBancosListCommand(options, io);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// src/commands/reference-lookup/lookup.ts
|
|
319
|
+
function runReferenceLookupCommand(command, input, options, io = { stdout: [], stderr: [] }) {
|
|
320
|
+
const module = REFERENCE_LOOKUP_MODULES[command];
|
|
321
|
+
const trimmed = input.trim();
|
|
322
|
+
if (trimmed.length === 0) {
|
|
323
|
+
io.stderr.push(`Missing code. Pass a lookup value for ${command}.`);
|
|
324
|
+
return EXIT.USAGE;
|
|
325
|
+
}
|
|
326
|
+
const result = module.lookup(trimmed);
|
|
327
|
+
if (!result) {
|
|
328
|
+
io.stderr.push(`Not found: ${trimmed}`);
|
|
329
|
+
return EXIT.INVALID;
|
|
330
|
+
}
|
|
331
|
+
if (options.json) {
|
|
332
|
+
const payload = {
|
|
333
|
+
ok: true,
|
|
334
|
+
[module.resultKey]: result,
|
|
335
|
+
...options.verbose ? { capturadoEm: module.capturadoEm } : {}
|
|
336
|
+
};
|
|
337
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
338
|
+
return EXIT.OK;
|
|
339
|
+
}
|
|
340
|
+
io.stdout.push(module.formatHuman(result));
|
|
341
|
+
if (options.verbose) {
|
|
342
|
+
io.stdout.push(`capturadoEm: ${module.capturadoEm}`);
|
|
343
|
+
}
|
|
344
|
+
return EXIT.OK;
|
|
345
|
+
}
|
|
346
|
+
function runReferenceLookup(command, value, options, io = { stdout: [], stderr: [] }) {
|
|
347
|
+
if (!isReferenceLookupCommand(command)) {
|
|
348
|
+
io.stderr.push(`Unknown reference lookup command: ${command}`);
|
|
349
|
+
return EXIT.USAGE;
|
|
350
|
+
}
|
|
351
|
+
if (!value?.trim()) {
|
|
352
|
+
io.stderr.push(`Missing code. Usage: br-validators ${command} lookup <codigo>`);
|
|
353
|
+
return EXIT.USAGE;
|
|
354
|
+
}
|
|
355
|
+
return runReferenceLookupCommand(command, value.trim(), options, io);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/commands/reference-lookup/search.ts
|
|
359
|
+
import { searchCbo } from "@br-validators/core/cbo";
|
|
360
|
+
import { searchCnaes } from "@br-validators/core/cnaes";
|
|
361
|
+
import { searchCfop } from "@br-validators/core/cfop";
|
|
362
|
+
import { searchNcm } from "@br-validators/core/ncm";
|
|
363
|
+
function runSearch(command, query, limit) {
|
|
364
|
+
switch (command) {
|
|
365
|
+
case "cnae":
|
|
366
|
+
return searchCnaes(query, { limit });
|
|
367
|
+
case "cfop":
|
|
368
|
+
return searchCfop(query, { limit });
|
|
369
|
+
case "ncm":
|
|
370
|
+
return searchNcm(query, { limit });
|
|
371
|
+
case "cbo":
|
|
372
|
+
return searchCbo(query, { limit });
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
function formatSearchHuman(command, results) {
|
|
376
|
+
const module = REFERENCE_LOOKUP_MODULES[command];
|
|
377
|
+
return results.map((row) => module.formatHuman(row));
|
|
378
|
+
}
|
|
379
|
+
function runReferenceSearchCommand(command, query, options, io = { stdout: [], stderr: [] }) {
|
|
380
|
+
const trimmed = query.trim();
|
|
381
|
+
if (trimmed.length === 0) {
|
|
382
|
+
io.stderr.push(`Missing search query. Pass a description fragment for ${command}.`);
|
|
383
|
+
return EXIT.USAGE;
|
|
384
|
+
}
|
|
385
|
+
const limit = options.limit !== void 0 && options.limit > 0 ? options.limit : 10;
|
|
386
|
+
const results = runSearch(command, trimmed, limit);
|
|
387
|
+
const module = REFERENCE_LOOKUP_MODULES[command];
|
|
388
|
+
const resultKey = `${module.resultKey}s`;
|
|
389
|
+
if (options.json) {
|
|
390
|
+
const payload = {
|
|
391
|
+
ok: true,
|
|
392
|
+
query: trimmed,
|
|
393
|
+
total: results.length,
|
|
394
|
+
[resultKey]: results,
|
|
395
|
+
...options.verbose ? { capturadoEm: module.capturadoEm } : {}
|
|
396
|
+
};
|
|
397
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
398
|
+
return EXIT.OK;
|
|
399
|
+
}
|
|
400
|
+
if (results.length === 0) {
|
|
401
|
+
io.stderr.push(`No matches for: ${trimmed}`);
|
|
402
|
+
return EXIT.INVALID;
|
|
403
|
+
}
|
|
404
|
+
for (const line of formatSearchHuman(command, results)) {
|
|
405
|
+
io.stdout.push(line);
|
|
406
|
+
}
|
|
407
|
+
if (options.verbose) {
|
|
408
|
+
io.stdout.push(`capturadoEm: ${module.capturadoEm}`);
|
|
409
|
+
}
|
|
410
|
+
return EXIT.OK;
|
|
411
|
+
}
|
|
412
|
+
function runReferenceSearch(command, query, options, io = { stdout: [], stderr: [] }) {
|
|
413
|
+
if (!isReferenceSearchCommand(command)) {
|
|
414
|
+
io.stderr.push(`Unknown reference search command: ${command}`);
|
|
415
|
+
return EXIT.USAGE;
|
|
416
|
+
}
|
|
417
|
+
if (!query?.trim()) {
|
|
418
|
+
io.stderr.push(`Missing query. Usage: br-validators ${command} search <query>`);
|
|
419
|
+
return EXIT.USAGE;
|
|
420
|
+
}
|
|
421
|
+
return runReferenceSearchCommand(command, query.trim(), options, io);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/commands/ibge/lookup.ts
|
|
425
|
+
import {
|
|
426
|
+
getMunicipioPorCodigo,
|
|
427
|
+
IBGE_DATA_VERSION
|
|
428
|
+
} from "@br-validators/core/ibge";
|
|
429
|
+
function normalizeIbgeMunicipioCode(raw) {
|
|
430
|
+
const digits = raw.replace(/\D/g, "");
|
|
431
|
+
if (digits.length !== 7) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
return Number(digits);
|
|
435
|
+
}
|
|
436
|
+
function formatMunicipioHuman(municipio) {
|
|
437
|
+
return `${municipio.codigo} \u2014 ${municipio.nome} (${municipio.uf})`;
|
|
438
|
+
}
|
|
439
|
+
function runIbgeLookupCommand(input, options, io = { stdout: [], stderr: [] }) {
|
|
440
|
+
const codigo = normalizeIbgeMunicipioCode(input);
|
|
441
|
+
if (codigo === null) {
|
|
442
|
+
io.stderr.push("Invalid IBGE municipality code. Use 7 digits (e.g. 3550308).");
|
|
443
|
+
return EXIT.USAGE;
|
|
444
|
+
}
|
|
445
|
+
const municipio = getMunicipioPorCodigo(codigo);
|
|
446
|
+
if (!municipio) {
|
|
447
|
+
io.stderr.push(`Municipality not found: ${input}`);
|
|
448
|
+
return EXIT.INVALID;
|
|
449
|
+
}
|
|
450
|
+
if (options.json) {
|
|
451
|
+
const payload = {
|
|
452
|
+
ok: true,
|
|
453
|
+
municipio
|
|
454
|
+
};
|
|
455
|
+
if (options.verbose) {
|
|
456
|
+
payload.capturadoEm = IBGE_DATA_VERSION.capturadoEm;
|
|
457
|
+
}
|
|
458
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
459
|
+
return EXIT.OK;
|
|
460
|
+
}
|
|
461
|
+
io.stdout.push(formatMunicipioHuman(municipio));
|
|
462
|
+
if (options.verbose) {
|
|
463
|
+
io.stdout.push(`capturadoEm: ${IBGE_DATA_VERSION.capturadoEm}`);
|
|
464
|
+
}
|
|
465
|
+
return EXIT.OK;
|
|
466
|
+
}
|
|
467
|
+
function runIbgeLookup(value, options, io = { stdout: [], stderr: [] }) {
|
|
468
|
+
if (!value?.trim()) {
|
|
469
|
+
io.stderr.push("Missing IBGE municipality code. Pass a 7-digit code.");
|
|
470
|
+
return EXIT.USAGE;
|
|
471
|
+
}
|
|
472
|
+
return runIbgeLookupCommand(value.trim(), options, io);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/commands/ibge/list.ts
|
|
476
|
+
import {
|
|
477
|
+
getEstados,
|
|
478
|
+
getMunicipios,
|
|
479
|
+
IBGE_DATA_VERSION as IBGE_DATA_VERSION2
|
|
480
|
+
} from "@br-validators/core/ibge";
|
|
481
|
+
function sliceRows(rows, limit) {
|
|
482
|
+
if (limit === void 0 || !Number.isFinite(limit) || limit <= 0) {
|
|
483
|
+
return rows;
|
|
484
|
+
}
|
|
485
|
+
return rows.slice(0, limit);
|
|
486
|
+
}
|
|
487
|
+
function formatEstadoHuman(estado) {
|
|
488
|
+
return `${estado.codigo} \u2014 ${estado.sigla} \u2014 ${estado.nome}`;
|
|
489
|
+
}
|
|
490
|
+
function runIbgeListEstadosCommand(options, io = { stdout: [], stderr: [] }) {
|
|
491
|
+
const estados = sliceRows(getEstados(), options.limit);
|
|
492
|
+
if (options.json) {
|
|
493
|
+
const payload = {
|
|
494
|
+
ok: true,
|
|
495
|
+
total: estados.length,
|
|
496
|
+
estados
|
|
497
|
+
};
|
|
498
|
+
if (options.verbose) {
|
|
499
|
+
payload.capturadoEm = IBGE_DATA_VERSION2.capturadoEm;
|
|
500
|
+
}
|
|
501
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
502
|
+
return EXIT.OK;
|
|
503
|
+
}
|
|
504
|
+
for (const estado of estados) {
|
|
505
|
+
io.stdout.push(formatEstadoHuman(estado));
|
|
506
|
+
}
|
|
507
|
+
if (options.verbose) {
|
|
508
|
+
io.stdout.push(`capturadoEm: ${IBGE_DATA_VERSION2.capturadoEm}`);
|
|
509
|
+
}
|
|
510
|
+
return EXIT.OK;
|
|
511
|
+
}
|
|
512
|
+
function runIbgeListMunicipiosCommand(options, io = { stdout: [], stderr: [] }) {
|
|
513
|
+
const uf = options.uf?.trim().toUpperCase();
|
|
514
|
+
const municipios = sliceRows(getMunicipios(uf ? { uf } : void 0), options.limit);
|
|
515
|
+
if (options.json) {
|
|
516
|
+
const payload = {
|
|
517
|
+
ok: true,
|
|
518
|
+
total: municipios.length,
|
|
519
|
+
municipios,
|
|
520
|
+
...uf ? { uf } : {}
|
|
521
|
+
};
|
|
522
|
+
if (options.verbose) {
|
|
523
|
+
payload.capturadoEm = IBGE_DATA_VERSION2.capturadoEm;
|
|
524
|
+
}
|
|
525
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
526
|
+
return EXIT.OK;
|
|
527
|
+
}
|
|
528
|
+
for (const municipio of municipios) {
|
|
529
|
+
io.stdout.push(formatMunicipioHuman(municipio));
|
|
530
|
+
}
|
|
531
|
+
if (options.verbose) {
|
|
532
|
+
io.stdout.push(`capturadoEm: ${IBGE_DATA_VERSION2.capturadoEm}`);
|
|
533
|
+
}
|
|
534
|
+
return EXIT.OK;
|
|
535
|
+
}
|
|
536
|
+
function runIbgeList(target, options, io = { stdout: [], stderr: [] }) {
|
|
537
|
+
if (target === "estados") {
|
|
538
|
+
return runIbgeListEstadosCommand(options, io);
|
|
539
|
+
}
|
|
540
|
+
return runIbgeListMunicipiosCommand(options, io);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// src/commands/feriados/list.ts
|
|
544
|
+
import {
|
|
545
|
+
FERIADOS_DATA_VERSION,
|
|
546
|
+
getFeriadosNacionais
|
|
547
|
+
} from "@br-validators/core/feriados";
|
|
548
|
+
function resolveYear(year) {
|
|
549
|
+
if (year !== void 0 && Number.isInteger(year) && year >= 1900 && year <= 2100) {
|
|
550
|
+
return year;
|
|
551
|
+
}
|
|
552
|
+
return (/* @__PURE__ */ new Date()).getUTCFullYear();
|
|
553
|
+
}
|
|
554
|
+
function formatFeriadoHuman(feriado) {
|
|
555
|
+
return `${feriado.data} \u2014 ${feriado.nome} (${feriado.tipo})`;
|
|
556
|
+
}
|
|
557
|
+
function runFeriadosListCommand(options, io = { stdout: [], stderr: [] }) {
|
|
558
|
+
const year = resolveYear(options.year);
|
|
559
|
+
const feriados = getFeriadosNacionais(year);
|
|
560
|
+
if (options.json) {
|
|
561
|
+
const payload = {
|
|
562
|
+
ok: true,
|
|
563
|
+
year,
|
|
564
|
+
total: feriados.length,
|
|
565
|
+
feriados
|
|
566
|
+
};
|
|
567
|
+
if (options.verbose) {
|
|
568
|
+
payload.capturadoEm = FERIADOS_DATA_VERSION.capturadoEm;
|
|
569
|
+
}
|
|
570
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
571
|
+
return EXIT.OK;
|
|
572
|
+
}
|
|
573
|
+
for (const feriado of feriados) {
|
|
574
|
+
io.stdout.push(formatFeriadoHuman(feriado));
|
|
575
|
+
}
|
|
576
|
+
if (options.verbose) {
|
|
577
|
+
io.stdout.push(`capturadoEm: ${FERIADOS_DATA_VERSION.capturadoEm}`);
|
|
578
|
+
}
|
|
579
|
+
return EXIT.OK;
|
|
580
|
+
}
|
|
581
|
+
function runFeriadosList(options, io = { stdout: [], stderr: [] }) {
|
|
582
|
+
return runFeriadosListCommand(options, io);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/commands/tse-municipios/lookup.ts
|
|
586
|
+
import {
|
|
587
|
+
getCodigosTsePorMunicipio,
|
|
588
|
+
getMunicipioIbgePorCodigoTse,
|
|
589
|
+
TSE_MUNICIPIOS_DATA_VERSION
|
|
590
|
+
} from "@br-validators/core/tse-municipios";
|
|
591
|
+
import { getMunicipioPorCodigo as getMunicipioPorCodigo2 } from "@br-validators/core/ibge";
|
|
592
|
+
function normalizeTseInput(raw) {
|
|
593
|
+
const digits = raw.replace(/\D/g, "");
|
|
594
|
+
if (digits.length === 5) {
|
|
595
|
+
return { kind: "tse", value: digits.padStart(5, "0") };
|
|
596
|
+
}
|
|
597
|
+
if (digits.length === 7) {
|
|
598
|
+
return { kind: "ibge", value: Number(digits) };
|
|
599
|
+
}
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
function lookupTseMunicipio(raw) {
|
|
603
|
+
const normalized = normalizeTseInput(raw);
|
|
604
|
+
if (!normalized) {
|
|
605
|
+
return void 0;
|
|
606
|
+
}
|
|
607
|
+
if (normalized.kind === "tse") {
|
|
608
|
+
const ibgeCodigo = getMunicipioIbgePorCodigoTse(normalized.value);
|
|
609
|
+
if (ibgeCodigo === void 0) {
|
|
610
|
+
return void 0;
|
|
611
|
+
}
|
|
612
|
+
return { kind: "tse-to-ibge", codigoTse: normalized.value, ibgeCodigo };
|
|
613
|
+
}
|
|
614
|
+
const codigosTse = getCodigosTsePorMunicipio(normalized.value);
|
|
615
|
+
if (codigosTse.length === 0) {
|
|
616
|
+
return void 0;
|
|
617
|
+
}
|
|
618
|
+
return { kind: "ibge-to-tse", ibgeCodigo: normalized.value, codigosTse };
|
|
619
|
+
}
|
|
620
|
+
function formatTseLookupHuman(result) {
|
|
621
|
+
if (result.kind === "tse-to-ibge") {
|
|
622
|
+
const municipio2 = getMunicipioPorCodigo2(result.ibgeCodigo);
|
|
623
|
+
const name2 = municipio2 ? `${municipio2.nome} (${municipio2.uf})` : String(result.ibgeCodigo);
|
|
624
|
+
return `TSE ${result.codigoTse} \u2192 IBGE ${result.ibgeCodigo} \u2014 ${name2}`;
|
|
625
|
+
}
|
|
626
|
+
const municipio = getMunicipioPorCodigo2(result.ibgeCodigo);
|
|
627
|
+
const name = municipio ? `${municipio.nome} (${municipio.uf})` : String(result.ibgeCodigo);
|
|
628
|
+
return `IBGE ${result.ibgeCodigo} \u2014 ${name} \u2192 TSE ${result.codigosTse.join(", ")}`;
|
|
629
|
+
}
|
|
630
|
+
function runTseMunicipiosLookupCommand(input, options, io = { stdout: [], stderr: [] }) {
|
|
631
|
+
const normalized = normalizeTseInput(input);
|
|
632
|
+
if (!normalized) {
|
|
633
|
+
io.stderr.push("Invalid code. Use 5-digit TSE or 7-digit IBGE municipality code.");
|
|
634
|
+
return EXIT.USAGE;
|
|
635
|
+
}
|
|
636
|
+
const result = lookupTseMunicipio(input);
|
|
637
|
+
if (!result) {
|
|
638
|
+
io.stderr.push(`Mapping not found: ${input}`);
|
|
639
|
+
return EXIT.INVALID;
|
|
640
|
+
}
|
|
641
|
+
if (options.json) {
|
|
642
|
+
const payload = {
|
|
643
|
+
ok: true,
|
|
644
|
+
mapping: result
|
|
645
|
+
};
|
|
646
|
+
if (options.verbose) {
|
|
647
|
+
payload.capturadoEm = TSE_MUNICIPIOS_DATA_VERSION.capturadoEm;
|
|
648
|
+
}
|
|
649
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
650
|
+
return EXIT.OK;
|
|
651
|
+
}
|
|
652
|
+
io.stdout.push(formatTseLookupHuman(result));
|
|
653
|
+
if (options.verbose) {
|
|
654
|
+
io.stdout.push(`capturadoEm: ${TSE_MUNICIPIOS_DATA_VERSION.capturadoEm}`);
|
|
655
|
+
}
|
|
656
|
+
return EXIT.OK;
|
|
657
|
+
}
|
|
658
|
+
function runTseMunicipiosLookup(value, options, io = { stdout: [], stderr: [] }) {
|
|
659
|
+
if (!value?.trim()) {
|
|
660
|
+
io.stderr.push("Missing code. Pass a 5-digit TSE or 7-digit IBGE municipality code.");
|
|
661
|
+
return EXIT.USAGE;
|
|
662
|
+
}
|
|
663
|
+
return runTseMunicipiosLookupCommand(value.trim(), options, io);
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/commands/cep/faixa.ts
|
|
667
|
+
import {
|
|
668
|
+
CEP_FAIXA_DATA_VERSION,
|
|
669
|
+
getCepFaixaInfo
|
|
670
|
+
} from "@br-validators/core/cep";
|
|
671
|
+
function normalizePrefix(raw) {
|
|
672
|
+
const digits = raw.replace(/\D/g, "");
|
|
673
|
+
if (digits.length < 5) {
|
|
674
|
+
return null;
|
|
675
|
+
}
|
|
676
|
+
return digits.slice(0, 5);
|
|
677
|
+
}
|
|
678
|
+
function formatCepFaixaHuman(faixa) {
|
|
679
|
+
return `${faixa.prefixo} \u2014 ${faixa.cidade} (${faixa.uf}) \xB7 IBGE ${faixa.codigoIbge}`;
|
|
680
|
+
}
|
|
681
|
+
function runCepFaixaCommand(input, options, io = { stdout: [], stderr: [] }) {
|
|
682
|
+
const prefix = normalizePrefix(input);
|
|
683
|
+
if (prefix === null) {
|
|
684
|
+
io.stderr.push("Invalid CEP prefix. Use at least 5 digits (e.g. 01310).");
|
|
685
|
+
return EXIT.USAGE;
|
|
686
|
+
}
|
|
687
|
+
const faixa = getCepFaixaInfo(prefix);
|
|
688
|
+
if (!faixa) {
|
|
689
|
+
io.stderr.push(`CEP prefix not found: ${input}`);
|
|
690
|
+
return EXIT.INVALID;
|
|
691
|
+
}
|
|
692
|
+
if (options.json) {
|
|
693
|
+
const payload = {
|
|
694
|
+
ok: true,
|
|
695
|
+
faixa
|
|
696
|
+
};
|
|
697
|
+
if (options.verbose) {
|
|
698
|
+
payload.capturadoEm = CEP_FAIXA_DATA_VERSION.capturadoEm;
|
|
699
|
+
}
|
|
700
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
701
|
+
return EXIT.OK;
|
|
702
|
+
}
|
|
703
|
+
io.stdout.push(formatCepFaixaHuman(faixa));
|
|
704
|
+
if (options.verbose) {
|
|
705
|
+
io.stdout.push(`capturadoEm: ${CEP_FAIXA_DATA_VERSION.capturadoEm}`);
|
|
706
|
+
}
|
|
707
|
+
return EXIT.OK;
|
|
708
|
+
}
|
|
709
|
+
function runCepFaixa(value, options, io = { stdout: [], stderr: [] }) {
|
|
710
|
+
if (!value?.trim()) {
|
|
711
|
+
io.stderr.push("Missing CEP prefix. Pass at least 5 digits.");
|
|
712
|
+
return EXIT.USAGE;
|
|
713
|
+
}
|
|
714
|
+
return runCepFaixaCommand(value.trim(), options, io);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// src/commands/ddd/lookup.ts
|
|
718
|
+
import {
|
|
719
|
+
getDddInfo,
|
|
720
|
+
TELEFONE_DDD_DATA_VERSION
|
|
721
|
+
} from "@br-validators/core/telefone";
|
|
722
|
+
function normalizeDdd(raw) {
|
|
723
|
+
const digits = raw.replace(/\D/g, "");
|
|
724
|
+
if (digits.length === 0) {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
return digits.padStart(2, "0").slice(-2);
|
|
728
|
+
}
|
|
729
|
+
function formatDddHuman(info) {
|
|
730
|
+
const municipios = info.municipios.slice(0, 3).join(", ");
|
|
731
|
+
const suffix = info.municipios.length > 3 ? "\u2026" : "";
|
|
732
|
+
return `DDD ${info.ddd} \u2014 ${info.uf} / ${info.regiao} \u2014 ${municipios}${suffix}`;
|
|
733
|
+
}
|
|
734
|
+
function runDddLookupCommand(input, options, io = { stdout: [], stderr: [] }) {
|
|
735
|
+
const ddd = normalizeDdd(input);
|
|
736
|
+
if (ddd === null) {
|
|
737
|
+
io.stderr.push("Invalid DDD. Use 2 digits (e.g. 11).");
|
|
738
|
+
return EXIT.USAGE;
|
|
739
|
+
}
|
|
740
|
+
const info = getDddInfo(ddd);
|
|
741
|
+
if (!info) {
|
|
742
|
+
io.stderr.push(`DDD not found: ${input}`);
|
|
743
|
+
return EXIT.INVALID;
|
|
744
|
+
}
|
|
745
|
+
if (options.json) {
|
|
746
|
+
const payload = {
|
|
747
|
+
ok: true,
|
|
748
|
+
ddd: info
|
|
749
|
+
};
|
|
750
|
+
if (options.verbose) {
|
|
751
|
+
payload.capturadoEm = TELEFONE_DDD_DATA_VERSION.capturadoEm;
|
|
752
|
+
}
|
|
753
|
+
io.stdout.push(JSON.stringify(payload, null, 2));
|
|
754
|
+
return EXIT.OK;
|
|
755
|
+
}
|
|
756
|
+
io.stdout.push(formatDddHuman(info));
|
|
757
|
+
if (options.verbose) {
|
|
758
|
+
io.stdout.push(`capturadoEm: ${TELEFONE_DDD_DATA_VERSION.capturadoEm}`);
|
|
759
|
+
}
|
|
760
|
+
return EXIT.OK;
|
|
761
|
+
}
|
|
762
|
+
function runDddLookup(value, options, io = { stdout: [], stderr: [] }) {
|
|
763
|
+
if (!value?.trim()) {
|
|
764
|
+
io.stderr.push("Missing DDD code. Pass 2 digits (e.g. 11).");
|
|
765
|
+
return EXIT.USAGE;
|
|
766
|
+
}
|
|
767
|
+
return runDddLookupCommand(value.trim(), options, io);
|
|
768
|
+
}
|
|
769
|
+
|
|
16
770
|
// src/commands/brcode.ts
|
|
17
771
|
import {
|
|
18
772
|
BRCODE_OFFICIAL_SOURCE_URL,
|
|
@@ -173,6 +927,45 @@ function printNfeChaveValidation(result, options, io = { stdout: [], stderr: []
|
|
|
173
927
|
io.stderr.push(`message: ${result.message}`);
|
|
174
928
|
return EXIT.INVALID;
|
|
175
929
|
}
|
|
930
|
+
function printProcessoJudicialValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
931
|
+
if (options.json) {
|
|
932
|
+
io.stdout.push(
|
|
933
|
+
JSON.stringify(
|
|
934
|
+
result.ok ? {
|
|
935
|
+
ok: true,
|
|
936
|
+
value: result.value,
|
|
937
|
+
format: result.format,
|
|
938
|
+
segments: result.segments,
|
|
939
|
+
...options.source ? { source: options.source } : {}
|
|
940
|
+
} : { ok: false, code: result.code, message: result.message },
|
|
941
|
+
null,
|
|
942
|
+
2
|
|
943
|
+
)
|
|
944
|
+
);
|
|
945
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
946
|
+
}
|
|
947
|
+
if (options.quiet) {
|
|
948
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
949
|
+
}
|
|
950
|
+
if (result.ok) {
|
|
951
|
+
io.stdout.push(`valid: yes (${result.format})`);
|
|
952
|
+
io.stdout.push(`value: ${result.value}`);
|
|
953
|
+
io.stdout.push(`sequencial: ${result.segments.sequencial}`);
|
|
954
|
+
io.stdout.push(`checkDigits: ${result.segments.checkDigits}`);
|
|
955
|
+
io.stdout.push(`ano: ${result.segments.ano}`);
|
|
956
|
+
io.stdout.push(`segmentoJustica: ${result.segments.segmentoJustica}`);
|
|
957
|
+
io.stdout.push(`tribunal: ${result.segments.tribunal}`);
|
|
958
|
+
io.stdout.push(`origem: ${result.segments.origem}`);
|
|
959
|
+
if (options.source) {
|
|
960
|
+
io.stdout.push(`source: ${options.source}`);
|
|
961
|
+
}
|
|
962
|
+
return EXIT.OK;
|
|
963
|
+
}
|
|
964
|
+
io.stderr.push("valid: no");
|
|
965
|
+
io.stderr.push(`code: ${result.code}`);
|
|
966
|
+
io.stderr.push(`message: ${result.message}`);
|
|
967
|
+
return EXIT.INVALID;
|
|
968
|
+
}
|
|
176
969
|
function printFormat(result, options, io = { stdout: [], stderr: [] }) {
|
|
177
970
|
if (options.json) {
|
|
178
971
|
io.stdout.push(JSON.stringify(result, null, 2));
|
|
@@ -343,6 +1136,146 @@ function runCnh(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
|
343
1136
|
return runCnhCommand(action, input, options, io);
|
|
344
1137
|
}
|
|
345
1138
|
|
|
1139
|
+
// src/commands/processo-judicial.ts
|
|
1140
|
+
import {
|
|
1141
|
+
PROCESSO_JUDICIAL_OFFICIAL_SOURCE_URL,
|
|
1142
|
+
formatProcessoJudicial,
|
|
1143
|
+
stripProcessoJudicial,
|
|
1144
|
+
validateProcessoJudicial
|
|
1145
|
+
} from "@br-validators/core/processo-judicial";
|
|
1146
|
+
function resolveInput5(value, fileContent) {
|
|
1147
|
+
const input = value ?? fileContent?.trim();
|
|
1148
|
+
if (!input) {
|
|
1149
|
+
return null;
|
|
1150
|
+
}
|
|
1151
|
+
return input;
|
|
1152
|
+
}
|
|
1153
|
+
function runProcessoJudicialCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
1154
|
+
const source = options.source ? PROCESSO_JUDICIAL_OFFICIAL_SOURCE_URL : void 0;
|
|
1155
|
+
switch (action) {
|
|
1156
|
+
case "validate":
|
|
1157
|
+
return printValidation(validateProcessoJudicial(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
1158
|
+
case "parse":
|
|
1159
|
+
return printProcessoJudicialValidation(validateProcessoJudicial(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
1160
|
+
case "format":
|
|
1161
|
+
return printFormat(formatProcessoJudicial(input), { json: options.json, quiet: options.quiet }, io);
|
|
1162
|
+
case "strip":
|
|
1163
|
+
return printStrip(stripProcessoJudicial(input), { json: options.json }, io);
|
|
1164
|
+
default: {
|
|
1165
|
+
const _exhaustive = action;
|
|
1166
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
1167
|
+
return EXIT.USAGE;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
function runProcessoJudicial(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
1172
|
+
const input = resolveInput5(value, options.file);
|
|
1173
|
+
if (input === null) {
|
|
1174
|
+
io.stderr.push("Missing processo judicial value. Pass an argument or use --file.");
|
|
1175
|
+
return EXIT.USAGE;
|
|
1176
|
+
}
|
|
1177
|
+
return runProcessoJudicialCommand(action, input, options, io);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/commands/rg.ts
|
|
1181
|
+
import {
|
|
1182
|
+
RG_SUPPORTED_UFS,
|
|
1183
|
+
formatRg,
|
|
1184
|
+
getRgOfficialSourceUrl,
|
|
1185
|
+
stripRg,
|
|
1186
|
+
validateRg
|
|
1187
|
+
} from "@br-validators/core/rg";
|
|
1188
|
+
function resolveInput6(value, fileContent) {
|
|
1189
|
+
const input = value ?? fileContent?.trim();
|
|
1190
|
+
if (!input) {
|
|
1191
|
+
return null;
|
|
1192
|
+
}
|
|
1193
|
+
return input;
|
|
1194
|
+
}
|
|
1195
|
+
function resolveRgUf(uf) {
|
|
1196
|
+
if (uf === void 0) {
|
|
1197
|
+
return null;
|
|
1198
|
+
}
|
|
1199
|
+
const normalized = uf.toUpperCase();
|
|
1200
|
+
if (RG_SUPPORTED_UFS.includes(normalized)) {
|
|
1201
|
+
return normalized;
|
|
1202
|
+
}
|
|
1203
|
+
return null;
|
|
1204
|
+
}
|
|
1205
|
+
function printRgValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
1206
|
+
if (options.json) {
|
|
1207
|
+
io.stdout.push(
|
|
1208
|
+
JSON.stringify(
|
|
1209
|
+
result.ok ? {
|
|
1210
|
+
ok: true,
|
|
1211
|
+
value: result.value,
|
|
1212
|
+
uf: result.uf,
|
|
1213
|
+
format: result.format,
|
|
1214
|
+
checkDigitValidated: result.checkDigitValidated,
|
|
1215
|
+
...options.source ? { source: options.source } : {}
|
|
1216
|
+
} : {
|
|
1217
|
+
ok: false,
|
|
1218
|
+
code: result.code,
|
|
1219
|
+
message: result.message,
|
|
1220
|
+
...result.uf ? { uf: result.uf } : {}
|
|
1221
|
+
},
|
|
1222
|
+
null,
|
|
1223
|
+
2
|
|
1224
|
+
)
|
|
1225
|
+
);
|
|
1226
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1227
|
+
}
|
|
1228
|
+
if (options.quiet) {
|
|
1229
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1230
|
+
}
|
|
1231
|
+
if (result.ok) {
|
|
1232
|
+
io.stdout.push(`valid: yes (${result.uf})`);
|
|
1233
|
+
io.stdout.push(`checkDigitValidated: ${result.checkDigitValidated ? "yes" : "no"}`);
|
|
1234
|
+
io.stdout.push(`value: ${result.value}`);
|
|
1235
|
+
io.stdout.push(`format: ${result.format}`);
|
|
1236
|
+
if (options.source) {
|
|
1237
|
+
io.stdout.push(`source: ${options.source}`);
|
|
1238
|
+
}
|
|
1239
|
+
return EXIT.OK;
|
|
1240
|
+
}
|
|
1241
|
+
io.stderr.push("valid: no");
|
|
1242
|
+
io.stderr.push(`code: ${result.code}`);
|
|
1243
|
+
io.stderr.push(`message: ${result.message}`);
|
|
1244
|
+
if (result.uf) {
|
|
1245
|
+
io.stderr.push(`uf: ${result.uf}`);
|
|
1246
|
+
}
|
|
1247
|
+
return EXIT.INVALID;
|
|
1248
|
+
}
|
|
1249
|
+
function runRgCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
1250
|
+
const uf = resolveRgUf(options.uf);
|
|
1251
|
+
if (!uf) {
|
|
1252
|
+
io.stderr.push(`Missing or invalid --uf. Use one of: ${RG_SUPPORTED_UFS.join(", ")}.`);
|
|
1253
|
+
return EXIT.USAGE;
|
|
1254
|
+
}
|
|
1255
|
+
const source = options.source ? getRgOfficialSourceUrl(uf) : void 0;
|
|
1256
|
+
switch (action) {
|
|
1257
|
+
case "validate":
|
|
1258
|
+
return printRgValidation(validateRg(input, { uf }), { json: options.json, quiet: options.quiet, source }, io);
|
|
1259
|
+
case "format":
|
|
1260
|
+
return printFormat(formatRg(input, { uf }), { json: options.json, quiet: options.quiet }, io);
|
|
1261
|
+
case "strip":
|
|
1262
|
+
return printStrip(stripRg(input, { uf }), { json: options.json }, io);
|
|
1263
|
+
default: {
|
|
1264
|
+
const _exhaustive = action;
|
|
1265
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
1266
|
+
return EXIT.USAGE;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
function runRg(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
1271
|
+
const input = resolveInput6(value, options.file);
|
|
1272
|
+
if (input === null) {
|
|
1273
|
+
io.stderr.push("Missing RG value. Pass an argument or use --file.");
|
|
1274
|
+
return EXIT.USAGE;
|
|
1275
|
+
}
|
|
1276
|
+
return runRgCommand(action, input, options, io);
|
|
1277
|
+
}
|
|
1278
|
+
|
|
346
1279
|
// src/commands/renavam.ts
|
|
347
1280
|
import {
|
|
348
1281
|
RENAVAM_OFFICIAL_SOURCE_URL,
|
|
@@ -350,7 +1283,7 @@ import {
|
|
|
350
1283
|
stripRenavam,
|
|
351
1284
|
validateRenavam
|
|
352
1285
|
} from "@br-validators/core";
|
|
353
|
-
function
|
|
1286
|
+
function resolveInput7(value, fileContent) {
|
|
354
1287
|
const input = value ?? fileContent?.trim();
|
|
355
1288
|
if (!input) {
|
|
356
1289
|
return null;
|
|
@@ -374,7 +1307,7 @@ function runRenavamCommand(action, input, options, io = { stdout: [], stderr: []
|
|
|
374
1307
|
}
|
|
375
1308
|
}
|
|
376
1309
|
function runRenavam(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
377
|
-
const input =
|
|
1310
|
+
const input = resolveInput7(value, options.file);
|
|
378
1311
|
if (input === null) {
|
|
379
1312
|
io.stderr.push("Missing RENAVAM value. Pass an argument or use --file.");
|
|
380
1313
|
return EXIT.USAGE;
|
|
@@ -389,7 +1322,7 @@ import {
|
|
|
389
1322
|
stripTituloEleitor,
|
|
390
1323
|
validateTituloEleitor
|
|
391
1324
|
} from "@br-validators/core";
|
|
392
|
-
function
|
|
1325
|
+
function resolveInput8(value, fileContent) {
|
|
393
1326
|
const input = value ?? fileContent?.trim();
|
|
394
1327
|
if (!input) {
|
|
395
1328
|
return null;
|
|
@@ -413,7 +1346,7 @@ function runTituloEleitorCommand(action, input, options, io = { stdout: [], stde
|
|
|
413
1346
|
}
|
|
414
1347
|
}
|
|
415
1348
|
function runTituloEleitor(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
416
|
-
const input =
|
|
1349
|
+
const input = resolveInput8(value, options.file);
|
|
417
1350
|
if (input === null) {
|
|
418
1351
|
io.stderr.push("Missing T\xEDtulo de Eleitor value. Pass an argument or use --file.");
|
|
419
1352
|
return EXIT.USAGE;
|
|
@@ -429,7 +1362,7 @@ import {
|
|
|
429
1362
|
stripNfeChave,
|
|
430
1363
|
validateNfeChave
|
|
431
1364
|
} from "@br-validators/core";
|
|
432
|
-
function
|
|
1365
|
+
function resolveInput9(value, fileContent) {
|
|
433
1366
|
const input = value ?? fileContent?.trim();
|
|
434
1367
|
if (!input) {
|
|
435
1368
|
return null;
|
|
@@ -455,7 +1388,7 @@ function runNfeChaveCommand(action, input, options, io = { stdout: [], stderr: [
|
|
|
455
1388
|
}
|
|
456
1389
|
}
|
|
457
1390
|
function runNfeChave(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
458
|
-
const input =
|
|
1391
|
+
const input = resolveInput9(value, options.file);
|
|
459
1392
|
if (input === null) {
|
|
460
1393
|
io.stderr.push("Missing NF-e chave de acesso value. Pass an argument or use --file.");
|
|
461
1394
|
return EXIT.USAGE;
|
|
@@ -470,7 +1403,7 @@ import {
|
|
|
470
1403
|
stripCnpj,
|
|
471
1404
|
validateCnpj
|
|
472
1405
|
} from "@br-validators/core";
|
|
473
|
-
function
|
|
1406
|
+
function resolveInput10(value, fileContent) {
|
|
474
1407
|
const input = value ?? fileContent?.trim();
|
|
475
1408
|
if (!input) {
|
|
476
1409
|
return null;
|
|
@@ -494,7 +1427,7 @@ function runCnpjCommand(action, input, options, io = { stdout: [], stderr: [] })
|
|
|
494
1427
|
}
|
|
495
1428
|
}
|
|
496
1429
|
function runCnpj(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
497
|
-
const input =
|
|
1430
|
+
const input = resolveInput10(value, options.file);
|
|
498
1431
|
if (input === null) {
|
|
499
1432
|
io.stderr.push("Missing CNPJ value. Pass an argument or use --file.");
|
|
500
1433
|
return EXIT.USAGE;
|
|
@@ -509,7 +1442,7 @@ import {
|
|
|
509
1442
|
stripCpf,
|
|
510
1443
|
validateCpf
|
|
511
1444
|
} from "@br-validators/core";
|
|
512
|
-
function
|
|
1445
|
+
function resolveInput11(value, fileContent) {
|
|
513
1446
|
const input = value ?? fileContent?.trim();
|
|
514
1447
|
if (!input) {
|
|
515
1448
|
return null;
|
|
@@ -533,7 +1466,7 @@ function runCpfCommand(action, input, options, io = { stdout: [], stderr: [] })
|
|
|
533
1466
|
}
|
|
534
1467
|
}
|
|
535
1468
|
function runCpf(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
536
|
-
const input =
|
|
1469
|
+
const input = resolveInput11(value, options.file);
|
|
537
1470
|
if (input === null) {
|
|
538
1471
|
io.stderr.push("Missing CPF value. Pass an argument or use --file.");
|
|
539
1472
|
return EXIT.USAGE;
|
|
@@ -549,7 +1482,7 @@ import {
|
|
|
549
1482
|
stripPlaca,
|
|
550
1483
|
validatePlaca
|
|
551
1484
|
} from "@br-validators/core";
|
|
552
|
-
function
|
|
1485
|
+
function resolveInput12(value, fileContent) {
|
|
553
1486
|
const input = value ?? fileContent?.trim();
|
|
554
1487
|
if (!input) {
|
|
555
1488
|
return null;
|
|
@@ -575,7 +1508,7 @@ function runPlacaCommand(action, input, options, io = { stdout: [], stderr: [] }
|
|
|
575
1508
|
}
|
|
576
1509
|
}
|
|
577
1510
|
function runPlaca(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
578
|
-
const input =
|
|
1511
|
+
const input = resolveInput12(value, options.file);
|
|
579
1512
|
if (input === null) {
|
|
580
1513
|
io.stderr.push("Missing placa value. Pass an argument or use --file.");
|
|
581
1514
|
return EXIT.USAGE;
|
|
@@ -590,7 +1523,7 @@ import {
|
|
|
590
1523
|
stripPisPasep,
|
|
591
1524
|
validatePisPasep
|
|
592
1525
|
} from "@br-validators/core";
|
|
593
|
-
function
|
|
1526
|
+
function resolveInput13(value, fileContent) {
|
|
594
1527
|
const input = value ?? fileContent?.trim();
|
|
595
1528
|
if (!input) {
|
|
596
1529
|
return null;
|
|
@@ -614,7 +1547,7 @@ function runPisPasepCommand(action, input, options, io = { stdout: [], stderr: [
|
|
|
614
1547
|
}
|
|
615
1548
|
}
|
|
616
1549
|
function runPisPasep(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
617
|
-
const input =
|
|
1550
|
+
const input = resolveInput13(value, options.file);
|
|
618
1551
|
if (input === null) {
|
|
619
1552
|
io.stderr.push("Missing PIS/PASEP value. Pass an argument or use --file.");
|
|
620
1553
|
return EXIT.USAGE;
|
|
@@ -629,7 +1562,7 @@ import {
|
|
|
629
1562
|
formatPixKey,
|
|
630
1563
|
validatePixKey
|
|
631
1564
|
} from "@br-validators/core";
|
|
632
|
-
function
|
|
1565
|
+
function resolveInput14(value, fileContent) {
|
|
633
1566
|
const input = value ?? fileContent?.trim();
|
|
634
1567
|
if (!input) {
|
|
635
1568
|
return null;
|
|
@@ -704,7 +1637,7 @@ function runPixCommand(action, input, options, io = { stdout: [], stderr: [] })
|
|
|
704
1637
|
}
|
|
705
1638
|
}
|
|
706
1639
|
function runPix(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
707
|
-
const input =
|
|
1640
|
+
const input = resolveInput14(value, options.file);
|
|
708
1641
|
if (input === null) {
|
|
709
1642
|
io.stderr.push("Missing PIX key value. Pass an argument or use --file.");
|
|
710
1643
|
return EXIT.USAGE;
|
|
@@ -723,7 +1656,7 @@ import {
|
|
|
723
1656
|
stripLinhaDigitavel,
|
|
724
1657
|
validateBoleto
|
|
725
1658
|
} from "@br-validators/core";
|
|
726
|
-
function
|
|
1659
|
+
function resolveInput15(value, fileContent) {
|
|
727
1660
|
const input = value ?? fileContent?.trim();
|
|
728
1661
|
if (!input) {
|
|
729
1662
|
return null;
|
|
@@ -858,7 +1791,7 @@ function runBoletoCommand(action, input, options, direction, io = { stdout: [],
|
|
|
858
1791
|
}
|
|
859
1792
|
}
|
|
860
1793
|
function runBoleto(action, value, options, direction, io = { stdout: [], stderr: [] }) {
|
|
861
|
-
const input =
|
|
1794
|
+
const input = resolveInput15(value, options.file);
|
|
862
1795
|
if (input === null) {
|
|
863
1796
|
io.stderr.push("Missing boleto value. Pass an argument or use --file.");
|
|
864
1797
|
return EXIT.USAGE;
|
|
@@ -874,7 +1807,7 @@ import {
|
|
|
874
1807
|
stripCartaoCredito,
|
|
875
1808
|
validateCartaoCredito
|
|
876
1809
|
} from "@br-validators/core";
|
|
877
|
-
function
|
|
1810
|
+
function resolveInput16(value, fileContent) {
|
|
878
1811
|
const input = value ?? fileContent?.trim();
|
|
879
1812
|
if (!input) {
|
|
880
1813
|
return null;
|
|
@@ -950,7 +1883,7 @@ function runCartaoCommand(action, input, options, io = { stdout: [], stderr: []
|
|
|
950
1883
|
}
|
|
951
1884
|
}
|
|
952
1885
|
function runCartao(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
953
|
-
const input =
|
|
1886
|
+
const input = resolveInput16(value, options.file);
|
|
954
1887
|
if (input === null) {
|
|
955
1888
|
io.stderr.push("Missing credit card PAN value. Pass an argument or use --file.");
|
|
956
1889
|
return EXIT.USAGE;
|
|
@@ -971,7 +1904,7 @@ import {
|
|
|
971
1904
|
validateIeProdutorRural,
|
|
972
1905
|
validateInscricaoEstadual
|
|
973
1906
|
} from "@br-validators/core";
|
|
974
|
-
function
|
|
1907
|
+
function resolveInput17(value, fileContent) {
|
|
975
1908
|
const input = value ?? fileContent?.trim();
|
|
976
1909
|
if (!input) {
|
|
977
1910
|
return null;
|
|
@@ -1068,7 +2001,7 @@ function runIeCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
|
1068
2001
|
}
|
|
1069
2002
|
}
|
|
1070
2003
|
function runIe(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
1071
|
-
const input =
|
|
2004
|
+
const input = resolveInput17(value, options.file);
|
|
1072
2005
|
if (input === null) {
|
|
1073
2006
|
io.stderr.push("Missing IE value. Pass an argument or use --file.");
|
|
1074
2007
|
return EXIT.USAGE;
|
|
@@ -1078,7 +2011,7 @@ function runIe(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
|
1078
2011
|
|
|
1079
2012
|
// src/commands/detect.ts
|
|
1080
2013
|
import { detect } from "@br-validators/core";
|
|
1081
|
-
function
|
|
2014
|
+
function resolveInput18(value, fileContent) {
|
|
1082
2015
|
const input = value ?? fileContent?.trim();
|
|
1083
2016
|
if (!input) {
|
|
1084
2017
|
return null;
|
|
@@ -1112,7 +2045,7 @@ function printDetect(result, options, io = { stdout: [], stderr: [] }) {
|
|
|
1112
2045
|
return EXIT.INVALID;
|
|
1113
2046
|
}
|
|
1114
2047
|
function runDetect(value, options, io = { stdout: [], stderr: [] }) {
|
|
1115
|
-
const input =
|
|
2048
|
+
const input = resolveInput18(value, options.file);
|
|
1116
2049
|
if (input === null) {
|
|
1117
2050
|
io.stderr.push("Missing value. Pass an argument or use --file.");
|
|
1118
2051
|
return EXIT.USAGE;
|
|
@@ -1143,7 +2076,7 @@ var SANITIZABLE_TYPES = [
|
|
|
1143
2076
|
function isSanitizableType(type) {
|
|
1144
2077
|
return SANITIZABLE_TYPES.includes(type);
|
|
1145
2078
|
}
|
|
1146
|
-
function
|
|
2079
|
+
function resolveInput19(value, fileContent) {
|
|
1147
2080
|
const input = value ?? fileContent?.trim();
|
|
1148
2081
|
if (!input) {
|
|
1149
2082
|
return null;
|
|
@@ -1174,7 +2107,7 @@ function runSanitize(type, value, options, io = { stdout: [], stderr: [] }) {
|
|
|
1174
2107
|
io.stderr.push(`Unsupported sanitize type: ${type}`);
|
|
1175
2108
|
return EXIT.USAGE;
|
|
1176
2109
|
}
|
|
1177
|
-
const input =
|
|
2110
|
+
const input = resolveInput19(value, options.file);
|
|
1178
2111
|
if (input === null) {
|
|
1179
2112
|
io.stderr.push("Missing value. Pass an argument or use --file.");
|
|
1180
2113
|
return EXIT.USAGE;
|
|
@@ -1544,6 +2477,27 @@ function handleTituloEleitorCli(action, value, opts, io = { stdout: [], stderr:
|
|
|
1544
2477
|
io
|
|
1545
2478
|
);
|
|
1546
2479
|
}
|
|
2480
|
+
function handleProcessoJudicialCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
2481
|
+
let fileContent;
|
|
2482
|
+
if (opts.file) {
|
|
2483
|
+
const content = readInputFile(opts.file, io);
|
|
2484
|
+
if (content === null) {
|
|
2485
|
+
return EXIT.USAGE;
|
|
2486
|
+
}
|
|
2487
|
+
fileContent = content;
|
|
2488
|
+
}
|
|
2489
|
+
return runProcessoJudicial(
|
|
2490
|
+
action,
|
|
2491
|
+
value,
|
|
2492
|
+
{
|
|
2493
|
+
json: Boolean(opts.json),
|
|
2494
|
+
quiet: Boolean(opts.quiet),
|
|
2495
|
+
source: Boolean(opts.source),
|
|
2496
|
+
file: fileContent
|
|
2497
|
+
},
|
|
2498
|
+
io
|
|
2499
|
+
);
|
|
2500
|
+
}
|
|
1547
2501
|
function handleNfeChaveCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1548
2502
|
let fileContent;
|
|
1549
2503
|
if (opts.file) {
|
|
@@ -1608,6 +2562,28 @@ function handleIeCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
|
1608
2562
|
io
|
|
1609
2563
|
);
|
|
1610
2564
|
}
|
|
2565
|
+
function handleRgCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
2566
|
+
let fileContent;
|
|
2567
|
+
if (opts.file) {
|
|
2568
|
+
const content = readInputFile(opts.file, io);
|
|
2569
|
+
if (content === null) {
|
|
2570
|
+
return EXIT.USAGE;
|
|
2571
|
+
}
|
|
2572
|
+
fileContent = content;
|
|
2573
|
+
}
|
|
2574
|
+
return runRg(
|
|
2575
|
+
action,
|
|
2576
|
+
value,
|
|
2577
|
+
{
|
|
2578
|
+
json: Boolean(opts.json),
|
|
2579
|
+
quiet: Boolean(opts.quiet),
|
|
2580
|
+
source: Boolean(opts.source),
|
|
2581
|
+
uf: opts.uf,
|
|
2582
|
+
file: fileContent
|
|
2583
|
+
},
|
|
2584
|
+
io
|
|
2585
|
+
);
|
|
2586
|
+
}
|
|
1611
2587
|
function handleDetectCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
1612
2588
|
let fileContent;
|
|
1613
2589
|
if (opts.file) {
|
|
@@ -1664,10 +2640,81 @@ function handleGenerateCli(type, opts, io = { stdout: [], stderr: [] }) {
|
|
|
1664
2640
|
io
|
|
1665
2641
|
);
|
|
1666
2642
|
}
|
|
2643
|
+
function handleBancosLookupCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
2644
|
+
return runBancosLookup(
|
|
2645
|
+
value,
|
|
2646
|
+
{
|
|
2647
|
+
json: Boolean(opts.json),
|
|
2648
|
+
verbose: Boolean(opts.verbose)
|
|
2649
|
+
},
|
|
2650
|
+
io
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
function handleBancosListCli(opts, io = { stdout: [], stderr: [] }) {
|
|
2654
|
+
return runBancosList(
|
|
2655
|
+
{
|
|
2656
|
+
json: Boolean(opts.json),
|
|
2657
|
+
verbose: Boolean(opts.verbose),
|
|
2658
|
+
limit: opts.limit
|
|
2659
|
+
},
|
|
2660
|
+
io
|
|
2661
|
+
);
|
|
2662
|
+
}
|
|
2663
|
+
function handleReferenceLookupCli(command, value, opts, io = { stdout: [], stderr: [] }) {
|
|
2664
|
+
return runReferenceLookup(
|
|
2665
|
+
command,
|
|
2666
|
+
value,
|
|
2667
|
+
{
|
|
2668
|
+
json: Boolean(opts.json),
|
|
2669
|
+
verbose: Boolean(opts.verbose)
|
|
2670
|
+
},
|
|
2671
|
+
io
|
|
2672
|
+
);
|
|
2673
|
+
}
|
|
2674
|
+
function handleReferenceSearchCli(command, query, opts, io = { stdout: [], stderr: [] }) {
|
|
2675
|
+
return runReferenceSearch(
|
|
2676
|
+
command,
|
|
2677
|
+
query,
|
|
2678
|
+
{
|
|
2679
|
+
json: Boolean(opts.json),
|
|
2680
|
+
verbose: Boolean(opts.verbose),
|
|
2681
|
+
limit: opts.limit
|
|
2682
|
+
},
|
|
2683
|
+
io
|
|
2684
|
+
);
|
|
2685
|
+
}
|
|
2686
|
+
function handleIbgeLookupCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
2687
|
+
return runIbgeLookup(value, { json: Boolean(opts.json), verbose: Boolean(opts.verbose) }, io);
|
|
2688
|
+
}
|
|
2689
|
+
function handleIbgeListCli(target, opts, io = { stdout: [], stderr: [] }) {
|
|
2690
|
+
return runIbgeList(target, {
|
|
2691
|
+
json: Boolean(opts.json),
|
|
2692
|
+
verbose: Boolean(opts.verbose),
|
|
2693
|
+
uf: opts.uf,
|
|
2694
|
+
limit: opts.limit
|
|
2695
|
+
}, io);
|
|
2696
|
+
}
|
|
2697
|
+
function handleFeriadosListCli(opts, io = { stdout: [], stderr: [] }) {
|
|
2698
|
+
return runFeriadosList({
|
|
2699
|
+
json: Boolean(opts.json),
|
|
2700
|
+
verbose: Boolean(opts.verbose),
|
|
2701
|
+
year: opts.year
|
|
2702
|
+
}, io);
|
|
2703
|
+
}
|
|
2704
|
+
function handleTseMunicipiosLookupCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
2705
|
+
return runTseMunicipiosLookup(value, { json: Boolean(opts.json), verbose: Boolean(opts.verbose) }, io);
|
|
2706
|
+
}
|
|
2707
|
+
function handleCepFaixaCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
2708
|
+
return runCepFaixa(value, { json: Boolean(opts.json), verbose: Boolean(opts.verbose) }, io);
|
|
2709
|
+
}
|
|
2710
|
+
function handleDddLookupCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
2711
|
+
return runDddLookup(value, { json: Boolean(opts.json), verbose: Boolean(opts.verbose) }, io);
|
|
2712
|
+
}
|
|
1667
2713
|
|
|
1668
2714
|
// src/argv-dispatch.ts
|
|
1669
2715
|
var STANDARD_ACTIONS = ["validate", "format", "strip"];
|
|
1670
2716
|
var NFE_ACTIONS = ["validate", "parse", "format", "strip"];
|
|
2717
|
+
var PROCESSO_JUDICIAL_ACTIONS = ["validate", "parse", "format", "strip"];
|
|
1671
2718
|
var BRCODE_ACTIONS = ["parse", "validate"];
|
|
1672
2719
|
var PLACA_ACTIONS = ["validate", "format", "strip", "convert"];
|
|
1673
2720
|
var PIX_ACTIONS = ["detect", "validate", "format"];
|
|
@@ -1727,6 +2774,20 @@ function parseArgv(tokens) {
|
|
|
1727
2774
|
index += 1;
|
|
1728
2775
|
continue;
|
|
1729
2776
|
}
|
|
2777
|
+
if (token === "--verbose") {
|
|
2778
|
+
opts.verbose = true;
|
|
2779
|
+
continue;
|
|
2780
|
+
}
|
|
2781
|
+
if (token === "--limit") {
|
|
2782
|
+
opts.limit = Number(tokens[index + 1]);
|
|
2783
|
+
index += 1;
|
|
2784
|
+
continue;
|
|
2785
|
+
}
|
|
2786
|
+
if (token === "--year") {
|
|
2787
|
+
opts.year = Number(tokens[index + 1]);
|
|
2788
|
+
index += 1;
|
|
2789
|
+
continue;
|
|
2790
|
+
}
|
|
1730
2791
|
if (token.startsWith("-")) {
|
|
1731
2792
|
continue;
|
|
1732
2793
|
}
|
|
@@ -1749,7 +2810,7 @@ function dispatchArgv(tokens, io) {
|
|
|
1749
2810
|
if (tokens.length === 0 || tokens.includes("--help") || tokens.includes("-h")) {
|
|
1750
2811
|
io.stdout.push("br-validators \u2014 100% open-source Brazilian document validators");
|
|
1751
2812
|
io.stdout.push("Usage: br-validators <command> ...");
|
|
1752
|
-
io.stdout.push("Commands: list \xB7 cpf \xB7 cnpj \xB7 cep \xB7 telefone \xB7 cnh \xB7 renavam \xB7 titulo-eleitor \xB7 nfe-chave \xB7 brcode \xB7 placa \xB7 pis-pasep \xB7 pix \xB7 boleto \xB7 cartao \xB7 cartao-credito \xB7 ie \xB7 detect \xB7 sanitize \xB7 generate");
|
|
2813
|
+
io.stdout.push("Commands: list \xB7 cpf \xB7 cnpj \xB7 cep \xB7 telefone \xB7 cnh \xB7 renavam \xB7 titulo-eleitor \xB7 processo-judicial \xB7 rg \xB7 nfe-chave \xB7 brcode \xB7 placa \xB7 pis-pasep \xB7 pix \xB7 boleto \xB7 cartao \xB7 cartao-credito \xB7 ie \xB7 bancos \xB7 ibge \xB7 feriados \xB7 tse-municipios \xB7 ddd \xB7 natureza-juridica \xB7 nbs \xB7 cest \xB7 cnae \xB7 cfop \xB7 ncm \xB7 cbo \xB7 moedas \xB7 paises-bacen \xB7 incoterms \xB7 portos \xB7 aeroportos \xB7 detect \xB7 sanitize \xB7 generate");
|
|
1753
2814
|
return EXIT.OK;
|
|
1754
2815
|
}
|
|
1755
2816
|
if (tokens.includes("--version") || tokens.includes("-V")) {
|
|
@@ -1768,8 +2829,18 @@ function dispatchArgv(tokens, io) {
|
|
|
1768
2829
|
return dispatchStandard(rest, opts, io, handleCnpjCli);
|
|
1769
2830
|
case "cpf":
|
|
1770
2831
|
return dispatchStandard(rest, opts, io, handleCpfCli);
|
|
1771
|
-
case "cep":
|
|
1772
|
-
|
|
2832
|
+
case "cep": {
|
|
2833
|
+
const action = rest[0];
|
|
2834
|
+
if (action === "faixa") {
|
|
2835
|
+
const value2 = rest.slice(1).join(" ") || void 0;
|
|
2836
|
+
return handleCepFaixaCli(value2, opts, io);
|
|
2837
|
+
}
|
|
2838
|
+
if (!action || !STANDARD_ACTIONS.includes(action)) {
|
|
2839
|
+
return usage(io, "Expected action: validate | format | strip | faixa <prefix>");
|
|
2840
|
+
}
|
|
2841
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
2842
|
+
return handleCepCli(action, value, opts, io);
|
|
2843
|
+
}
|
|
1773
2844
|
case "telefone":
|
|
1774
2845
|
return dispatchStandard(rest, opts, io, handleTelefoneCli);
|
|
1775
2846
|
case "cnh":
|
|
@@ -1778,6 +2849,19 @@ function dispatchArgv(tokens, io) {
|
|
|
1778
2849
|
return dispatchStandard(rest, opts, io, handleRenavamCli);
|
|
1779
2850
|
case "titulo-eleitor":
|
|
1780
2851
|
return dispatchStandard(rest, opts, io, handleTituloEleitorCli);
|
|
2852
|
+
case "processo-judicial": {
|
|
2853
|
+
const action = rest[0];
|
|
2854
|
+
if (!action || !PROCESSO_JUDICIAL_ACTIONS.includes(action)) {
|
|
2855
|
+
return usage(io, "Expected action: validate | parse | format | strip");
|
|
2856
|
+
}
|
|
2857
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
2858
|
+
return handleProcessoJudicialCli(
|
|
2859
|
+
action,
|
|
2860
|
+
value,
|
|
2861
|
+
opts,
|
|
2862
|
+
io
|
|
2863
|
+
);
|
|
2864
|
+
}
|
|
1781
2865
|
case "nfe-chave": {
|
|
1782
2866
|
const action = rest[0];
|
|
1783
2867
|
if (!action || !NFE_ACTIONS.includes(action)) {
|
|
@@ -1851,14 +2935,87 @@ function dispatchArgv(tokens, io) {
|
|
|
1851
2935
|
io,
|
|
1852
2936
|
(action, value, ieOpts, ioArg) => handleIeCli(action, value, ieOpts, ioArg)
|
|
1853
2937
|
);
|
|
2938
|
+
case "rg":
|
|
2939
|
+
return dispatchStandard(
|
|
2940
|
+
rest,
|
|
2941
|
+
opts,
|
|
2942
|
+
io,
|
|
2943
|
+
(action, value, rgOpts, ioArg) => handleRgCli(action, value, rgOpts, ioArg)
|
|
2944
|
+
);
|
|
2945
|
+
case "bancos": {
|
|
2946
|
+
const action = rest[0];
|
|
2947
|
+
if (action === "lookup") {
|
|
2948
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
2949
|
+
return handleBancosLookupCli(value, opts, io);
|
|
2950
|
+
}
|
|
2951
|
+
if (action === "list") {
|
|
2952
|
+
return handleBancosListCli(opts, io);
|
|
2953
|
+
}
|
|
2954
|
+
return usage(io, "Expected: bancos lookup <codigo|ispb> | bancos list [--limit n]");
|
|
2955
|
+
}
|
|
2956
|
+
case "ibge": {
|
|
2957
|
+
const action = rest[0];
|
|
2958
|
+
if (action === "lookup") {
|
|
2959
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
2960
|
+
return handleIbgeLookupCli(value, opts, io);
|
|
2961
|
+
}
|
|
2962
|
+
if (action === "list") {
|
|
2963
|
+
const target = rest[1];
|
|
2964
|
+
if (target === "estados") {
|
|
2965
|
+
return handleIbgeListCli("estados", opts, io);
|
|
2966
|
+
}
|
|
2967
|
+
if (target === "municipios") {
|
|
2968
|
+
return handleIbgeListCli("municipios", opts, io);
|
|
2969
|
+
}
|
|
2970
|
+
return usage(io, "Expected: ibge list estados | ibge list municipios [--uf UF] [--limit n]");
|
|
2971
|
+
}
|
|
2972
|
+
return usage(io, "Expected: ibge lookup <codigo> | ibge list estados | ibge list municipios");
|
|
2973
|
+
}
|
|
2974
|
+
case "feriados": {
|
|
2975
|
+
const action = rest[0];
|
|
2976
|
+
if (action === "list") {
|
|
2977
|
+
return handleFeriadosListCli(opts, io);
|
|
2978
|
+
}
|
|
2979
|
+
return usage(io, "Expected: feriados list [--year YYYY]");
|
|
2980
|
+
}
|
|
2981
|
+
case "tse-municipios": {
|
|
2982
|
+
const action = rest[0];
|
|
2983
|
+
if (action === "lookup") {
|
|
2984
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
2985
|
+
return handleTseMunicipiosLookupCli(value, opts, io);
|
|
2986
|
+
}
|
|
2987
|
+
return usage(io, "Expected: tse-municipios lookup <codigo-tse|codigo-ibge>");
|
|
2988
|
+
}
|
|
2989
|
+
case "ddd": {
|
|
2990
|
+
const action = rest[0];
|
|
2991
|
+
if (action === "lookup") {
|
|
2992
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
2993
|
+
return handleDddLookupCli(value, opts, io);
|
|
2994
|
+
}
|
|
2995
|
+
return usage(io, "Expected: ddd lookup <code>");
|
|
2996
|
+
}
|
|
1854
2997
|
case "detect":
|
|
1855
2998
|
return handleDetectCli(rest.join(" ") || void 0, opts, io);
|
|
1856
2999
|
case "sanitize":
|
|
1857
3000
|
return handleSanitizeCli(rest[0] ?? "", rest.slice(1).join(" ") || void 0, opts, io);
|
|
1858
3001
|
case "generate":
|
|
1859
3002
|
return handleGenerateCli(rest[0] ?? "", opts, io);
|
|
1860
|
-
default:
|
|
3003
|
+
default: {
|
|
3004
|
+
if (isReferenceLookupCommand(root)) {
|
|
3005
|
+
const action = rest[0];
|
|
3006
|
+
if (action === "lookup") {
|
|
3007
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
3008
|
+
return handleReferenceLookupCli(root, value, opts, io);
|
|
3009
|
+
}
|
|
3010
|
+
if (action === "search" && isReferenceSearchCommand(root)) {
|
|
3011
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
3012
|
+
return handleReferenceSearchCli(root, value, opts, io);
|
|
3013
|
+
}
|
|
3014
|
+
const searchHint = isReferenceSearchCommand(root) ? " | search <query>" : "";
|
|
3015
|
+
return usage(io, `Expected: ${root} lookup <codigo>${searchHint}`);
|
|
3016
|
+
}
|
|
1861
3017
|
return usage(io, `Unknown command: ${root}`);
|
|
3018
|
+
}
|
|
1862
3019
|
}
|
|
1863
3020
|
}
|
|
1864
3021
|
|