@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 +49 -7
- package/dist/index.js +22 -8
- package/dist/run-captured.d.ts +9 -0
- package/dist/run-captured.js +1861 -0
- package/package.json +20 -4
|
@@ -0,0 +1,1861 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
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"];
|
|
10
|
+
var EXIT = {
|
|
11
|
+
OK: 0,
|
|
12
|
+
INVALID: 1,
|
|
13
|
+
USAGE: 2
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/commands/brcode.ts
|
|
17
|
+
import {
|
|
18
|
+
BRCODE_OFFICIAL_SOURCE_URL,
|
|
19
|
+
parseBrCode,
|
|
20
|
+
validateBrCode
|
|
21
|
+
} from "@br-validators/core";
|
|
22
|
+
function resolveInput(value, fileContent) {
|
|
23
|
+
const input = value ?? fileContent?.trim();
|
|
24
|
+
if (!input) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return input;
|
|
28
|
+
}
|
|
29
|
+
function printBrCodeResult(result, options, io = { stdout: [], stderr: [] }) {
|
|
30
|
+
if (options.json) {
|
|
31
|
+
io.stdout.push(
|
|
32
|
+
JSON.stringify(
|
|
33
|
+
result.ok ? {
|
|
34
|
+
ok: true,
|
|
35
|
+
value: result.value,
|
|
36
|
+
format: result.format,
|
|
37
|
+
merchantName: result.merchantName,
|
|
38
|
+
merchantCity: result.merchantCity,
|
|
39
|
+
...result.amount ? { amount: result.amount } : {},
|
|
40
|
+
...result.txid ? { txid: result.txid } : {},
|
|
41
|
+
...result.pixKey ? { pixKey: result.pixKey, pixKeyType: result.pixKeyType } : {},
|
|
42
|
+
...result.pixInitiationUrl ? { pixInitiationUrl: result.pixInitiationUrl } : {},
|
|
43
|
+
...options.source ? { source: options.source } : {}
|
|
44
|
+
} : { ok: false, code: result.code, message: result.message },
|
|
45
|
+
null,
|
|
46
|
+
2
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
50
|
+
}
|
|
51
|
+
if (options.quiet) {
|
|
52
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
53
|
+
}
|
|
54
|
+
if (result.ok) {
|
|
55
|
+
io.stdout.push("valid: yes");
|
|
56
|
+
io.stdout.push(`merchantName: ${result.merchantName}`);
|
|
57
|
+
io.stdout.push(`merchantCity: ${result.merchantCity}`);
|
|
58
|
+
if (result.amount) {
|
|
59
|
+
io.stdout.push(`amount: ${result.amount}`);
|
|
60
|
+
}
|
|
61
|
+
if (result.txid) {
|
|
62
|
+
io.stdout.push(`txid: ${result.txid}`);
|
|
63
|
+
}
|
|
64
|
+
if (result.pixKey) {
|
|
65
|
+
io.stdout.push(`pixKey: ${result.pixKey}`);
|
|
66
|
+
io.stdout.push(`pixKeyType: ${result.pixKeyType}`);
|
|
67
|
+
}
|
|
68
|
+
if (result.pixInitiationUrl) {
|
|
69
|
+
io.stdout.push(`pixInitiationUrl: ${result.pixInitiationUrl}`);
|
|
70
|
+
}
|
|
71
|
+
if (options.source) {
|
|
72
|
+
io.stdout.push(`source: ${options.source}`);
|
|
73
|
+
}
|
|
74
|
+
return EXIT.OK;
|
|
75
|
+
}
|
|
76
|
+
io.stderr.push("valid: no");
|
|
77
|
+
io.stderr.push(`code: ${result.code}`);
|
|
78
|
+
io.stderr.push(`message: ${result.message}`);
|
|
79
|
+
return EXIT.INVALID;
|
|
80
|
+
}
|
|
81
|
+
function runBrCodeCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
82
|
+
const source = options.source ? BRCODE_OFFICIAL_SOURCE_URL : void 0;
|
|
83
|
+
const result = action === "validate" ? validateBrCode(input) : parseBrCode(input);
|
|
84
|
+
return printBrCodeResult(result, { json: options.json, quiet: options.quiet, source }, io);
|
|
85
|
+
}
|
|
86
|
+
function runBrCode(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
87
|
+
const input = resolveInput(value, options.file);
|
|
88
|
+
if (input === null) {
|
|
89
|
+
io.stderr.push("Missing BR Code payload. Pass an argument or use --file.");
|
|
90
|
+
return EXIT.USAGE;
|
|
91
|
+
}
|
|
92
|
+
return runBrCodeCommand(action, input, options, io);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/commands/cep.ts
|
|
96
|
+
import {
|
|
97
|
+
CEP_OFFICIAL_SOURCE_URL,
|
|
98
|
+
formatCep,
|
|
99
|
+
stripCep,
|
|
100
|
+
validateCep
|
|
101
|
+
} from "@br-validators/core";
|
|
102
|
+
|
|
103
|
+
// src/output.ts
|
|
104
|
+
function printValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
105
|
+
if (options.json) {
|
|
106
|
+
io.stdout.push(
|
|
107
|
+
JSON.stringify(
|
|
108
|
+
result.ok ? {
|
|
109
|
+
ok: true,
|
|
110
|
+
value: result.value,
|
|
111
|
+
format: result.format,
|
|
112
|
+
...options.source ? { source: options.source } : {}
|
|
113
|
+
} : { ok: false, code: result.code, message: result.message },
|
|
114
|
+
null,
|
|
115
|
+
2
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
119
|
+
}
|
|
120
|
+
if (options.quiet) {
|
|
121
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
122
|
+
}
|
|
123
|
+
if (result.ok) {
|
|
124
|
+
io.stdout.push(`valid: yes (${result.format})`);
|
|
125
|
+
io.stdout.push(`value: ${result.value}`);
|
|
126
|
+
if (options.source) {
|
|
127
|
+
io.stdout.push(`source: ${options.source}`);
|
|
128
|
+
}
|
|
129
|
+
return EXIT.OK;
|
|
130
|
+
}
|
|
131
|
+
io.stderr.push("valid: no");
|
|
132
|
+
io.stderr.push(`code: ${result.code}`);
|
|
133
|
+
io.stderr.push(`message: ${result.message}`);
|
|
134
|
+
return EXIT.INVALID;
|
|
135
|
+
}
|
|
136
|
+
function printNfeChaveValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
137
|
+
if (options.json) {
|
|
138
|
+
io.stdout.push(
|
|
139
|
+
JSON.stringify(
|
|
140
|
+
result.ok ? {
|
|
141
|
+
ok: true,
|
|
142
|
+
value: result.value,
|
|
143
|
+
format: result.format,
|
|
144
|
+
parsed: result.parsed,
|
|
145
|
+
...result.uf ? { uf: result.uf } : {},
|
|
146
|
+
...options.source ? { source: options.source } : {}
|
|
147
|
+
} : { ok: false, code: result.code, message: result.message },
|
|
148
|
+
null,
|
|
149
|
+
2
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
153
|
+
}
|
|
154
|
+
if (options.quiet) {
|
|
155
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
156
|
+
}
|
|
157
|
+
if (result.ok) {
|
|
158
|
+
io.stdout.push(`valid: yes (${result.format})`);
|
|
159
|
+
io.stdout.push(`value: ${result.value}`);
|
|
160
|
+
io.stdout.push(`cUF: ${result.parsed.cUF}`);
|
|
161
|
+
io.stdout.push(`cnpj: ${result.parsed.cnpj}`);
|
|
162
|
+
io.stdout.push(`mod: ${result.parsed.mod}`);
|
|
163
|
+
if (result.uf) {
|
|
164
|
+
io.stdout.push(`uf: ${result.uf}`);
|
|
165
|
+
}
|
|
166
|
+
if (options.source) {
|
|
167
|
+
io.stdout.push(`source: ${options.source}`);
|
|
168
|
+
}
|
|
169
|
+
return EXIT.OK;
|
|
170
|
+
}
|
|
171
|
+
io.stderr.push("valid: no");
|
|
172
|
+
io.stderr.push(`code: ${result.code}`);
|
|
173
|
+
io.stderr.push(`message: ${result.message}`);
|
|
174
|
+
return EXIT.INVALID;
|
|
175
|
+
}
|
|
176
|
+
function printFormat(result, options, io = { stdout: [], stderr: [] }) {
|
|
177
|
+
if (options.json) {
|
|
178
|
+
io.stdout.push(JSON.stringify(result, null, 2));
|
|
179
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
180
|
+
}
|
|
181
|
+
if (options.quiet) {
|
|
182
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
183
|
+
}
|
|
184
|
+
if (result.ok) {
|
|
185
|
+
io.stdout.push(result.formatted);
|
|
186
|
+
return EXIT.OK;
|
|
187
|
+
}
|
|
188
|
+
io.stderr.push(`code: ${result.code}`);
|
|
189
|
+
io.stderr.push(`message: ${result.message}`);
|
|
190
|
+
return EXIT.INVALID;
|
|
191
|
+
}
|
|
192
|
+
function printStrip(value, options, io = { stdout: [] }) {
|
|
193
|
+
if (options.json) {
|
|
194
|
+
io.stdout.push(JSON.stringify({ stripped: value }, null, 2));
|
|
195
|
+
} else {
|
|
196
|
+
io.stdout.push(value);
|
|
197
|
+
}
|
|
198
|
+
return EXIT.OK;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/commands/cep.ts
|
|
202
|
+
function resolveInput2(value, fileContent) {
|
|
203
|
+
const input = value ?? fileContent?.trim();
|
|
204
|
+
if (!input) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
return input;
|
|
208
|
+
}
|
|
209
|
+
function runCepCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
210
|
+
const source = options.source ? CEP_OFFICIAL_SOURCE_URL : void 0;
|
|
211
|
+
switch (action) {
|
|
212
|
+
case "validate":
|
|
213
|
+
return printValidation(validateCep(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
214
|
+
case "format":
|
|
215
|
+
return printFormat(formatCep(input), { json: options.json, quiet: options.quiet }, io);
|
|
216
|
+
case "strip":
|
|
217
|
+
return printStrip(stripCep(input), { json: options.json }, io);
|
|
218
|
+
default: {
|
|
219
|
+
const _exhaustive = action;
|
|
220
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
221
|
+
return EXIT.USAGE;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function runCep(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
226
|
+
const input = resolveInput2(value, options.file);
|
|
227
|
+
if (input === null) {
|
|
228
|
+
io.stderr.push("Missing CEP value. Pass an argument or use --file.");
|
|
229
|
+
return EXIT.USAGE;
|
|
230
|
+
}
|
|
231
|
+
return runCepCommand(action, input, options, io);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/commands/telefone.ts
|
|
235
|
+
import {
|
|
236
|
+
TELEFONE_OFFICIAL_SOURCE_URL,
|
|
237
|
+
formatTelefone,
|
|
238
|
+
stripTelefone,
|
|
239
|
+
validateTelefone
|
|
240
|
+
} from "@br-validators/core";
|
|
241
|
+
function resolveInput3(value, fileContent) {
|
|
242
|
+
const input = value ?? fileContent?.trim();
|
|
243
|
+
if (!input) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
return input;
|
|
247
|
+
}
|
|
248
|
+
function printTelefoneValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
249
|
+
if (options.json) {
|
|
250
|
+
io.stdout.push(
|
|
251
|
+
JSON.stringify(
|
|
252
|
+
result.ok ? {
|
|
253
|
+
ok: true,
|
|
254
|
+
value: result.value,
|
|
255
|
+
tipo: result.tipo,
|
|
256
|
+
format: result.format,
|
|
257
|
+
...options.source ? { source: options.source } : {}
|
|
258
|
+
} : { ok: false, code: result.code, message: result.message },
|
|
259
|
+
null,
|
|
260
|
+
2
|
|
261
|
+
)
|
|
262
|
+
);
|
|
263
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
264
|
+
}
|
|
265
|
+
if (options.quiet) {
|
|
266
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
267
|
+
}
|
|
268
|
+
if (result.ok) {
|
|
269
|
+
io.stdout.push(`valid: yes (${result.tipo})`);
|
|
270
|
+
io.stdout.push(`value: ${result.value}`);
|
|
271
|
+
io.stdout.push(`format: ${result.format}`);
|
|
272
|
+
if (options.source) {
|
|
273
|
+
io.stdout.push(`source: ${options.source}`);
|
|
274
|
+
}
|
|
275
|
+
return EXIT.OK;
|
|
276
|
+
}
|
|
277
|
+
io.stderr.push("valid: no");
|
|
278
|
+
io.stderr.push(`code: ${result.code}`);
|
|
279
|
+
io.stderr.push(`message: ${result.message}`);
|
|
280
|
+
return EXIT.INVALID;
|
|
281
|
+
}
|
|
282
|
+
function runTelefoneCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
283
|
+
const source = options.source ? TELEFONE_OFFICIAL_SOURCE_URL : void 0;
|
|
284
|
+
switch (action) {
|
|
285
|
+
case "validate":
|
|
286
|
+
return printTelefoneValidation(validateTelefone(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
287
|
+
case "format":
|
|
288
|
+
return printFormat(formatTelefone(input), { json: options.json, quiet: options.quiet }, io);
|
|
289
|
+
case "strip":
|
|
290
|
+
return printStrip(stripTelefone(input), { json: options.json }, io);
|
|
291
|
+
default: {
|
|
292
|
+
const _exhaustive = action;
|
|
293
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
294
|
+
return EXIT.USAGE;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function runTelefone(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
299
|
+
const input = resolveInput3(value, options.file);
|
|
300
|
+
if (input === null) {
|
|
301
|
+
io.stderr.push("Missing telephone value. Pass an argument or use --file.");
|
|
302
|
+
return EXIT.USAGE;
|
|
303
|
+
}
|
|
304
|
+
return runTelefoneCommand(action, input, options, io);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// src/commands/cnh.ts
|
|
308
|
+
import {
|
|
309
|
+
CNH_OFFICIAL_SOURCE_URL,
|
|
310
|
+
formatCnh,
|
|
311
|
+
stripCnh,
|
|
312
|
+
validateCnh
|
|
313
|
+
} from "@br-validators/core";
|
|
314
|
+
function resolveInput4(value, fileContent) {
|
|
315
|
+
const input = value ?? fileContent?.trim();
|
|
316
|
+
if (!input) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
return input;
|
|
320
|
+
}
|
|
321
|
+
function runCnhCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
322
|
+
const source = options.source ? CNH_OFFICIAL_SOURCE_URL : void 0;
|
|
323
|
+
switch (action) {
|
|
324
|
+
case "validate":
|
|
325
|
+
return printValidation(validateCnh(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
326
|
+
case "format":
|
|
327
|
+
return printFormat(formatCnh(input), { json: options.json, quiet: options.quiet }, io);
|
|
328
|
+
case "strip":
|
|
329
|
+
return printStrip(stripCnh(input), { json: options.json }, io);
|
|
330
|
+
default: {
|
|
331
|
+
const _exhaustive = action;
|
|
332
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
333
|
+
return EXIT.USAGE;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function runCnh(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
338
|
+
const input = resolveInput4(value, options.file);
|
|
339
|
+
if (input === null) {
|
|
340
|
+
io.stderr.push("Missing CNH value. Pass an argument or use --file.");
|
|
341
|
+
return EXIT.USAGE;
|
|
342
|
+
}
|
|
343
|
+
return runCnhCommand(action, input, options, io);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// src/commands/renavam.ts
|
|
347
|
+
import {
|
|
348
|
+
RENAVAM_OFFICIAL_SOURCE_URL,
|
|
349
|
+
formatRenavam,
|
|
350
|
+
stripRenavam,
|
|
351
|
+
validateRenavam
|
|
352
|
+
} from "@br-validators/core";
|
|
353
|
+
function resolveInput5(value, fileContent) {
|
|
354
|
+
const input = value ?? fileContent?.trim();
|
|
355
|
+
if (!input) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
return input;
|
|
359
|
+
}
|
|
360
|
+
function runRenavamCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
361
|
+
const source = options.source ? RENAVAM_OFFICIAL_SOURCE_URL : void 0;
|
|
362
|
+
switch (action) {
|
|
363
|
+
case "validate":
|
|
364
|
+
return printValidation(validateRenavam(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
365
|
+
case "format":
|
|
366
|
+
return printFormat(formatRenavam(input), { json: options.json, quiet: options.quiet }, io);
|
|
367
|
+
case "strip":
|
|
368
|
+
return printStrip(stripRenavam(input), { json: options.json }, io);
|
|
369
|
+
default: {
|
|
370
|
+
const _exhaustive = action;
|
|
371
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
372
|
+
return EXIT.USAGE;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
function runRenavam(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
377
|
+
const input = resolveInput5(value, options.file);
|
|
378
|
+
if (input === null) {
|
|
379
|
+
io.stderr.push("Missing RENAVAM value. Pass an argument or use --file.");
|
|
380
|
+
return EXIT.USAGE;
|
|
381
|
+
}
|
|
382
|
+
return runRenavamCommand(action, input, options, io);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/commands/titulo-eleitor.ts
|
|
386
|
+
import {
|
|
387
|
+
TITULO_ELEITOR_OFFICIAL_SOURCE_URL,
|
|
388
|
+
formatTituloEleitor,
|
|
389
|
+
stripTituloEleitor,
|
|
390
|
+
validateTituloEleitor
|
|
391
|
+
} from "@br-validators/core";
|
|
392
|
+
function resolveInput6(value, fileContent) {
|
|
393
|
+
const input = value ?? fileContent?.trim();
|
|
394
|
+
if (!input) {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
return input;
|
|
398
|
+
}
|
|
399
|
+
function runTituloEleitorCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
400
|
+
const source = options.source ? TITULO_ELEITOR_OFFICIAL_SOURCE_URL : void 0;
|
|
401
|
+
switch (action) {
|
|
402
|
+
case "validate":
|
|
403
|
+
return printValidation(validateTituloEleitor(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
404
|
+
case "format":
|
|
405
|
+
return printFormat(formatTituloEleitor(input), { json: options.json, quiet: options.quiet }, io);
|
|
406
|
+
case "strip":
|
|
407
|
+
return printStrip(stripTituloEleitor(input), { json: options.json }, io);
|
|
408
|
+
default: {
|
|
409
|
+
const _exhaustive = action;
|
|
410
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
411
|
+
return EXIT.USAGE;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function runTituloEleitor(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
416
|
+
const input = resolveInput6(value, options.file);
|
|
417
|
+
if (input === null) {
|
|
418
|
+
io.stderr.push("Missing T\xEDtulo de Eleitor value. Pass an argument or use --file.");
|
|
419
|
+
return EXIT.USAGE;
|
|
420
|
+
}
|
|
421
|
+
return runTituloEleitorCommand(action, input, options, io);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/commands/nfe-chave.ts
|
|
425
|
+
import {
|
|
426
|
+
NFE_CHAVE_OFFICIAL_SOURCE_URL,
|
|
427
|
+
formatNfeChave,
|
|
428
|
+
parseNfeChave,
|
|
429
|
+
stripNfeChave,
|
|
430
|
+
validateNfeChave
|
|
431
|
+
} from "@br-validators/core";
|
|
432
|
+
function resolveInput7(value, fileContent) {
|
|
433
|
+
const input = value ?? fileContent?.trim();
|
|
434
|
+
if (!input) {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
return input;
|
|
438
|
+
}
|
|
439
|
+
function runNfeChaveCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
440
|
+
const source = options.source ? NFE_CHAVE_OFFICIAL_SOURCE_URL : void 0;
|
|
441
|
+
switch (action) {
|
|
442
|
+
case "validate":
|
|
443
|
+
return printValidation(validateNfeChave(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
444
|
+
case "parse":
|
|
445
|
+
return printNfeChaveValidation(parseNfeChave(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
446
|
+
case "format":
|
|
447
|
+
return printFormat(formatNfeChave(input), { json: options.json, quiet: options.quiet }, io);
|
|
448
|
+
case "strip":
|
|
449
|
+
return printStrip(stripNfeChave(input), { json: options.json }, io);
|
|
450
|
+
default: {
|
|
451
|
+
const _exhaustive = action;
|
|
452
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
453
|
+
return EXIT.USAGE;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function runNfeChave(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
458
|
+
const input = resolveInput7(value, options.file);
|
|
459
|
+
if (input === null) {
|
|
460
|
+
io.stderr.push("Missing NF-e chave de acesso value. Pass an argument or use --file.");
|
|
461
|
+
return EXIT.USAGE;
|
|
462
|
+
}
|
|
463
|
+
return runNfeChaveCommand(action, input, options, io);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/commands/cnpj.ts
|
|
467
|
+
import {
|
|
468
|
+
CNPJ_OFFICIAL_SOURCE_URL,
|
|
469
|
+
formatCnpj,
|
|
470
|
+
stripCnpj,
|
|
471
|
+
validateCnpj
|
|
472
|
+
} from "@br-validators/core";
|
|
473
|
+
function resolveInput8(value, fileContent) {
|
|
474
|
+
const input = value ?? fileContent?.trim();
|
|
475
|
+
if (!input) {
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
return input;
|
|
479
|
+
}
|
|
480
|
+
function runCnpjCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
481
|
+
const source = options.source ? CNPJ_OFFICIAL_SOURCE_URL : void 0;
|
|
482
|
+
switch (action) {
|
|
483
|
+
case "validate":
|
|
484
|
+
return printValidation(validateCnpj(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
485
|
+
case "format":
|
|
486
|
+
return printFormat(formatCnpj(input), { json: options.json, quiet: options.quiet }, io);
|
|
487
|
+
case "strip":
|
|
488
|
+
return printStrip(stripCnpj(input), { json: options.json }, io);
|
|
489
|
+
default: {
|
|
490
|
+
const _exhaustive = action;
|
|
491
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
492
|
+
return EXIT.USAGE;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function runCnpj(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
497
|
+
const input = resolveInput8(value, options.file);
|
|
498
|
+
if (input === null) {
|
|
499
|
+
io.stderr.push("Missing CNPJ value. Pass an argument or use --file.");
|
|
500
|
+
return EXIT.USAGE;
|
|
501
|
+
}
|
|
502
|
+
return runCnpjCommand(action, input, options, io);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/commands/cpf.ts
|
|
506
|
+
import {
|
|
507
|
+
CPF_OFFICIAL_SOURCE_URL,
|
|
508
|
+
formatCpf,
|
|
509
|
+
stripCpf,
|
|
510
|
+
validateCpf
|
|
511
|
+
} from "@br-validators/core";
|
|
512
|
+
function resolveInput9(value, fileContent) {
|
|
513
|
+
const input = value ?? fileContent?.trim();
|
|
514
|
+
if (!input) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
return input;
|
|
518
|
+
}
|
|
519
|
+
function runCpfCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
520
|
+
const source = options.source ? CPF_OFFICIAL_SOURCE_URL : void 0;
|
|
521
|
+
switch (action) {
|
|
522
|
+
case "validate":
|
|
523
|
+
return printValidation(validateCpf(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
524
|
+
case "format":
|
|
525
|
+
return printFormat(formatCpf(input), { json: options.json, quiet: options.quiet }, io);
|
|
526
|
+
case "strip":
|
|
527
|
+
return printStrip(stripCpf(input), { json: options.json }, io);
|
|
528
|
+
default: {
|
|
529
|
+
const _exhaustive = action;
|
|
530
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
531
|
+
return EXIT.USAGE;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
function runCpf(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
536
|
+
const input = resolveInput9(value, options.file);
|
|
537
|
+
if (input === null) {
|
|
538
|
+
io.stderr.push("Missing CPF value. Pass an argument or use --file.");
|
|
539
|
+
return EXIT.USAGE;
|
|
540
|
+
}
|
|
541
|
+
return runCpfCommand(action, input, options, io);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/commands/placa.ts
|
|
545
|
+
import {
|
|
546
|
+
PLACA_OFFICIAL_SOURCE_URL,
|
|
547
|
+
convertPlacaToMercosul,
|
|
548
|
+
formatPlaca,
|
|
549
|
+
stripPlaca,
|
|
550
|
+
validatePlaca
|
|
551
|
+
} from "@br-validators/core";
|
|
552
|
+
function resolveInput10(value, fileContent) {
|
|
553
|
+
const input = value ?? fileContent?.trim();
|
|
554
|
+
if (!input) {
|
|
555
|
+
return null;
|
|
556
|
+
}
|
|
557
|
+
return input;
|
|
558
|
+
}
|
|
559
|
+
function runPlacaCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
560
|
+
const source = options.source ? PLACA_OFFICIAL_SOURCE_URL : void 0;
|
|
561
|
+
switch (action) {
|
|
562
|
+
case "validate":
|
|
563
|
+
return printValidation(validatePlaca(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
564
|
+
case "format":
|
|
565
|
+
return printFormat(formatPlaca(input), { json: options.json, quiet: options.quiet }, io);
|
|
566
|
+
case "convert":
|
|
567
|
+
return printFormat(convertPlacaToMercosul(input), { json: options.json, quiet: options.quiet }, io);
|
|
568
|
+
case "strip":
|
|
569
|
+
return printStrip(stripPlaca(input), { json: options.json }, io);
|
|
570
|
+
default: {
|
|
571
|
+
const _exhaustive = action;
|
|
572
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
573
|
+
return EXIT.USAGE;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
function runPlaca(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
578
|
+
const input = resolveInput10(value, options.file);
|
|
579
|
+
if (input === null) {
|
|
580
|
+
io.stderr.push("Missing placa value. Pass an argument or use --file.");
|
|
581
|
+
return EXIT.USAGE;
|
|
582
|
+
}
|
|
583
|
+
return runPlacaCommand(action, input, options, io);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/commands/pis-pasep.ts
|
|
587
|
+
import {
|
|
588
|
+
PIS_PASEP_OFFICIAL_SOURCE_URL,
|
|
589
|
+
formatPisPasep,
|
|
590
|
+
stripPisPasep,
|
|
591
|
+
validatePisPasep
|
|
592
|
+
} from "@br-validators/core";
|
|
593
|
+
function resolveInput11(value, fileContent) {
|
|
594
|
+
const input = value ?? fileContent?.trim();
|
|
595
|
+
if (!input) {
|
|
596
|
+
return null;
|
|
597
|
+
}
|
|
598
|
+
return input;
|
|
599
|
+
}
|
|
600
|
+
function runPisPasepCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
601
|
+
const source = options.source ? PIS_PASEP_OFFICIAL_SOURCE_URL : void 0;
|
|
602
|
+
switch (action) {
|
|
603
|
+
case "validate":
|
|
604
|
+
return printValidation(validatePisPasep(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
605
|
+
case "format":
|
|
606
|
+
return printFormat(formatPisPasep(input), { json: options.json, quiet: options.quiet }, io);
|
|
607
|
+
case "strip":
|
|
608
|
+
return printStrip(stripPisPasep(input), { json: options.json }, io);
|
|
609
|
+
default: {
|
|
610
|
+
const _exhaustive = action;
|
|
611
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
612
|
+
return EXIT.USAGE;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
function runPisPasep(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
617
|
+
const input = resolveInput11(value, options.file);
|
|
618
|
+
if (input === null) {
|
|
619
|
+
io.stderr.push("Missing PIS/PASEP value. Pass an argument or use --file.");
|
|
620
|
+
return EXIT.USAGE;
|
|
621
|
+
}
|
|
622
|
+
return runPisPasepCommand(action, input, options, io);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/commands/pix.ts
|
|
626
|
+
import {
|
|
627
|
+
PIX_OFFICIAL_SOURCE_URL,
|
|
628
|
+
detectPixKeyType,
|
|
629
|
+
formatPixKey,
|
|
630
|
+
validatePixKey
|
|
631
|
+
} from "@br-validators/core";
|
|
632
|
+
function resolveInput12(value, fileContent) {
|
|
633
|
+
const input = value ?? fileContent?.trim();
|
|
634
|
+
if (!input) {
|
|
635
|
+
return null;
|
|
636
|
+
}
|
|
637
|
+
return input;
|
|
638
|
+
}
|
|
639
|
+
function printPixValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
640
|
+
if (options.json) {
|
|
641
|
+
io.stdout.push(
|
|
642
|
+
JSON.stringify(
|
|
643
|
+
result.ok ? {
|
|
644
|
+
ok: true,
|
|
645
|
+
value: result.value,
|
|
646
|
+
keyType: result.keyType,
|
|
647
|
+
format: result.format,
|
|
648
|
+
...options.source ? { source: options.source } : {}
|
|
649
|
+
} : {
|
|
650
|
+
ok: false,
|
|
651
|
+
code: result.code,
|
|
652
|
+
message: result.message,
|
|
653
|
+
...result.keyType ? { keyType: result.keyType } : {}
|
|
654
|
+
},
|
|
655
|
+
null,
|
|
656
|
+
2
|
|
657
|
+
)
|
|
658
|
+
);
|
|
659
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
660
|
+
}
|
|
661
|
+
if (options.quiet) {
|
|
662
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
663
|
+
}
|
|
664
|
+
if (result.ok) {
|
|
665
|
+
io.stdout.push(`valid: yes (${result.keyType})`);
|
|
666
|
+
io.stdout.push(`value: ${result.value}`);
|
|
667
|
+
io.stdout.push(`format: ${result.format}`);
|
|
668
|
+
if (options.source) {
|
|
669
|
+
io.stdout.push(`source: ${options.source}`);
|
|
670
|
+
}
|
|
671
|
+
return EXIT.OK;
|
|
672
|
+
}
|
|
673
|
+
io.stderr.push("valid: no");
|
|
674
|
+
io.stderr.push(`code: ${result.code}`);
|
|
675
|
+
io.stderr.push(`message: ${result.message}`);
|
|
676
|
+
if (result.keyType) {
|
|
677
|
+
io.stderr.push(`keyType: ${result.keyType}`);
|
|
678
|
+
}
|
|
679
|
+
return EXIT.INVALID;
|
|
680
|
+
}
|
|
681
|
+
function printPixDetect(keyType, options, io = { stdout: [] }) {
|
|
682
|
+
if (options.json) {
|
|
683
|
+
io.stdout.push(JSON.stringify({ keyType }, null, 2));
|
|
684
|
+
} else if (!options.quiet) {
|
|
685
|
+
io.stdout.push(keyType);
|
|
686
|
+
}
|
|
687
|
+
return EXIT.OK;
|
|
688
|
+
}
|
|
689
|
+
function runPixCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
690
|
+
const source = options.source ? PIX_OFFICIAL_SOURCE_URL : void 0;
|
|
691
|
+
const validateOptions = options.type ? { type: options.type } : void 0;
|
|
692
|
+
switch (action) {
|
|
693
|
+
case "validate":
|
|
694
|
+
return printPixValidation(validatePixKey(input, validateOptions), { json: options.json, quiet: options.quiet, source }, io);
|
|
695
|
+
case "format":
|
|
696
|
+
return printFormat(formatPixKey(input, validateOptions), { json: options.json, quiet: options.quiet }, io);
|
|
697
|
+
case "detect":
|
|
698
|
+
return printPixDetect(detectPixKeyType(input), { json: options.json, quiet: options.quiet }, io);
|
|
699
|
+
default: {
|
|
700
|
+
const _exhaustive = action;
|
|
701
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
702
|
+
return EXIT.USAGE;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function runPix(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
707
|
+
const input = resolveInput12(value, options.file);
|
|
708
|
+
if (input === null) {
|
|
709
|
+
io.stderr.push("Missing PIX key value. Pass an argument or use --file.");
|
|
710
|
+
return EXIT.USAGE;
|
|
711
|
+
}
|
|
712
|
+
return runPixCommand(action, input, options, io);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// src/commands/boleto.ts
|
|
716
|
+
import {
|
|
717
|
+
BOLETO_OFFICIAL_SOURCE_URL,
|
|
718
|
+
convertCodigoBarrasToLinhaDigitavel,
|
|
719
|
+
convertLinhaToCodigoBarras,
|
|
720
|
+
detectBoletoInputKind,
|
|
721
|
+
formatBoleto,
|
|
722
|
+
stripCodigoBarras,
|
|
723
|
+
stripLinhaDigitavel,
|
|
724
|
+
validateBoleto
|
|
725
|
+
} from "@br-validators/core";
|
|
726
|
+
function resolveInput13(value, fileContent) {
|
|
727
|
+
const input = value ?? fileContent?.trim();
|
|
728
|
+
if (!input) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
return input;
|
|
732
|
+
}
|
|
733
|
+
function printBoletoValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
734
|
+
if (options.json) {
|
|
735
|
+
io.stdout.push(
|
|
736
|
+
JSON.stringify(
|
|
737
|
+
result.ok ? {
|
|
738
|
+
ok: true,
|
|
739
|
+
value: result.value,
|
|
740
|
+
inputKind: result.inputKind,
|
|
741
|
+
format: result.format,
|
|
742
|
+
situacao: result.situacao,
|
|
743
|
+
...options.source ? { source: options.source } : {}
|
|
744
|
+
} : {
|
|
745
|
+
ok: false,
|
|
746
|
+
code: result.code,
|
|
747
|
+
message: result.message,
|
|
748
|
+
...result.inputKind ? { inputKind: result.inputKind } : {}
|
|
749
|
+
},
|
|
750
|
+
null,
|
|
751
|
+
2
|
|
752
|
+
)
|
|
753
|
+
);
|
|
754
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
755
|
+
}
|
|
756
|
+
if (options.quiet) {
|
|
757
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
758
|
+
}
|
|
759
|
+
if (result.ok) {
|
|
760
|
+
io.stdout.push(`valid: yes (${result.inputKind})`);
|
|
761
|
+
io.stdout.push(`value: ${result.value}`);
|
|
762
|
+
io.stdout.push(`format: ${result.format}`);
|
|
763
|
+
io.stdout.push(`situacao: ${result.situacao}`);
|
|
764
|
+
if (options.source) {
|
|
765
|
+
io.stdout.push(`source: ${options.source}`);
|
|
766
|
+
}
|
|
767
|
+
return EXIT.OK;
|
|
768
|
+
}
|
|
769
|
+
io.stderr.push("valid: no");
|
|
770
|
+
io.stderr.push(`code: ${result.code}`);
|
|
771
|
+
io.stderr.push(`message: ${result.message}`);
|
|
772
|
+
if (result.inputKind) {
|
|
773
|
+
io.stderr.push(`inputKind: ${result.inputKind}`);
|
|
774
|
+
}
|
|
775
|
+
return EXIT.INVALID;
|
|
776
|
+
}
|
|
777
|
+
function printBoletoDetect(inputKind, options, io = { stdout: [] }) {
|
|
778
|
+
if (options.json) {
|
|
779
|
+
io.stdout.push(JSON.stringify({ inputKind }, null, 2));
|
|
780
|
+
} else if (!options.quiet) {
|
|
781
|
+
io.stdout.push(inputKind);
|
|
782
|
+
}
|
|
783
|
+
return EXIT.OK;
|
|
784
|
+
}
|
|
785
|
+
function printBoletoConvert(result, options, io = { stdout: [], stderr: [] }) {
|
|
786
|
+
if (options.json) {
|
|
787
|
+
io.stdout.push(
|
|
788
|
+
JSON.stringify(
|
|
789
|
+
result.ok ? { ok: true, value: result.value, inputKind: result.inputKind, format: result.format } : { ok: false, code: result.code, message: result.message, ...result.inputKind ? { inputKind: result.inputKind } : {} },
|
|
790
|
+
null,
|
|
791
|
+
2
|
|
792
|
+
)
|
|
793
|
+
);
|
|
794
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
795
|
+
}
|
|
796
|
+
if (options.quiet) {
|
|
797
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
798
|
+
}
|
|
799
|
+
if (result.ok) {
|
|
800
|
+
io.stdout.push(result.value);
|
|
801
|
+
return EXIT.OK;
|
|
802
|
+
}
|
|
803
|
+
io.stderr.push(`code: ${result.code}`);
|
|
804
|
+
io.stderr.push(`message: ${result.message}`);
|
|
805
|
+
return EXIT.INVALID;
|
|
806
|
+
}
|
|
807
|
+
function printBoletoFormat(input, options, io = { stdout: [], stderr: [] }) {
|
|
808
|
+
return printFormat(formatBoleto(input), { json: options.json, quiet: options.quiet }, io);
|
|
809
|
+
}
|
|
810
|
+
function printBoletoStrip(input, options, io = { stdout: [] }) {
|
|
811
|
+
const kind = detectBoletoInputKind(input);
|
|
812
|
+
const stripped = kind === "codigo-barras" ? stripCodigoBarras(input) : stripLinhaDigitavel(input);
|
|
813
|
+
if (options.json) {
|
|
814
|
+
io.stdout.push(JSON.stringify({ stripped, inputKind: kind }, null, 2));
|
|
815
|
+
} else if (!options.quiet) {
|
|
816
|
+
io.stdout.push(stripped);
|
|
817
|
+
}
|
|
818
|
+
return EXIT.OK;
|
|
819
|
+
}
|
|
820
|
+
function runBoletoCommand(action, input, options, direction, io = { stdout: [], stderr: [] }) {
|
|
821
|
+
const source = options.source ? BOLETO_OFFICIAL_SOURCE_URL : void 0;
|
|
822
|
+
const validateOptions = options.kind ? { kind: options.kind } : void 0;
|
|
823
|
+
switch (action) {
|
|
824
|
+
case "validate":
|
|
825
|
+
return printBoletoValidation(validateBoleto(input, validateOptions), { json: options.json, quiet: options.quiet, source }, io);
|
|
826
|
+
case "detect":
|
|
827
|
+
return printBoletoDetect(detectBoletoInputKind(input), { json: options.json, quiet: options.quiet }, io);
|
|
828
|
+
case "convert": {
|
|
829
|
+
if (direction === "linha-to-barras") {
|
|
830
|
+
return printBoletoConvert(convertLinhaToCodigoBarras(input), { json: options.json, quiet: options.quiet }, io);
|
|
831
|
+
}
|
|
832
|
+
if (direction === "barras-to-linha") {
|
|
833
|
+
return printBoletoConvert(convertCodigoBarrasToLinhaDigitavel(input), { json: options.json, quiet: options.quiet }, io);
|
|
834
|
+
}
|
|
835
|
+
io.stderr.push("Missing convert direction. Use linha-to-barras or barras-to-linha.");
|
|
836
|
+
return EXIT.USAGE;
|
|
837
|
+
}
|
|
838
|
+
case "format":
|
|
839
|
+
return printBoletoFormat(input, { json: options.json, quiet: options.quiet }, io);
|
|
840
|
+
case "strip":
|
|
841
|
+
return printBoletoStrip(input, { json: options.json, quiet: options.quiet }, io);
|
|
842
|
+
default: {
|
|
843
|
+
const _exhaustive = action;
|
|
844
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
845
|
+
return EXIT.USAGE;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
function runBoleto(action, value, options, direction, io = { stdout: [], stderr: [] }) {
|
|
850
|
+
const input = resolveInput13(value, options.file);
|
|
851
|
+
if (input === null) {
|
|
852
|
+
io.stderr.push("Missing boleto value. Pass an argument or use --file.");
|
|
853
|
+
return EXIT.USAGE;
|
|
854
|
+
}
|
|
855
|
+
return runBoletoCommand(action, input, options, direction, io);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// src/commands/cartao.ts
|
|
859
|
+
import {
|
|
860
|
+
CARTAO_OFFICIAL_SOURCE_URL,
|
|
861
|
+
detectCardBrand,
|
|
862
|
+
formatCartaoCredito,
|
|
863
|
+
stripCartaoCredito,
|
|
864
|
+
validateCartaoCredito
|
|
865
|
+
} from "@br-validators/core";
|
|
866
|
+
function resolveInput14(value, fileContent) {
|
|
867
|
+
const input = value ?? fileContent?.trim();
|
|
868
|
+
if (!input) {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
return input;
|
|
872
|
+
}
|
|
873
|
+
function printCartaoValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
874
|
+
if (options.json) {
|
|
875
|
+
io.stdout.push(
|
|
876
|
+
JSON.stringify(
|
|
877
|
+
result.ok ? {
|
|
878
|
+
ok: true,
|
|
879
|
+
value: result.value,
|
|
880
|
+
brand: result.brand,
|
|
881
|
+
format: result.format,
|
|
882
|
+
...options.source ? { source: options.source } : {}
|
|
883
|
+
} : {
|
|
884
|
+
ok: false,
|
|
885
|
+
code: result.code,
|
|
886
|
+
message: result.message,
|
|
887
|
+
...result.brand ? { brand: result.brand } : {}
|
|
888
|
+
},
|
|
889
|
+
null,
|
|
890
|
+
2
|
|
891
|
+
)
|
|
892
|
+
);
|
|
893
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
894
|
+
}
|
|
895
|
+
if (options.quiet) {
|
|
896
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
897
|
+
}
|
|
898
|
+
if (result.ok) {
|
|
899
|
+
io.stdout.push(`valid: yes (${result.format})`);
|
|
900
|
+
io.stdout.push(`brand: ${result.brand}`);
|
|
901
|
+
io.stdout.push(`value: ${result.value}`);
|
|
902
|
+
if (options.source) {
|
|
903
|
+
io.stdout.push(`source: ${options.source}`);
|
|
904
|
+
}
|
|
905
|
+
return EXIT.OK;
|
|
906
|
+
}
|
|
907
|
+
io.stderr.push("valid: no");
|
|
908
|
+
io.stderr.push(`code: ${result.code}`);
|
|
909
|
+
io.stderr.push(`message: ${result.message}`);
|
|
910
|
+
if (result.brand) {
|
|
911
|
+
io.stderr.push(`brand: ${result.brand}`);
|
|
912
|
+
}
|
|
913
|
+
return EXIT.INVALID;
|
|
914
|
+
}
|
|
915
|
+
function printCartaoDetect(brand, options, io = { stdout: [] }) {
|
|
916
|
+
if (options.json) {
|
|
917
|
+
io.stdout.push(JSON.stringify({ brand }, null, 2));
|
|
918
|
+
} else if (!options.quiet) {
|
|
919
|
+
io.stdout.push(brand);
|
|
920
|
+
}
|
|
921
|
+
return EXIT.OK;
|
|
922
|
+
}
|
|
923
|
+
function runCartaoCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
924
|
+
const source = options.source ? CARTAO_OFFICIAL_SOURCE_URL : void 0;
|
|
925
|
+
switch (action) {
|
|
926
|
+
case "validate":
|
|
927
|
+
return printCartaoValidation(validateCartaoCredito(input), { json: options.json, quiet: options.quiet, source }, io);
|
|
928
|
+
case "detect":
|
|
929
|
+
return printCartaoDetect(detectCardBrand(stripCartaoCredito(input)), { json: options.json, quiet: options.quiet }, io);
|
|
930
|
+
case "format":
|
|
931
|
+
return printFormat(formatCartaoCredito(input), { json: options.json, quiet: options.quiet }, io);
|
|
932
|
+
case "strip":
|
|
933
|
+
return printStrip(stripCartaoCredito(input), { json: options.json }, io);
|
|
934
|
+
default: {
|
|
935
|
+
const _exhaustive = action;
|
|
936
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
937
|
+
return EXIT.USAGE;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function runCartao(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
942
|
+
const input = resolveInput14(value, options.file);
|
|
943
|
+
if (input === null) {
|
|
944
|
+
io.stderr.push("Missing credit card PAN value. Pass an argument or use --file.");
|
|
945
|
+
return EXIT.USAGE;
|
|
946
|
+
}
|
|
947
|
+
return runCartaoCommand(action, input, options, io);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/commands/ie.ts
|
|
951
|
+
import {
|
|
952
|
+
formatIeProdutorRural,
|
|
953
|
+
formatInscricaoEstadual,
|
|
954
|
+
getIeOfficialSourceUrl,
|
|
955
|
+
getIeProdutorRuralOfficialSourceUrl,
|
|
956
|
+
IE_SUPPORTED_UFS,
|
|
957
|
+
isSpRuralIeInput,
|
|
958
|
+
stripIeSpRural,
|
|
959
|
+
stripInscricaoEstadual,
|
|
960
|
+
validateIeProdutorRural,
|
|
961
|
+
validateInscricaoEstadual
|
|
962
|
+
} from "@br-validators/core";
|
|
963
|
+
function resolveInput15(value, fileContent) {
|
|
964
|
+
const input = value ?? fileContent?.trim();
|
|
965
|
+
if (!input) {
|
|
966
|
+
return null;
|
|
967
|
+
}
|
|
968
|
+
return input;
|
|
969
|
+
}
|
|
970
|
+
function resolveUf(uf) {
|
|
971
|
+
if (uf === void 0) {
|
|
972
|
+
return null;
|
|
973
|
+
}
|
|
974
|
+
const normalized = uf.toUpperCase();
|
|
975
|
+
if (IE_SUPPORTED_UFS.includes(normalized)) {
|
|
976
|
+
return normalized;
|
|
977
|
+
}
|
|
978
|
+
return null;
|
|
979
|
+
}
|
|
980
|
+
function isSpRuralRoute(uf, input) {
|
|
981
|
+
return uf === "SP" && isSpRuralIeInput(input);
|
|
982
|
+
}
|
|
983
|
+
function printIeValidation(result, options, io = { stdout: [], stderr: [] }) {
|
|
984
|
+
if (options.json) {
|
|
985
|
+
io.stdout.push(
|
|
986
|
+
JSON.stringify(
|
|
987
|
+
result.ok ? {
|
|
988
|
+
ok: true,
|
|
989
|
+
value: result.value,
|
|
990
|
+
uf: result.uf,
|
|
991
|
+
format: result.format,
|
|
992
|
+
...options.rural ? { produtorRural: true } : {},
|
|
993
|
+
...options.source ? { source: options.source } : {}
|
|
994
|
+
} : {
|
|
995
|
+
ok: false,
|
|
996
|
+
code: result.code,
|
|
997
|
+
message: result.message,
|
|
998
|
+
...result.uf ? { uf: result.uf } : {}
|
|
999
|
+
},
|
|
1000
|
+
null,
|
|
1001
|
+
2
|
|
1002
|
+
)
|
|
1003
|
+
);
|
|
1004
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1005
|
+
}
|
|
1006
|
+
if (options.quiet) {
|
|
1007
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1008
|
+
}
|
|
1009
|
+
if (result.ok) {
|
|
1010
|
+
io.stdout.push(`valid: yes (${result.uf})`);
|
|
1011
|
+
if (options.rural) {
|
|
1012
|
+
io.stdout.push("kind: produtor-rural");
|
|
1013
|
+
}
|
|
1014
|
+
io.stdout.push(`value: ${result.value}`);
|
|
1015
|
+
io.stdout.push(`format: ${result.format}`);
|
|
1016
|
+
if (options.source) {
|
|
1017
|
+
io.stdout.push(`source: ${options.source}`);
|
|
1018
|
+
}
|
|
1019
|
+
return EXIT.OK;
|
|
1020
|
+
}
|
|
1021
|
+
io.stderr.push("valid: no");
|
|
1022
|
+
io.stderr.push(`code: ${result.code}`);
|
|
1023
|
+
io.stderr.push(`message: ${result.message}`);
|
|
1024
|
+
if (result.uf) {
|
|
1025
|
+
io.stderr.push(`uf: ${result.uf}`);
|
|
1026
|
+
}
|
|
1027
|
+
return EXIT.INVALID;
|
|
1028
|
+
}
|
|
1029
|
+
function runIeCommand(action, input, options, io = { stdout: [], stderr: [] }) {
|
|
1030
|
+
const uf = resolveUf(options.uf);
|
|
1031
|
+
if (!uf) {
|
|
1032
|
+
io.stderr.push(`Missing or invalid --uf. Use one of: ${IE_SUPPORTED_UFS.join(", ")}.`);
|
|
1033
|
+
return EXIT.USAGE;
|
|
1034
|
+
}
|
|
1035
|
+
const rural = isSpRuralRoute(uf, input);
|
|
1036
|
+
const source = options.source ? rural ? getIeProdutorRuralOfficialSourceUrl() : getIeOfficialSourceUrl(uf) : void 0;
|
|
1037
|
+
switch (action) {
|
|
1038
|
+
case "validate":
|
|
1039
|
+
return printIeValidation(
|
|
1040
|
+
rural ? validateIeProdutorRural(uf, input) : validateInscricaoEstadual(input, { uf }),
|
|
1041
|
+
{ json: options.json, quiet: options.quiet, source, rural },
|
|
1042
|
+
io
|
|
1043
|
+
);
|
|
1044
|
+
case "format":
|
|
1045
|
+
return printFormat(
|
|
1046
|
+
rural ? formatIeProdutorRural(input) : formatInscricaoEstadual(input, { uf }),
|
|
1047
|
+
{ json: options.json, quiet: options.quiet },
|
|
1048
|
+
io
|
|
1049
|
+
);
|
|
1050
|
+
case "strip":
|
|
1051
|
+
return printStrip(rural ? stripIeSpRural(input) : stripInscricaoEstadual(input), { json: options.json }, io);
|
|
1052
|
+
default: {
|
|
1053
|
+
const _exhaustive = action;
|
|
1054
|
+
io.stderr.push(`Unknown action: ${_exhaustive}`);
|
|
1055
|
+
return EXIT.USAGE;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
function runIe(action, value, options, io = { stdout: [], stderr: [] }) {
|
|
1060
|
+
const input = resolveInput15(value, options.file);
|
|
1061
|
+
if (input === null) {
|
|
1062
|
+
io.stderr.push("Missing IE value. Pass an argument or use --file.");
|
|
1063
|
+
return EXIT.USAGE;
|
|
1064
|
+
}
|
|
1065
|
+
return runIeCommand(action, input, options, io);
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
// src/commands/detect.ts
|
|
1069
|
+
import { detect } from "@br-validators/core";
|
|
1070
|
+
function resolveInput16(value, fileContent) {
|
|
1071
|
+
const input = value ?? fileContent?.trim();
|
|
1072
|
+
if (!input) {
|
|
1073
|
+
return null;
|
|
1074
|
+
}
|
|
1075
|
+
return input;
|
|
1076
|
+
}
|
|
1077
|
+
function printDetect(result, options, io = { stdout: [], stderr: [] }) {
|
|
1078
|
+
if (options.json) {
|
|
1079
|
+
io.stdout.push(JSON.stringify(result, null, 2));
|
|
1080
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1081
|
+
}
|
|
1082
|
+
if (options.quiet) {
|
|
1083
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1084
|
+
}
|
|
1085
|
+
if (result.ok) {
|
|
1086
|
+
io.stdout.push(`type: ${result.type}`);
|
|
1087
|
+
io.stdout.push("valid: yes");
|
|
1088
|
+
io.stdout.push(`value: ${result.value}`);
|
|
1089
|
+
if (result.format) {
|
|
1090
|
+
io.stdout.push(`format: ${result.format}`);
|
|
1091
|
+
}
|
|
1092
|
+
if (result.meta) {
|
|
1093
|
+
io.stdout.push(`meta: ${JSON.stringify(result.meta)}`);
|
|
1094
|
+
}
|
|
1095
|
+
return EXIT.OK;
|
|
1096
|
+
}
|
|
1097
|
+
io.stderr.push(`type: ${result.type}`);
|
|
1098
|
+
io.stderr.push("valid: no");
|
|
1099
|
+
io.stderr.push(`code: ${result.code}`);
|
|
1100
|
+
io.stderr.push(`message: ${result.message}`);
|
|
1101
|
+
return EXIT.INVALID;
|
|
1102
|
+
}
|
|
1103
|
+
function runDetect(value, options, io = { stdout: [], stderr: [] }) {
|
|
1104
|
+
const input = resolveInput16(value, options.file);
|
|
1105
|
+
if (input === null) {
|
|
1106
|
+
io.stderr.push("Missing value. Pass an argument or use --file.");
|
|
1107
|
+
return EXIT.USAGE;
|
|
1108
|
+
}
|
|
1109
|
+
const uf = options.uf?.toUpperCase();
|
|
1110
|
+
const result = detect(input, uf ? { uf } : {});
|
|
1111
|
+
return printDetect(result, options, io);
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// src/commands/sanitize.ts
|
|
1115
|
+
import { sanitize } from "@br-validators/core";
|
|
1116
|
+
var SANITIZABLE_TYPES = [
|
|
1117
|
+
"cpf",
|
|
1118
|
+
"cnpj",
|
|
1119
|
+
"cep",
|
|
1120
|
+
"placa",
|
|
1121
|
+
"pis-pasep",
|
|
1122
|
+
"telefone",
|
|
1123
|
+
"cnh",
|
|
1124
|
+
"renavam",
|
|
1125
|
+
"titulo-eleitor",
|
|
1126
|
+
"nfe-chave",
|
|
1127
|
+
"boleto",
|
|
1128
|
+
"cartao-credito",
|
|
1129
|
+
"inscricao-estadual",
|
|
1130
|
+
"inscricao-estadual-produtor-rural"
|
|
1131
|
+
];
|
|
1132
|
+
function isSanitizableType(type) {
|
|
1133
|
+
return SANITIZABLE_TYPES.includes(type);
|
|
1134
|
+
}
|
|
1135
|
+
function resolveInput17(value, fileContent) {
|
|
1136
|
+
const input = value ?? fileContent?.trim();
|
|
1137
|
+
if (!input) {
|
|
1138
|
+
return null;
|
|
1139
|
+
}
|
|
1140
|
+
return input;
|
|
1141
|
+
}
|
|
1142
|
+
function printSanitize(result, options, io = { stdout: [], stderr: [] }) {
|
|
1143
|
+
if (options.json) {
|
|
1144
|
+
io.stdout.push(JSON.stringify(result, null, 2));
|
|
1145
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1146
|
+
}
|
|
1147
|
+
if (options.quiet) {
|
|
1148
|
+
return result.ok ? EXIT.OK : EXIT.INVALID;
|
|
1149
|
+
}
|
|
1150
|
+
if (result.ok) {
|
|
1151
|
+
io.stdout.push("valid: yes");
|
|
1152
|
+
io.stdout.push(`value: ${result.value}`);
|
|
1153
|
+
io.stdout.push(`fixes: ${result.fixes.join(", ")}`);
|
|
1154
|
+
return EXIT.OK;
|
|
1155
|
+
}
|
|
1156
|
+
io.stderr.push("valid: no");
|
|
1157
|
+
io.stderr.push(`code: ${result.code}`);
|
|
1158
|
+
io.stderr.push(`message: ${result.message}`);
|
|
1159
|
+
return EXIT.INVALID;
|
|
1160
|
+
}
|
|
1161
|
+
function runSanitize(type, value, options, io = { stdout: [], stderr: [] }) {
|
|
1162
|
+
if (!isSanitizableType(type)) {
|
|
1163
|
+
io.stderr.push(`Unsupported sanitize type: ${type}`);
|
|
1164
|
+
return EXIT.USAGE;
|
|
1165
|
+
}
|
|
1166
|
+
const input = resolveInput17(value, options.file);
|
|
1167
|
+
if (input === null) {
|
|
1168
|
+
io.stderr.push("Missing value. Pass an argument or use --file.");
|
|
1169
|
+
return EXIT.USAGE;
|
|
1170
|
+
}
|
|
1171
|
+
const uf = options.uf?.toUpperCase();
|
|
1172
|
+
const result = sanitize(input, type, uf ? { uf } : {});
|
|
1173
|
+
return printSanitize(result, options, io);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
// src/commands/generate.ts
|
|
1177
|
+
import { generate, isGeneratableCardBrand } from "@br-validators/core";
|
|
1178
|
+
var GENERATABLE_TYPES = [
|
|
1179
|
+
"cpf",
|
|
1180
|
+
"cnpj",
|
|
1181
|
+
"cep",
|
|
1182
|
+
"placa",
|
|
1183
|
+
"pis-pasep",
|
|
1184
|
+
"renavam",
|
|
1185
|
+
"cnh",
|
|
1186
|
+
"telefone",
|
|
1187
|
+
"cartao-credito",
|
|
1188
|
+
"inscricao-estadual",
|
|
1189
|
+
"titulo-eleitor"
|
|
1190
|
+
];
|
|
1191
|
+
function isGeneratableType(type) {
|
|
1192
|
+
return GENERATABLE_TYPES.includes(type);
|
|
1193
|
+
}
|
|
1194
|
+
function buildGenerateOptions(options) {
|
|
1195
|
+
const core = {};
|
|
1196
|
+
if (options.masked) {
|
|
1197
|
+
core.masked = true;
|
|
1198
|
+
}
|
|
1199
|
+
if (options.seed !== void 0) {
|
|
1200
|
+
core.seed = options.seed;
|
|
1201
|
+
}
|
|
1202
|
+
if (options.format) {
|
|
1203
|
+
core.format = options.format;
|
|
1204
|
+
}
|
|
1205
|
+
if (options.uf) {
|
|
1206
|
+
core.uf = options.uf.toUpperCase();
|
|
1207
|
+
}
|
|
1208
|
+
if (options.brand && isGeneratableCardBrand(options.brand)) {
|
|
1209
|
+
core.brand = options.brand;
|
|
1210
|
+
}
|
|
1211
|
+
return core;
|
|
1212
|
+
}
|
|
1213
|
+
function printGenerate(value, options, io = { stdout: [], stderr: [] }) {
|
|
1214
|
+
if (options.json) {
|
|
1215
|
+
io.stdout.push(JSON.stringify({ ok: true, value }, null, 2));
|
|
1216
|
+
return EXIT.OK;
|
|
1217
|
+
}
|
|
1218
|
+
if (options.quiet) {
|
|
1219
|
+
return EXIT.OK;
|
|
1220
|
+
}
|
|
1221
|
+
io.stdout.push(value);
|
|
1222
|
+
return EXIT.OK;
|
|
1223
|
+
}
|
|
1224
|
+
function runGenerate(type, options, io = { stdout: [], stderr: [] }) {
|
|
1225
|
+
if (!isGeneratableType(type)) {
|
|
1226
|
+
io.stderr.push(`Unsupported generate type: ${type}`);
|
|
1227
|
+
return EXIT.USAGE;
|
|
1228
|
+
}
|
|
1229
|
+
const value = generate(type, buildGenerateOptions(options));
|
|
1230
|
+
return printGenerate(value, options, io);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
// src/commands/list.ts
|
|
1234
|
+
function listSupportedTypes(io = { stdout: [] }) {
|
|
1235
|
+
for (const type of SUPPORTED_TYPES) {
|
|
1236
|
+
io.stdout.push(type);
|
|
1237
|
+
}
|
|
1238
|
+
return 0;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// src/handlers.ts
|
|
1242
|
+
function readInputFile(path, io) {
|
|
1243
|
+
try {
|
|
1244
|
+
const fsModule = __require("fs");
|
|
1245
|
+
return fsModule.readFileSync(path, "utf8");
|
|
1246
|
+
} catch {
|
|
1247
|
+
io.stderr.push(`Cannot read file: ${path}`);
|
|
1248
|
+
return null;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function handleListCli(io = { stdout: [], stderr: [] }) {
|
|
1252
|
+
return listSupportedTypes(io);
|
|
1253
|
+
}
|
|
1254
|
+
function handleCnpjCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1255
|
+
let fileContent;
|
|
1256
|
+
if (opts.file) {
|
|
1257
|
+
const content = readInputFile(opts.file, io);
|
|
1258
|
+
if (content === null) {
|
|
1259
|
+
return EXIT.USAGE;
|
|
1260
|
+
}
|
|
1261
|
+
fileContent = content;
|
|
1262
|
+
}
|
|
1263
|
+
return runCnpj(
|
|
1264
|
+
action,
|
|
1265
|
+
value,
|
|
1266
|
+
{
|
|
1267
|
+
json: Boolean(opts.json),
|
|
1268
|
+
quiet: Boolean(opts.quiet),
|
|
1269
|
+
source: Boolean(opts.source),
|
|
1270
|
+
file: fileContent
|
|
1271
|
+
},
|
|
1272
|
+
io
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
function handleCpfCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1276
|
+
let fileContent;
|
|
1277
|
+
if (opts.file) {
|
|
1278
|
+
const content = readInputFile(opts.file, io);
|
|
1279
|
+
if (content === null) {
|
|
1280
|
+
return EXIT.USAGE;
|
|
1281
|
+
}
|
|
1282
|
+
fileContent = content;
|
|
1283
|
+
}
|
|
1284
|
+
return runCpf(
|
|
1285
|
+
action,
|
|
1286
|
+
value,
|
|
1287
|
+
{
|
|
1288
|
+
json: Boolean(opts.json),
|
|
1289
|
+
quiet: Boolean(opts.quiet),
|
|
1290
|
+
source: Boolean(opts.source),
|
|
1291
|
+
file: fileContent
|
|
1292
|
+
},
|
|
1293
|
+
io
|
|
1294
|
+
);
|
|
1295
|
+
}
|
|
1296
|
+
function handleCepCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1297
|
+
let fileContent;
|
|
1298
|
+
if (opts.file) {
|
|
1299
|
+
const content = readInputFile(opts.file, io);
|
|
1300
|
+
if (content === null) {
|
|
1301
|
+
return EXIT.USAGE;
|
|
1302
|
+
}
|
|
1303
|
+
fileContent = content;
|
|
1304
|
+
}
|
|
1305
|
+
return runCep(
|
|
1306
|
+
action,
|
|
1307
|
+
value,
|
|
1308
|
+
{
|
|
1309
|
+
json: Boolean(opts.json),
|
|
1310
|
+
quiet: Boolean(opts.quiet),
|
|
1311
|
+
source: Boolean(opts.source),
|
|
1312
|
+
file: fileContent
|
|
1313
|
+
},
|
|
1314
|
+
io
|
|
1315
|
+
);
|
|
1316
|
+
}
|
|
1317
|
+
function handleTelefoneCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1318
|
+
let fileContent;
|
|
1319
|
+
if (opts.file) {
|
|
1320
|
+
const content = readInputFile(opts.file, io);
|
|
1321
|
+
if (content === null) {
|
|
1322
|
+
return EXIT.USAGE;
|
|
1323
|
+
}
|
|
1324
|
+
fileContent = content;
|
|
1325
|
+
}
|
|
1326
|
+
return runTelefone(
|
|
1327
|
+
action,
|
|
1328
|
+
value,
|
|
1329
|
+
{
|
|
1330
|
+
json: Boolean(opts.json),
|
|
1331
|
+
quiet: Boolean(opts.quiet),
|
|
1332
|
+
source: Boolean(opts.source),
|
|
1333
|
+
file: fileContent
|
|
1334
|
+
},
|
|
1335
|
+
io
|
|
1336
|
+
);
|
|
1337
|
+
}
|
|
1338
|
+
function handleCnhCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1339
|
+
let fileContent;
|
|
1340
|
+
if (opts.file) {
|
|
1341
|
+
const content = readInputFile(opts.file, io);
|
|
1342
|
+
if (content === null) {
|
|
1343
|
+
return EXIT.USAGE;
|
|
1344
|
+
}
|
|
1345
|
+
fileContent = content;
|
|
1346
|
+
}
|
|
1347
|
+
return runCnh(
|
|
1348
|
+
action,
|
|
1349
|
+
value,
|
|
1350
|
+
{
|
|
1351
|
+
json: Boolean(opts.json),
|
|
1352
|
+
quiet: Boolean(opts.quiet),
|
|
1353
|
+
source: Boolean(opts.source),
|
|
1354
|
+
file: fileContent
|
|
1355
|
+
},
|
|
1356
|
+
io
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
function handlePlacaCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1360
|
+
let fileContent;
|
|
1361
|
+
if (opts.file) {
|
|
1362
|
+
const content = readInputFile(opts.file, io);
|
|
1363
|
+
if (content === null) {
|
|
1364
|
+
return EXIT.USAGE;
|
|
1365
|
+
}
|
|
1366
|
+
fileContent = content;
|
|
1367
|
+
}
|
|
1368
|
+
return runPlaca(
|
|
1369
|
+
action,
|
|
1370
|
+
value,
|
|
1371
|
+
{
|
|
1372
|
+
json: Boolean(opts.json),
|
|
1373
|
+
quiet: Boolean(opts.quiet),
|
|
1374
|
+
source: Boolean(opts.source),
|
|
1375
|
+
file: fileContent
|
|
1376
|
+
},
|
|
1377
|
+
io
|
|
1378
|
+
);
|
|
1379
|
+
}
|
|
1380
|
+
function handlePisPasepCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1381
|
+
let fileContent;
|
|
1382
|
+
if (opts.file) {
|
|
1383
|
+
const content = readInputFile(opts.file, io);
|
|
1384
|
+
if (content === null) {
|
|
1385
|
+
return EXIT.USAGE;
|
|
1386
|
+
}
|
|
1387
|
+
fileContent = content;
|
|
1388
|
+
}
|
|
1389
|
+
return runPisPasep(
|
|
1390
|
+
action,
|
|
1391
|
+
value,
|
|
1392
|
+
{
|
|
1393
|
+
json: Boolean(opts.json),
|
|
1394
|
+
quiet: Boolean(opts.quiet),
|
|
1395
|
+
source: Boolean(opts.source),
|
|
1396
|
+
file: fileContent
|
|
1397
|
+
},
|
|
1398
|
+
io
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
function handlePixCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1402
|
+
let fileContent;
|
|
1403
|
+
if (opts.file) {
|
|
1404
|
+
const content = readInputFile(opts.file, io);
|
|
1405
|
+
if (content === null) {
|
|
1406
|
+
return EXIT.USAGE;
|
|
1407
|
+
}
|
|
1408
|
+
fileContent = content;
|
|
1409
|
+
}
|
|
1410
|
+
return runPix(
|
|
1411
|
+
action,
|
|
1412
|
+
value,
|
|
1413
|
+
{
|
|
1414
|
+
json: Boolean(opts.json),
|
|
1415
|
+
quiet: Boolean(opts.quiet),
|
|
1416
|
+
source: Boolean(opts.source),
|
|
1417
|
+
type: opts.type,
|
|
1418
|
+
file: fileContent
|
|
1419
|
+
},
|
|
1420
|
+
io
|
|
1421
|
+
);
|
|
1422
|
+
}
|
|
1423
|
+
function handleBoletoCli(action, value, opts, direction, io = { stdout: [], stderr: [] }) {
|
|
1424
|
+
let fileContent;
|
|
1425
|
+
if (opts.file) {
|
|
1426
|
+
const content = readInputFile(opts.file, io);
|
|
1427
|
+
if (content === null) {
|
|
1428
|
+
return EXIT.USAGE;
|
|
1429
|
+
}
|
|
1430
|
+
fileContent = content;
|
|
1431
|
+
}
|
|
1432
|
+
return runBoleto(
|
|
1433
|
+
action,
|
|
1434
|
+
value,
|
|
1435
|
+
{
|
|
1436
|
+
json: Boolean(opts.json),
|
|
1437
|
+
quiet: Boolean(opts.quiet),
|
|
1438
|
+
source: Boolean(opts.source),
|
|
1439
|
+
kind: opts.kind,
|
|
1440
|
+
file: fileContent
|
|
1441
|
+
},
|
|
1442
|
+
direction,
|
|
1443
|
+
io
|
|
1444
|
+
);
|
|
1445
|
+
}
|
|
1446
|
+
function handleCartaoCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1447
|
+
let fileContent;
|
|
1448
|
+
if (opts.file) {
|
|
1449
|
+
const content = readInputFile(opts.file, io);
|
|
1450
|
+
if (content === null) {
|
|
1451
|
+
return EXIT.USAGE;
|
|
1452
|
+
}
|
|
1453
|
+
fileContent = content;
|
|
1454
|
+
}
|
|
1455
|
+
return runCartao(
|
|
1456
|
+
action,
|
|
1457
|
+
value,
|
|
1458
|
+
{
|
|
1459
|
+
json: Boolean(opts.json),
|
|
1460
|
+
quiet: Boolean(opts.quiet),
|
|
1461
|
+
source: Boolean(opts.source),
|
|
1462
|
+
file: fileContent
|
|
1463
|
+
},
|
|
1464
|
+
io
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
function handleCartaoCreditoCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1468
|
+
let fileContent;
|
|
1469
|
+
if (opts.file) {
|
|
1470
|
+
const content = readInputFile(opts.file, io);
|
|
1471
|
+
if (content === null) {
|
|
1472
|
+
return EXIT.USAGE;
|
|
1473
|
+
}
|
|
1474
|
+
fileContent = content;
|
|
1475
|
+
}
|
|
1476
|
+
return runCartao(
|
|
1477
|
+
action,
|
|
1478
|
+
value,
|
|
1479
|
+
{
|
|
1480
|
+
json: Boolean(opts.json),
|
|
1481
|
+
quiet: Boolean(opts.quiet),
|
|
1482
|
+
source: Boolean(opts.source),
|
|
1483
|
+
file: fileContent
|
|
1484
|
+
},
|
|
1485
|
+
io
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
function handleRenavamCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1489
|
+
let fileContent;
|
|
1490
|
+
if (opts.file) {
|
|
1491
|
+
const content = readInputFile(opts.file, io);
|
|
1492
|
+
if (content === null) {
|
|
1493
|
+
return EXIT.USAGE;
|
|
1494
|
+
}
|
|
1495
|
+
fileContent = content;
|
|
1496
|
+
}
|
|
1497
|
+
return runRenavam(
|
|
1498
|
+
action,
|
|
1499
|
+
value,
|
|
1500
|
+
{
|
|
1501
|
+
json: Boolean(opts.json),
|
|
1502
|
+
quiet: Boolean(opts.quiet),
|
|
1503
|
+
source: Boolean(opts.source),
|
|
1504
|
+
file: fileContent
|
|
1505
|
+
},
|
|
1506
|
+
io
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
function handleTituloEleitorCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1510
|
+
let fileContent;
|
|
1511
|
+
if (opts.file) {
|
|
1512
|
+
const content = readInputFile(opts.file, io);
|
|
1513
|
+
if (content === null) {
|
|
1514
|
+
return EXIT.USAGE;
|
|
1515
|
+
}
|
|
1516
|
+
fileContent = content;
|
|
1517
|
+
}
|
|
1518
|
+
return runTituloEleitor(
|
|
1519
|
+
action,
|
|
1520
|
+
value,
|
|
1521
|
+
{
|
|
1522
|
+
json: Boolean(opts.json),
|
|
1523
|
+
quiet: Boolean(opts.quiet),
|
|
1524
|
+
source: Boolean(opts.source),
|
|
1525
|
+
file: fileContent
|
|
1526
|
+
},
|
|
1527
|
+
io
|
|
1528
|
+
);
|
|
1529
|
+
}
|
|
1530
|
+
function handleNfeChaveCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1531
|
+
let fileContent;
|
|
1532
|
+
if (opts.file) {
|
|
1533
|
+
const content = readInputFile(opts.file, io);
|
|
1534
|
+
if (content === null) {
|
|
1535
|
+
return EXIT.USAGE;
|
|
1536
|
+
}
|
|
1537
|
+
fileContent = content;
|
|
1538
|
+
}
|
|
1539
|
+
return runNfeChave(
|
|
1540
|
+
action,
|
|
1541
|
+
value,
|
|
1542
|
+
{
|
|
1543
|
+
json: Boolean(opts.json),
|
|
1544
|
+
quiet: Boolean(opts.quiet),
|
|
1545
|
+
source: Boolean(opts.source),
|
|
1546
|
+
file: fileContent
|
|
1547
|
+
},
|
|
1548
|
+
io
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
function handleBrCodeCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1552
|
+
let fileContent;
|
|
1553
|
+
if (opts.file) {
|
|
1554
|
+
const content = readInputFile(opts.file, io);
|
|
1555
|
+
if (content === null) {
|
|
1556
|
+
return EXIT.USAGE;
|
|
1557
|
+
}
|
|
1558
|
+
fileContent = content;
|
|
1559
|
+
}
|
|
1560
|
+
return runBrCode(
|
|
1561
|
+
action,
|
|
1562
|
+
value,
|
|
1563
|
+
{
|
|
1564
|
+
json: Boolean(opts.json),
|
|
1565
|
+
quiet: Boolean(opts.quiet),
|
|
1566
|
+
source: Boolean(opts.source),
|
|
1567
|
+
file: fileContent
|
|
1568
|
+
},
|
|
1569
|
+
io
|
|
1570
|
+
);
|
|
1571
|
+
}
|
|
1572
|
+
function handleIeCli(action, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1573
|
+
let fileContent;
|
|
1574
|
+
if (opts.file) {
|
|
1575
|
+
const content = readInputFile(opts.file, io);
|
|
1576
|
+
if (content === null) {
|
|
1577
|
+
return EXIT.USAGE;
|
|
1578
|
+
}
|
|
1579
|
+
fileContent = content;
|
|
1580
|
+
}
|
|
1581
|
+
return runIe(
|
|
1582
|
+
action,
|
|
1583
|
+
value,
|
|
1584
|
+
{
|
|
1585
|
+
json: Boolean(opts.json),
|
|
1586
|
+
quiet: Boolean(opts.quiet),
|
|
1587
|
+
source: Boolean(opts.source),
|
|
1588
|
+
uf: opts.uf,
|
|
1589
|
+
file: fileContent
|
|
1590
|
+
},
|
|
1591
|
+
io
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
function handleDetectCli(value, opts, io = { stdout: [], stderr: [] }) {
|
|
1595
|
+
let fileContent;
|
|
1596
|
+
if (opts.file) {
|
|
1597
|
+
const content = readInputFile(opts.file, io);
|
|
1598
|
+
if (content === null) {
|
|
1599
|
+
return EXIT.USAGE;
|
|
1600
|
+
}
|
|
1601
|
+
fileContent = content;
|
|
1602
|
+
}
|
|
1603
|
+
return runDetect(
|
|
1604
|
+
value,
|
|
1605
|
+
{
|
|
1606
|
+
json: Boolean(opts.json),
|
|
1607
|
+
quiet: Boolean(opts.quiet),
|
|
1608
|
+
uf: opts.uf,
|
|
1609
|
+
file: fileContent
|
|
1610
|
+
},
|
|
1611
|
+
io
|
|
1612
|
+
);
|
|
1613
|
+
}
|
|
1614
|
+
function handleSanitizeCli(type, value, opts, io = { stdout: [], stderr: [] }) {
|
|
1615
|
+
let fileContent;
|
|
1616
|
+
if (opts.file) {
|
|
1617
|
+
const content = readInputFile(opts.file, io);
|
|
1618
|
+
if (content === null) {
|
|
1619
|
+
return EXIT.USAGE;
|
|
1620
|
+
}
|
|
1621
|
+
fileContent = content;
|
|
1622
|
+
}
|
|
1623
|
+
return runSanitize(
|
|
1624
|
+
type,
|
|
1625
|
+
value,
|
|
1626
|
+
{
|
|
1627
|
+
json: Boolean(opts.json),
|
|
1628
|
+
quiet: Boolean(opts.quiet),
|
|
1629
|
+
uf: opts.uf,
|
|
1630
|
+
file: fileContent
|
|
1631
|
+
},
|
|
1632
|
+
io
|
|
1633
|
+
);
|
|
1634
|
+
}
|
|
1635
|
+
function handleGenerateCli(type, opts, io = { stdout: [], stderr: [] }) {
|
|
1636
|
+
return runGenerate(
|
|
1637
|
+
type,
|
|
1638
|
+
{
|
|
1639
|
+
json: Boolean(opts.json),
|
|
1640
|
+
quiet: Boolean(opts.quiet),
|
|
1641
|
+
masked: Boolean(opts.masked),
|
|
1642
|
+
format: opts.format,
|
|
1643
|
+
seed: opts.seed,
|
|
1644
|
+
uf: opts.uf,
|
|
1645
|
+
brand: opts.brand
|
|
1646
|
+
},
|
|
1647
|
+
io
|
|
1648
|
+
);
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
// src/argv-dispatch.ts
|
|
1652
|
+
var STANDARD_ACTIONS = ["validate", "format", "strip"];
|
|
1653
|
+
var NFE_ACTIONS = ["validate", "parse", "format", "strip"];
|
|
1654
|
+
var BRCODE_ACTIONS = ["parse", "validate"];
|
|
1655
|
+
var PLACA_ACTIONS = ["validate", "format", "strip", "convert"];
|
|
1656
|
+
var PIX_ACTIONS = ["detect", "validate", "format"];
|
|
1657
|
+
var BOLETO_CONVERT = ["linha-to-barras", "barras-to-linha"];
|
|
1658
|
+
function usage(io, message) {
|
|
1659
|
+
io.stderr.push(message);
|
|
1660
|
+
return EXIT.USAGE;
|
|
1661
|
+
}
|
|
1662
|
+
function parseArgv(tokens) {
|
|
1663
|
+
const positionals = [];
|
|
1664
|
+
const opts = {};
|
|
1665
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
1666
|
+
const token = tokens[index];
|
|
1667
|
+
if (token === "--json") {
|
|
1668
|
+
opts.json = true;
|
|
1669
|
+
continue;
|
|
1670
|
+
}
|
|
1671
|
+
if (token === "-q" || token === "--quiet") {
|
|
1672
|
+
opts.quiet = true;
|
|
1673
|
+
continue;
|
|
1674
|
+
}
|
|
1675
|
+
if (token === "--source") {
|
|
1676
|
+
opts.source = true;
|
|
1677
|
+
continue;
|
|
1678
|
+
}
|
|
1679
|
+
if (token === "--masked") {
|
|
1680
|
+
opts.masked = true;
|
|
1681
|
+
continue;
|
|
1682
|
+
}
|
|
1683
|
+
if (token === "-f" || token === "--file") {
|
|
1684
|
+
opts.file = tokens[index + 1];
|
|
1685
|
+
index += 1;
|
|
1686
|
+
continue;
|
|
1687
|
+
}
|
|
1688
|
+
if (token === "--uf") {
|
|
1689
|
+
opts.uf = tokens[index + 1];
|
|
1690
|
+
index += 1;
|
|
1691
|
+
continue;
|
|
1692
|
+
}
|
|
1693
|
+
if (token === "--format") {
|
|
1694
|
+
opts.format = tokens[index + 1];
|
|
1695
|
+
index += 1;
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1698
|
+
if (token === "--seed") {
|
|
1699
|
+
opts.seed = Number(tokens[index + 1]);
|
|
1700
|
+
index += 1;
|
|
1701
|
+
continue;
|
|
1702
|
+
}
|
|
1703
|
+
if (token === "--kind") {
|
|
1704
|
+
opts.kind = tokens[index + 1];
|
|
1705
|
+
index += 1;
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1708
|
+
if (token === "--type") {
|
|
1709
|
+
opts.type = tokens[index + 1];
|
|
1710
|
+
index += 1;
|
|
1711
|
+
continue;
|
|
1712
|
+
}
|
|
1713
|
+
if (token.startsWith("-")) {
|
|
1714
|
+
continue;
|
|
1715
|
+
}
|
|
1716
|
+
positionals.push(token);
|
|
1717
|
+
}
|
|
1718
|
+
return { positionals, opts };
|
|
1719
|
+
}
|
|
1720
|
+
function pickValue(rest) {
|
|
1721
|
+
return rest.slice(1).join(" ") || void 0;
|
|
1722
|
+
}
|
|
1723
|
+
function dispatchStandard(rest, opts, io, handler) {
|
|
1724
|
+
const action = rest[0];
|
|
1725
|
+
if (!action || !STANDARD_ACTIONS.includes(action)) {
|
|
1726
|
+
return usage(io, "Expected action: validate | format | strip");
|
|
1727
|
+
}
|
|
1728
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
1729
|
+
return handler(action, value, opts, io);
|
|
1730
|
+
}
|
|
1731
|
+
function dispatchArgv(tokens, io) {
|
|
1732
|
+
if (tokens.length === 0 || tokens.includes("--help") || tokens.includes("-h")) {
|
|
1733
|
+
io.stdout.push("br-validators \u2014 100% open-source Brazilian document validators");
|
|
1734
|
+
io.stdout.push("Usage: br-validators <command> ...");
|
|
1735
|
+
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");
|
|
1736
|
+
return EXIT.OK;
|
|
1737
|
+
}
|
|
1738
|
+
if (tokens.includes("--version") || tokens.includes("-V")) {
|
|
1739
|
+
io.stdout.push("0.12.0-alpha.1");
|
|
1740
|
+
return EXIT.OK;
|
|
1741
|
+
}
|
|
1742
|
+
const { positionals, opts } = parseArgv(tokens);
|
|
1743
|
+
const [root, ...rest] = positionals;
|
|
1744
|
+
if (!root) {
|
|
1745
|
+
return usage(io, "Missing command");
|
|
1746
|
+
}
|
|
1747
|
+
switch (root) {
|
|
1748
|
+
case "list":
|
|
1749
|
+
return handleListCli(io);
|
|
1750
|
+
case "cnpj":
|
|
1751
|
+
return dispatchStandard(rest, opts, io, handleCnpjCli);
|
|
1752
|
+
case "cpf":
|
|
1753
|
+
return dispatchStandard(rest, opts, io, handleCpfCli);
|
|
1754
|
+
case "cep":
|
|
1755
|
+
return dispatchStandard(rest, opts, io, handleCepCli);
|
|
1756
|
+
case "telefone":
|
|
1757
|
+
return dispatchStandard(rest, opts, io, handleTelefoneCli);
|
|
1758
|
+
case "cnh":
|
|
1759
|
+
return dispatchStandard(rest, opts, io, handleCnhCli);
|
|
1760
|
+
case "renavam":
|
|
1761
|
+
return dispatchStandard(rest, opts, io, handleRenavamCli);
|
|
1762
|
+
case "titulo-eleitor":
|
|
1763
|
+
return dispatchStandard(rest, opts, io, handleTituloEleitorCli);
|
|
1764
|
+
case "nfe-chave": {
|
|
1765
|
+
const action = rest[0];
|
|
1766
|
+
if (!action || !NFE_ACTIONS.includes(action)) {
|
|
1767
|
+
return usage(io, "Expected action: validate | parse | format | strip");
|
|
1768
|
+
}
|
|
1769
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
1770
|
+
return handleNfeChaveCli(action, value, opts, io);
|
|
1771
|
+
}
|
|
1772
|
+
case "brcode": {
|
|
1773
|
+
const action = rest[0];
|
|
1774
|
+
if (!action || !BRCODE_ACTIONS.includes(action)) {
|
|
1775
|
+
return usage(io, "Expected action: parse | validate");
|
|
1776
|
+
}
|
|
1777
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
1778
|
+
return handleBrCodeCli(action, value, opts, io);
|
|
1779
|
+
}
|
|
1780
|
+
case "placa": {
|
|
1781
|
+
const action = rest[0];
|
|
1782
|
+
if (!action || !PLACA_ACTIONS.includes(action)) {
|
|
1783
|
+
return usage(io, "Expected action: validate | format | strip | convert");
|
|
1784
|
+
}
|
|
1785
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
1786
|
+
return handlePlacaCli(action, value, opts, io);
|
|
1787
|
+
}
|
|
1788
|
+
case "pis-pasep":
|
|
1789
|
+
return dispatchStandard(rest, opts, io, handlePisPasepCli);
|
|
1790
|
+
case "pix": {
|
|
1791
|
+
const action = rest[0];
|
|
1792
|
+
if (!action || !PIX_ACTIONS.includes(action)) {
|
|
1793
|
+
return usage(io, "Expected action: detect | validate | format");
|
|
1794
|
+
}
|
|
1795
|
+
const value = rest.slice(1).join(" ") || void 0;
|
|
1796
|
+
return handlePixCli(action, value, opts, io);
|
|
1797
|
+
}
|
|
1798
|
+
case "boleto": {
|
|
1799
|
+
const action = rest[0];
|
|
1800
|
+
if (action === "convert") {
|
|
1801
|
+
const direction = rest[1];
|
|
1802
|
+
if (!direction || !BOLETO_CONVERT.includes(direction)) {
|
|
1803
|
+
return usage(io, "Expected: boleto convert linha-to-barras|barras-to-linha <value>");
|
|
1804
|
+
}
|
|
1805
|
+
const value2 = rest.slice(2).join(" ") || void 0;
|
|
1806
|
+
return handleBoletoCli("convert", value2, opts, direction, io);
|
|
1807
|
+
}
|
|
1808
|
+
if (!action || !["detect", "validate", "format", "strip"].includes(action)) {
|
|
1809
|
+
return usage(io, "Expected action: detect | validate | format | strip | convert");
|
|
1810
|
+
}
|
|
1811
|
+
const value = pickValue(rest);
|
|
1812
|
+
return handleBoletoCli(
|
|
1813
|
+
action,
|
|
1814
|
+
value,
|
|
1815
|
+
opts,
|
|
1816
|
+
void 0,
|
|
1817
|
+
io
|
|
1818
|
+
);
|
|
1819
|
+
}
|
|
1820
|
+
case "cartao": {
|
|
1821
|
+
const action = rest[0];
|
|
1822
|
+
if (!action || !["detect", "validate", "format", "strip"].includes(action)) {
|
|
1823
|
+
return usage(io, "Expected action: detect | validate | format | strip");
|
|
1824
|
+
}
|
|
1825
|
+
const value = pickValue(rest);
|
|
1826
|
+
return handleCartaoCli(action, value, opts, io);
|
|
1827
|
+
}
|
|
1828
|
+
case "cartao-credito":
|
|
1829
|
+
return dispatchStandard(rest, opts, io, handleCartaoCreditoCli);
|
|
1830
|
+
case "ie":
|
|
1831
|
+
return dispatchStandard(
|
|
1832
|
+
rest,
|
|
1833
|
+
opts,
|
|
1834
|
+
io,
|
|
1835
|
+
(action, value, ieOpts, ioArg) => handleIeCli(action, value, ieOpts, ioArg)
|
|
1836
|
+
);
|
|
1837
|
+
case "detect":
|
|
1838
|
+
return handleDetectCli(rest.join(" ") || void 0, opts, io);
|
|
1839
|
+
case "sanitize":
|
|
1840
|
+
return handleSanitizeCli(rest[0] ?? "", rest.slice(1).join(" ") || void 0, opts, io);
|
|
1841
|
+
case "generate":
|
|
1842
|
+
return handleGenerateCli(rest[0] ?? "", opts, io);
|
|
1843
|
+
default:
|
|
1844
|
+
return usage(io, `Unknown command: ${root}`);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// src/run-captured.ts
|
|
1849
|
+
function runCaptured(argv) {
|
|
1850
|
+
const io = { stdout: [], stderr: [] };
|
|
1851
|
+
const tokens = argv[0] === "node" ? argv.slice(2) : argv[0] === "br-validators" ? argv.slice(1) : argv;
|
|
1852
|
+
const exitCode = dispatchArgv(tokens, io);
|
|
1853
|
+
return {
|
|
1854
|
+
exitCode,
|
|
1855
|
+
stdout: io.stdout.join("\n"),
|
|
1856
|
+
stderr: io.stderr.join("\n")
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
export {
|
|
1860
|
+
runCaptured
|
|
1861
|
+
};
|