@br-validators/cli 0.12.0-alpha.0 → 0.12.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,45 +20,87 @@ npx @br-validators/cli --help
20
20
 
21
21
  ---
22
22
 
23
- ## Commands
23
+ ## Global commands
24
24
 
25
25
  ```bash
26
26
  br-validators list
27
27
  br-validators --version
28
+ br-validators --help
29
+ ```
30
+
31
+ ---
32
+
33
+ ## Per-type commands
28
34
 
35
+ ```bash
29
36
  br-validators cnpj validate 12ABC34501DE35 --json --source
30
37
  br-validators cpf validate 12345678909
31
38
  br-validators cep format 01310100
39
+ br-validators telefone validate 11999999999
40
+ br-validators cnh validate 62472927637
41
+ br-validators renavam validate 63977791104
42
+ br-validators titulo-eleitor validate 004356870906
43
+ br-validators nfe-chave validate 52060433009911002506550120000007800267301615 --json
44
+ br-validators nfe-chave parse 52060433009911002506550120000007800267301615 --json
45
+ br-validators brcode validate '<emv-payload>' --json
32
46
  br-validators placa validate ABC1D23
33
47
  br-validators pis-pasep validate 10027230888
34
48
  br-validators pix validate pix@bcb.gov.br
35
- br-validators boleto validate <linha-ou-barcode>
49
+ br-validators boleto validate '03399.02579 08991.834006 71742.301014 6 14500000099668'
36
50
  br-validators cartao validate 4111111111111111
51
+ br-validators cartao-credito validate 4111111111111111
37
52
  br-validators ie validate 110042490114 --uf SP --json
53
+ br-validators ie validate P-01100424.3/002 --uf SP # SP produtor rural (auto-detect)
38
54
  ```
39
55
 
40
- ### Actions (all types)
56
+ ### Actions (per-type)
41
57
 
42
58
  | Action | Description |
43
59
  |--------|-------------|
44
60
  | `validate` | Check format + check digits |
45
61
  | `format` | Apply official mask |
46
62
  | `strip` | Normalize to canonical digits/chars |
63
+ | `parse` | NF-e chave, BR Code |
64
+ | `convert` | Boleto linha ↔ barcode; placa legacy → Mercosul |
65
+ | `detect` | PIX key type; boleto input kind; cartão brand |
66
+
67
+ ---
68
+
69
+ ## Platform commands
70
+
71
+ | Command | Description |
72
+ |---------|-------------|
73
+ | `detect [value]` | Classify raw input; `--uf` for IE |
74
+ | `sanitize <type> [value]` | ETL fixes + validate; `--uf` for `inscricao-estadual` |
75
+ | `generate <type>` | Synthetic test document; `--seed`, `--masked`, `--format` |
76
+
77
+ ```bash
78
+ br-validators detect '123.456.789-09' --json
79
+ br-validators detect '110042490114' --uf SP --json
80
+ br-validators sanitize cpf ' 123.456.789-09 ' --json
81
+ br-validators sanitize inscricao-estadual '110.042.490.114' --uf SP --json
82
+ br-validators generate cpf --seed 42 --masked --json
83
+ br-validators generate cnpj --format alphanumeric --seed 7 --json
84
+ br-validators generate placa --format mercosul --seed 3
85
+ ```
86
+
87
+ ---
47
88
 
48
- ### Flags
89
+ ## Flags
49
90
 
50
91
  | Flag | Description |
51
92
  |------|-------------|
52
- | `--json` | JSON output (`ValidationResult`) |
93
+ | `--json` | JSON output |
53
94
  | `--quiet` / `-q` | Exit code only (CI) |
54
95
  | `--file` / `-f` | Read value from file |
55
- | `--source` | Print official source URL |
56
- | `--uf` | Required for IE (27 UFs) |
96
+ | `--source` | Print official source URL (per-type) |
97
+ | `--uf` | Required for IE / detect / sanitize IE |
57
98
 
58
99
  ### CI
59
100
 
60
101
  ```bash
61
102
  br-validators cnpj validate "$CNPJ" --quiet || exit 1
103
+ br-validators detect "$RAW_INPUT" --json --quiet || exit 1
62
104
  ```
63
105
 
64
106
  ---
package/dist/index.js CHANGED
@@ -1,11 +1,14 @@
1
1
  #!/usr/bin/env node
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
2
8
 
3
9
  // src/program.ts
4
10
  import { Command } from "commander";
5
11
 
