@br-validators/cli 1.5.0 → 1.6.1
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 +21 -3
- package/dist/index.js +825 -27
- package/dist/run-captured.js +848 -31
- package/package.json +2 -2
package/dist/run-captured.js
CHANGED
|
@@ -6,7 +6,7 @@ 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,
|
|
@@ -41,16 +41,31 @@ import {
|
|
|
41
41
|
getAeroportoPorIcao
|
|
42
42
|
} from "@br-validators/core/aeroportos";
|
|
43
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";
|
|
44
54
|
var REFERENCE_LOOKUP_COMMANDS = [
|
|
45
55
|
"natureza-juridica",
|
|
46
56
|
"nbs",
|
|
47
57
|
"cest",
|
|
58
|
+
"cnae",
|
|
59
|
+
"cfop",
|
|
60
|
+
"ncm",
|
|
61
|
+
"cbo",
|
|
48
62
|
"moedas",
|
|
49
63
|
"paises-bacen",
|
|
50
64
|
"incoterms",
|
|
51
65
|
"portos",
|
|
52
66
|
"aeroportos"
|
|
53
67
|
];
|
|
68
|
+
var REFERENCE_SEARCH_COMMANDS = ["cnae", "cfop", "ncm", "cbo"];
|
|
54
69
|
function lookupAeroporto(input) {
|
|
55
70
|
const normalized = input.trim().toUpperCase();
|
|
56
71
|
if (/^[A-Z0-9]{3}$/.test(normalized)) {
|
|
@@ -95,6 +110,50 @@ var REFERENCE_LOOKUP_MODULES = {
|
|
|
95
110
|
return `${row.codigo} \u2014 ${row.descricao}`;
|
|
96
111
|
}
|
|
97
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
|
+
},
|
|
98
157
|
moedas: {
|
|
99
158
|
command: "moedas",
|
|
100
159
|
description: "ISO 4217 + Bacen PTAX currencies \u2014 offline lookup",
|
|
@@ -156,6 +215,9 @@ var REFERENCE_LOOKUP_MODULES = {
|
|
|
156
215
|
function isReferenceLookupCommand(value) {
|
|
157
216
|
return REFERENCE_LOOKUP_COMMANDS.includes(value);
|
|
158
217
|
}
|
|
218
|
+
function isReferenceSearchCommand(value) {
|
|
219
|
+
return REFERENCE_SEARCH_COMMANDS.includes(value);
|
|
220
|
+
}
|
|
159
221
|
|
|
160
222
|
// src/commands/bancos/list.ts
|
|
161
223
|
import { BANCOS_DATA_VERSION as BANCOS_DATA_VERSION2, getBancos } from "@br-validators/core/bancos";
|
|
@@ -293,6 +355,418 @@ function runReferenceLookup(command, value, options, io = { stdout: [], stderr:
|
|
|
293
355
|
return runReferenceLookupCommand(command, value.trim(), options, io);
|
|
294
356
|
}
|
|
295
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
|
+
|
|
296
770
|
// src/commands/brcode.ts
|
|
297
771
|
import {
|
|
298
772
|
BRCODE_OFFICIAL_SOURCE_URL,
|
|
@@ -453,6 +927,45 @@ function printNfeChaveValidation(result, options, io = { stdout: [], stderr: []
|
|
|
453
927
|
io.stderr.push(`message: ${result.message}`);
|
|
454
928
|
return EXIT.INVALID;
|
|
455
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
|
+
}
|
|
456
969
|
function printFormat(result, options, io = { stdout: [], stderr: [] }) {
|
|
457
970
|
if (options.json) {
|
|
458
971
|
io.stdout.push(JSON.stringify(result, null, 2));
|
|
@@ -623,6 +1136,146 @@ function runCnh(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
|
623
1136
|
return runCnhCommand(action, input, options, io);
|
|
624
1137
|
}
|
|
625
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
|
+
|
|
626
1279
|
// src/commands/renavam.ts
|
|
627
1280
|
import {
|
|
628
1281
|
RENAVAM_OFFICIAL_SOURCE_URL,
|
|
@@ -630,7 +1283,7 @@ import {
|
|
|
630
1283
|
stripRenavam,
|
|
631
1284
|
validateRenavam
|
|
632
1285
|
} from "@br-validators/core";
|
|
633
|
-
function
|
|
1286
|
+
function resolveInput7(value, fileContent) {
|
|
634
1287
|
const input = value ?? fileContent?.trim();
|
|
635
1288
|
if (!input) {
|
|
636
1289
|
return null;
|
|
@@ -654,7 +1307,7 @@ function runRenavamCommand(action, input, options, io = { stdout: [], stderr: []
|
|
|
654
1307
|
}
|
|
655
1308
|
}
|
|
656
1309
|
function runRenavam(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
657
|
-
const input =
|
|
1310
|
+
const input = resolveInput7(value, options.file);
|
|
658
1311
|
if (input === null) {
|
|
659
1312
|
io.stderr.push("Missing RENAVAM value. Pass an argument or use --file.");
|
|
660
1313
|
return EXIT.USAGE;
|
|
@@ -669,7 +1322,7 @@ import {
|
|
|
669
1322
|
stripTituloEleitor,
|
|
670
1323
|
validateTituloEleitor
|
|
671
1324
|
} from "@br-validators/core";
|
|
672
|
-
function
|
|
1325
|
+
function resolveInput8(value, fileContent) {
|
|
673
1326
|
const input = value ?? fileContent?.trim();
|
|
674
1327
|
if (!input) {
|
|
675
1328
|
return null;
|
|
@@ -693,7 +1346,7 @@ function runTituloEleitorCommand(action, input, options, io = { stdout: [], stde
|
|
|
693
1346
|
}
|
|
694
1347
|
}
|
|
695
1348
|
function runTituloEleitor(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
696
|
-
const input =
|
|
1349
|
+
const input = resolveInput8(value, options.file);
|
|
697
1350
|
if (input === null) {
|
|
698
1351
|
io.stderr.push("Missing T\xEDtulo de Eleitor value. Pass an argument or use --file.");
|
|
699
1352
|
return EXIT.USAGE;
|
|
@@ -709,7 +1362,7 @@ import {
|
|
|
709
1362
|
stripNfeChave,
|
|
710
1363
|
validateNfeChave
|
|
711
1364
|
} from "@br-validators/core";
|
|
712
|
-
function
|
|
1365
|
+
function resolveInput9(value, fileContent) {
|
|
713
1366
|
const input = value ?? fileContent?.trim();
|
|
714
1367
|
if (!input) {
|
|
715
1368
|
return null;
|
|
@@ -735,7 +1388,7 @@ function runNfeChaveCommand(action, input, options, io = { stdout: [], stderr: [
|
|
|
735
1388
|
}
|
|
736
1389
|
}
|
|
737
1390
|
function runNfeChave(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
738
|
-
const input =
|
|
1391
|
+
const input = resolveInput9(value, options.file);
|
|
739
1392
|
if (input === null) {
|
|
740
1393
|
io.stderr.push("Missing NF-e chave de acesso value. Pass an argument or use --file.");
|
|
741
1394
|
return EXIT.USAGE;
|
|
@@ -750,7 +1403,7 @@ import {
|
|
|
750
1403
|
stripCnpj,
|
|
751
1404
|
validateCnpj
|
|
752
1405
|
} from "@br-validators/core";
|
|
753
|
-
function
|
|
1406
|
+
function resolveInput10(value, fileContent) {
|
|
754
1407
|
const input = value ?? fileContent?.trim();
|
|
755
1408
|
if (!input) {
|
|
756
1409
|
return null;
|
|
@@ -774,7 +1427,7 @@ function runCnpjCommand(action, input, options, io = { stdout: [], stderr: [] })
|
|
|
774
1427
|
}
|
|
775
1428
|
}
|
|
776
1429
|
function runCnpj(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
777
|
-
const input =
|
|
1430
|
+
const input = resolveInput10(value, options.file);
|
|
778
1431
|
if (input === null) {
|
|
779
1432
|
io.stderr.push("Missing CNPJ value. Pass an argument or use --file.");
|
|
780
1433
|
return EXIT.USAGE;
|
|
@@ -789,7 +1442,7 @@ import {
|
|
|
789
1442
|
stripCpf,
|
|
790
1443
|
validateCpf
|
|
791
1444
|
} from "@br-validators/core";
|
|
792
|
-
function
|
|
1445
|
+
function resolveInput11(value, fileContent) {
|
|
793
1446
|
const input = value ?? fileContent?.trim();
|
|
794
1447
|
if (!input) {
|
|
795
1448
|
return null;
|
|
@@ -813,7 +1466,7 @@ function runCpfCommand(action, input, options, io = { stdout: [], stderr: [] })
|
|
|
813
1466
|
}
|
|
814
1467
|
}
|
|
815
1468
|
function runCpf(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
816
|
-
const input =
|
|
1469
|
+
const input = resolveInput11(value, options.file);
|
|
817
1470
|
if (input === null) {
|
|
818
1471
|
io.stderr.push("Missing CPF value. Pass an argument or use --file.");
|
|
819
1472
|
return EXIT.USAGE;
|
|
@@ -829,7 +1482,7 @@ import {
|
|
|
829
1482
|
stripPlaca,
|
|
830
1483
|
validatePlaca
|
|
831
1484
|
} from "@br-validators/core";
|
|
832
|
-
function
|
|
1485
|
+
function resolveInput12(value, fileContent) {
|
|
833
1486
|
const input = value ?? fileContent?.trim();
|
|
834
1487
|
if (!input) {
|
|
835
1488
|
return null;
|
|
@@ -855,7 +1508,7 @@ function runPlacaCommand(action, input, options, io = { stdout: [], stderr: [] }
|
|
|
855
1508
|
}
|
|
856
1509
|
}
|
|
857
1510
|
function runPlaca(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
858
|
-
const input =
|
|
1511
|
+
const input = resolveInput12(value, options.file);
|
|
859
1512
|
if (input === null) {
|
|
860
1513
|
io.stderr.push("Missing placa value. Pass an argument or use --file.");
|
|
861
1514
|
return EXIT.USAGE;
|
|
@@ -870,7 +1523,7 @@ import {
|
|
|
870
1523
|
stripPisPasep,
|
|
871
1524
|
validatePisPasep
|
|
872
1525
|
} from "@br-validators/core";
|
|
873
|
-
function
|
|
1526
|
+
function resolveInput13(value, fileContent) {
|
|
874
1527
|
const input = value ?? fileContent?.trim();
|
|
875
1528
|
if (!input) {
|
|
876
1529
|
return null;
|
|
@@ -894,7 +1547,7 @@ function runPisPasepCommand(action, input, options, io = { stdout: [], stderr: [
|
|
|
894
1547
|
}
|
|
895
1548
|
}
|
|
896
1549
|
function runPisPasep(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
897
|
-
const input =
|
|
1550
|
+
const input = resolveInput13(value, options.file);
|
|
898
1551
|
if (input === null) {
|
|
899
1552
|
io.stderr.push("Missing PIS/PASEP value. Pass an argument or use --file.");
|
|
900
1553
|
return EXIT.USAGE;
|
|
@@ -909,7 +1562,7 @@ import {
|
|
|
909
1562
|
formatPixKey,
|
|
910
1563
|
validatePixKey
|
|
911
1564
|
} from "@br-validators/core";
|
|
912
|
-
function
|
|
1565
|
+
function resolveInput14(value, fileContent) {
|
|
913
1566
|
const input = value ?? fileContent?.trim();
|
|
914
1567
|
if (!input) {
|
|
915
1568
|
return null;
|
|
@@ -984,7 +1637,7 @@ function runPixCommand(action, input, options, io = { stdout: [], stderr: [] })
|
|
|
984
1637
|
}
|
|
985
1638
|
}
|
|
986
1639
|
function runPix(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
987
|
-
const input =
|
|
1640
|
+
const input = resolveInput14(value, options.file);
|
|
988
1641
|
if (input === null) {
|
|
989
1642
|
io.stderr.push("Missing PIX key value. Pass an argument or use --file.");
|
|
990
1643
|
return EXIT.USAGE;
|
|
@@ -1003,7 +1656,7 @@ import {
|
|
|
1003
1656
|
stripLinhaDigitavel,
|
|
1004
1657
|
validateBoleto
|
|
1005
1658
|
} from "@br-validators/core";
|
|
1006
|
-
function
|
|
1659
|
+
function resolveInput15(value, fileContent) {
|
|
1007
1660
|
const input = value ?? fileContent?.trim();
|
|
1008
1661
|
if (!input) {
|
|
1009
1662
|
return null;
|
|
@@ -1138,7 +1791,7 @@ function runBoletoCommand(action, input, options, direction, io = { stdout: [],
|
|
|
1138
1791
|
}
|
|
1139
1792
|
}
|
|
1140
1793
|
function runBoleto(action, value, options, direction, io = { stdout: [], stderr: [] }) {
|
|
1141
|
-
const input =
|
|
1794
|
+
const input = resolveInput15(value, options.file);
|
|
1142
1795
|
if (input === null) {
|
|
1143
1796
|
io.stderr.push("Missing boleto value. Pass an argument or use --file.");
|
|
1144
1797
|
return EXIT.USAGE;
|
|
@@ -1154,7 +1807,7 @@ import {
|
|
|
1154
1807
|
stripCartaoCredito,
|
|
1155
1808
|
validateCartaoCredito
|
|
1156
1809
|
} from "@br-validators/core";
|
|
1157
|
-
function
|
|
1810
|
+
function resolveInput16(value, fileContent) {
|
|
1158
1811
|
const input = value ?? fileContent?.trim();
|
|
1159
1812
|
if (!input) {
|
|
1160
1813
|
return null;
|
|
@@ -1230,7 +1883,7 @@ function runCartaoCommand(action, input, options, io = { stdout: [], stderr: []
|
|
|
1230
1883
|
}
|
|
1231
1884
|
}
|
|
1232
1885
|
function runCartao(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
1233
|
-
const input =
|
|
1886
|
+
const input = resolveInput16(value, options.file);
|
|
1234
1887
|
if (input === null) {
|
|
1235
1888
|
io.stderr.push("Missing credit card PAN value. Pass an argument or use --file.");
|
|
1236
1889
|
return EXIT.USAGE;
|
|
@@ -1251,7 +1904,7 @@ import {
|
|
|
1251
1904
|
validateIeProdutorRural,
|
|
1252
1905
|
validateInscricaoEstadual
|
|
1253
1906
|
} from "@br-validators/core";
|
|
1254
|
-
function
|
|
1907
|
+
function resolveInput17(value, fileContent) {
|
|
1255
1908
|
const input = value ?? fileContent?.trim();
|
|
1256
1909
|
if (!input) {
|
|
1257
1910
|
return null;
|
|
@@ -1348,7 +2001,7 @@ function runIeCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
|
1348
2001
|
}
|
|
1349
2002
|
}
|
|
1350
2003
|
function runIe(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
1351
|
-
const input =
|
|
2004
|
+
const input = resolveInput17(value, options.file);
|
|
1352
2005
|
if (input === null) {
|
|
1353
2006
|
io.stderr.push("Missing IE value. Pass an argument or use --file.");
|
|
1354
2007
|
return EXIT.USAGE;
|
|
@@ -1358,7 +2011,7 @@ function runIe(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
|
1358
2011
|
|
|
1359
2012
|
// src/commands/detect.ts
|
|
1360
2013
|
import { detect } from "@br-validators/core";
|
|
1361
|
-
function
|
|
2014
|
+
function resolveInput18(value, fileContent) {
|
|
1362
2015
|
const input = value ?? fileContent?.trim();
|
|
1363
2016
|
if (!input) {
|
|
1364
2017
|
return null;
|
|
@@ -1392,7 +2045,7 @@ function printDetect(result, options, io = { stdout: [], stderr: [] }) {
|
|
|
1392
2045
|
return EXIT.INVALID;
|
|
1393
2046
|
}
|
|
1394
2047
|
function runDetect(value, options, io = { stdout: [], stderr: [] }) {
|
|
1395
|
-
const input =
|
|
2048
|
+
const input = resolveInput18(value, options.file);
|
|
1396
2049
|
if (input === null) {
|
|
1397
2050
|
io.stderr.push("Missing value. Pass an argument or use --file.");
|
|
1398
2051
|
return EXIT.USAGE;
|
|
@@ -1423,7 +2076,7 @@ var SANITIZABLE_TYPES = [
|
|
|
1423
2076
|
function isSanitizableType(type) {
|
|
1424
2077
|
return SANITIZABLE_TYPES.includes(type);
|
|
1425
2078
|
}
|
|
1426
|
-
function
|
|
2079
|
+
function resolveInput19(value, fileContent) {
|
|
1427
2080
|
const input = value ?? fileContent?.trim();
|
|
1428
2081
|
if (!input) {
|
|
1429
2082
|
return null;
|
|
@@ -1454,7 +2107,7 @@ function runSanitize(type, value, options, io = { stdout: [], stderr: [] }) {
|
|
|
1454
2107
|
io.stderr.push(`Unsupported sanitize type: ${type}`);
|
|
1455
2108
|
return EXIT.USAGE;
|
|
1456
2109
|
}
|
|
1457
|
-
const input =
|
|
2110
|
+
const input = resolveInput19(value, options.file);
|
|
1458
2111
|
if (input === null) {
|
|
1459
2112
|
io.stderr.push("Missing value. Pass an argument or use --file.");
|
|
1460
2113
|
return EXIT.USAGE;
|
|
@@ -1824,6 +2477,27 @@ function handleTituloEleitorCli(action, value, opts, io = { stdout: [], stderr:
|
|
|
1824
2477
|
io
|
|
1825
2478
|
);
|
|
1826
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
|
+
}
|
|
1827
2501
|
function handleNfeChaveCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1828
2502
|
let fileContent;
|
|
1829
2503
|
if (opts.file) {
|
|
@@ -1888,6 +2562,28 @@ function handleIeCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
|
1888
2562
|
io
|
|
1889
2563
|
);
|
|
1890
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
|
+
}
|
|
1891
2587
|
function handleDetectCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
1892
2588
|
let fileContent;
|
|
1893
2589
|
if (opts.file) {
|
|
@@ -1975,10 +2671,50 @@ function handleReferenceLookupCli(command, value, opts, io = { stdout: [], stder
|
|
|
1975
2671
|
io
|
|
1976
2672
|
);
|
|
1977
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
|
+
}
|
|
1978
2713
|
|
|
1979
2714
|
// src/argv-dispatch.ts
|
|
1980
2715
|
var STANDARD_ACTIONS = ["validate", "format", "strip"];
|
|
1981
2716
|
var NFE_ACTIONS = ["validate", "parse", "format", "strip"];
|
|
2717
|
+
var PROCESSO_JUDICIAL_ACTIONS = ["validate", "parse", "format", "strip"];
|
|
1982
2718
|
var BRCODE_ACTIONS = ["parse", "validate"];
|
|
1983
2719
|
var PLACA_ACTIONS = ["validate", "format", "strip", "convert"];
|
|
1984
2720
|
var PIX_ACTIONS = ["detect", "validate", "format"];
|
|
@@ -2047,6 +2783,11 @@ function parseArgv(tokens) {
|
|
|
2047
2783
|
index += 1;
|
|
2048
2784
|
continue;
|
|
2049
2785
|
}
|
|
2786
|
+
if (token === "--year") {
|
|
2787
|
+
opts.year = Number(tokens[index + 1]);
|
|
2788
|
+
index += 1;
|
|
2789
|
+
continue;
|
|
2790
|
+
}
|
|
2050
2791
|
if (token.startsWith("-")) {
|
|
2051
2792
|
continue;
|
|
2052
2793
|
}
|
|
@@ -2069,7 +2810,7 @@ function dispatchArgv(tokens, io) {
|
|
|
2069
2810
|
if (tokens.length === 0 || tokens.includes("--help") || tokens.includes("-h")) {
|
|
2070
2811
|
io.stdout.push("br-validators \u2014 100% open-source Brazilian document validators");
|
|
2071
2812
|
io.stdout.push("Usage: br-validators <command> ...");
|
|
2072
|
-
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 bancos \xB7 natureza-juridica \xB7 nbs \xB7 cest \xB7 moedas \xB7 paises-bacen \xB7 incoterms \xB7 portos \xB7 aeroportos \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");
|
|
2073
2814
|
return EXIT.OK;
|
|
2074
2815
|
}
|
|
2075
2816
|
if (tokens.includes("--version") || tokens.includes("-V")) {
|
|
@@ -2088,8 +2829,18 @@ function dispatchArgv(tokens, io) {
|
|
|
2088
2829
|
return dispatchStandard(rest, opts, io, handleCnpjCli);
|
|
2089
2830
|
case "cpf":
|
|
2090
2831
|
return dispatchStandard(rest, opts, io, handleCpfCli);
|
|
2091
|
-
case "cep":
|
|
2092
|
-
|
|
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
|
+
}
|
|
2093
2844
|
case "telefone":
|
|
2094
2845
|
return dispatchStandard(rest, opts, io, handleTelefoneCli);
|
|
2095
2846
|
case "cnh":
|
|
@@ -2098,6 +2849,19 @@ function dispatchArgv(tokens, io) {
|
|
|
2098
2849
|
return dispatchStandard(rest, opts, io, handleRenavamCli);
|
|
2099
2850
|
case "titulo-eleitor":
|
|
2100
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
|
+
}
|
|
2101
2865
|
case "nfe-chave": {
|
|
2102
2866
|
const action = rest[0];
|
|
2103
2867
|
if (!action || !NFE_ACTIONS.includes(action)) {
|
|
@@ -2171,6 +2935,13 @@ function dispatchArgv(tokens, io) {
|
|
|
2171
2935
|
io,
|
|
2172
2936
|
(action, value, ieOpts, ioArg) => handleIeCli(action, value, ieOpts, ioArg)
|
|
2173
2937
|
);
|
|
2938
|
+
case "rg":
|
|
2939
|
+
return dispatchStandard(
|
|
2940
|
+
rest,
|
|
2941
|
+
opts,
|
|
2942
|
+
io,
|
|
2943
|
+
(action, value, rgOpts, ioArg) => handleRgCli(action, value, rgOpts, ioArg)
|
|
2944
|
+
);
|
|
2174
2945
|
case "bancos": {
|
|
2175
2946
|
const action = rest[0];
|
|
2176
2947
|
if (action === "lookup") {
|
|
@@ -2182,6 +2953,47 @@ function dispatchArgv(tokens, io) {
|
|
|
2182
2953
|
}
|
|
2183
2954
|
return usage(io, "Expected: bancos lookup <codigo|ispb> | bancos list [--limit n]");
|
|
2184
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
|
+
}
|
|
2185
2997
|
case "detect":
|
|
2186
2998
|
return handleDetectCli(rest.join(" ") || void 0, opts, io);
|
|
2187
2999
|
case "sanitize":
|
|
@@ -2195,7 +3007,12 @@ function dispatchArgv(tokens, io) {
|
|
|
2195
3007
|
const value = rest.slice(1).join(" ") || void 0;
|
|
2196
3008
|
return handleReferenceLookupCli(root, value, opts, io);
|
|
2197
3009
|
}
|
|
2198
|
-
|
|
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}`);
|
|
2199
3016
|
}
|
|
2200
3017
|
return usage(io, `Unknown command: ${root}`);
|
|
2201
3018
|
}
|