6
- // src/handlers.ts
7
- import { readFileSync } from "fs";
8
-
9
12
  // src/commands/brcode.ts
10
13
  import {
11
14
  BRCODE_OFFICIAL_SOURCE_URL,
@@ -1177,7 +1180,7 @@ function runSanitize(type, value, options, io = { stdout: [], stderr: [] }) {
1177
1180
  }
1178
1181
 
1179
1182
  // src/commands/generate.ts
1180
- import { generate } from "@br-validators/core";
1183
+ import { generate, isGeneratableCardBrand } from "@br-validators/core";
1181
1184
  var GENERATABLE_TYPES = [
1182
1185
  "cpf",
1183
1186
  "cnpj",
@@ -1187,7 +1190,9 @@ var GENERATABLE_TYPES = [
1187
1190
  "renavam",
1188
1191
  "cnh",
1189
1192
  "telefone",
1190
- "cartao-credito"
1193
+ "cartao-credito",
1194
+ "inscricao-estadual",
1195
+ "titulo-eleitor"
1191
1196
  ];
1192
1197
  function isGeneratableType(type) {
1193
1198
  return GENERATABLE_TYPES.includes(type);
@@ -1203,6 +1208,12 @@ function buildGenerateOptions(options) {
1203
1208
  if (options.format) {
1204
1209
  core.format = options.format;
1205
1210
  }
1211
+ if (options.uf) {
1212
+ core.uf = options.uf.toUpperCase();
1213
+ }
1214
+ if (options.brand && isGeneratableCardBrand(options.brand)) {
1215
+ core.brand = options.brand;
1216
+ }
1206
1217
  return core;
1207
1218
  }
1208
1219
  function printGenerate(value, options, io = { stdout: [], stderr: [] }) {
@@ -1236,7 +1247,8 @@ function listSupportedTypes(io = { stdout: [] }) {
1236
1247
  // src/handlers.ts
1237
1248
  function readInputFile(path, io) {
1238
1249
  try {
1239
- return readFileSync(path, "utf8");
1250
+ const fsModule = __require("fs");
1251
+ return fsModule.readFileSync(path, "utf8");
1240
1252
  } catch {
1241
1253
  io.stderr.push(`Cannot read file: ${path}`);
1242
1254
  return null;
@@ -1634,7 +1646,9 @@ function handleGenerateCli(type, opts, io = { stdout: [], stderr: [] }) {
1634
1646
  quiet: Boolean(opts.quiet),
1635
1647
  masked: Boolean(opts.masked),
1636
1648
  format: opts.format,
1637
- seed: opts.seed
1649
+ seed: opts.seed,
1650
+ uf: opts.uf,
1651
+ brand: opts.brand
1638
1652
  },
1639
1653
  io
1640
1654
  );
@@ -1822,7 +1836,7 @@ function createProgram() {
1822
1836
  process.exitCode = handleSanitizeCli(type, value, opts, io);
1823
1837
  writeCliIo(io);
1824
1838
  });
1825
- program.command("generate <type>").description("Generate synthetic valid test document").option("--json", "JSON output").option("-q, --quiet", "Exit code only").option("--masked", "Return masked/formatted output").option("--format <format>", "Format variant (numeric, alphanumeric, legacy, mercosul, celular, fixo)").option("--seed <number>", "Deterministic PRNG seed", (v) => Number(v)).action((type, opts) => {
1839
+ program.command("generate <type>").description("Generate synthetic valid test document").option("--json", "JSON output").option("-q, --quiet", "Exit code only").option("--masked", "Return masked/formatted output").option("--format <format>", "Format variant (numeric, alphanumeric, legacy, mercosul, celular, fixo)").option("--seed <number>", "Deterministic PRNG seed", (v) => Number(v)).option("--uf <uf>", "State code (required for inscricao-estadual and titulo-eleitor)").option("--brand <brand>", "Card brand (visa, mastercard, amex, elo, hipercard)").action((type, opts) => {
1826
1840
  const io = { stdout: [], stderr: [] };
1827
1841
  process.exitCode = handleGenerateCli(type, opts, io);
1828
1842
  writeCliIo(io);
@@ -0,0 +1,9 @@
1
+ type CliRunResult = {
2
+ exitCode: number;
3
+ stdout: string;
4
+ stderr: string;
5
+ };
6
+ /** Run CLI with argv; capture stdout/stderr and exit code (browser-safe — no commander/process.exit). */
7
+ declare function runCaptured(argv: string[]): CliRunResult;
8
+
9
+ export { type CliRunResult, runCaptured };