@qodalis/cli-encode 2.0.0-beta.7

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/public-api.mjs ADDED
@@ -0,0 +1,961 @@
1
+ import { DefaultLibraryAuthor, CliForegroundColor } from '@qodalis/cli-core';
2
+
3
+ // src/lib/processors/cli-base64-command-processor.ts
4
+ var CliBase64CommandProcessor = class {
5
+ constructor() {
6
+ this.command = "base64";
7
+ this.aliases = ["b64"];
8
+ this.description = "Encode or decode Base64 strings";
9
+ this.author = DefaultLibraryAuthor;
10
+ this.processors = [];
11
+ this.metadata = {
12
+ icon: "\u{1F523}",
13
+ module: "misc"
14
+ };
15
+ this.processors = [
16
+ {
17
+ command: "encode",
18
+ aliases: ["enc", "e"],
19
+ description: "Encode text to Base64",
20
+ acceptsRawInput: true,
21
+ valueRequired: true,
22
+ processCommand: async (command, context) => {
23
+ const text = command.value || command.data || "";
24
+ const encoded = btoa(
25
+ new TextEncoder().encode(text).reduce(
26
+ (data, byte) => data + String.fromCharCode(byte),
27
+ ""
28
+ )
29
+ );
30
+ context.writer.writeln(encoded);
31
+ context.process.output(encoded);
32
+ },
33
+ writeDescription: (context) => {
34
+ const { writer } = context;
35
+ writer.writeln("Encode text to Base64 format");
36
+ writer.writeln();
37
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
38
+ writer.writeln(
39
+ ` ${writer.wrapInColor("base64 encode <text>", CliForegroundColor.Cyan)}`
40
+ );
41
+ writer.writeln();
42
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
43
+ writer.writeln(
44
+ ` base64 encode Hello World ${writer.wrapInColor("# \u2192 SGVsbG8gV29ybGQ=", CliForegroundColor.Green)}`
45
+ );
46
+ }
47
+ },
48
+ {
49
+ command: "decode",
50
+ aliases: ["dec", "d"],
51
+ description: "Decode a Base64 string",
52
+ acceptsRawInput: true,
53
+ valueRequired: true,
54
+ processCommand: async (command, context) => {
55
+ const encoded = command.value || command.data || "";
56
+ try {
57
+ const bytes = Uint8Array.from(
58
+ atob(encoded),
59
+ (c) => c.charCodeAt(0)
60
+ );
61
+ const decoded = new TextDecoder().decode(bytes);
62
+ context.writer.writeln(decoded);
63
+ context.process.output(decoded);
64
+ } catch {
65
+ context.writer.writeError("Invalid Base64 string");
66
+ context.process.exit(-1);
67
+ }
68
+ },
69
+ writeDescription: (context) => {
70
+ const { writer } = context;
71
+ writer.writeln("Decode a Base64 string back to text");
72
+ writer.writeln();
73
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
74
+ writer.writeln(
75
+ ` ${writer.wrapInColor("base64 decode <base64>", CliForegroundColor.Cyan)}`
76
+ );
77
+ writer.writeln();
78
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
79
+ writer.writeln(
80
+ ` base64 decode SGVsbG8gV29ybGQ= ${writer.wrapInColor("# \u2192 Hello World", CliForegroundColor.Green)}`
81
+ );
82
+ }
83
+ }
84
+ ];
85
+ }
86
+ async processCommand(command, context) {
87
+ context.executor.showHelp(command, context);
88
+ }
89
+ writeDescription(context) {
90
+ const { writer, translator: t } = context;
91
+ writer.writeln(t.t("cli.base64.long_description", "Encode and decode Base64 strings"));
92
+ writer.writeln(t.t("cli.base64.utf8_note", "Supports UTF-8 text encoding"));
93
+ writer.writeln();
94
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
95
+ writer.writeln(
96
+ ` ${writer.wrapInColor("base64 encode <text>", CliForegroundColor.Cyan)} ${t.t("cli.base64.encode_desc", "Encode text to Base64")}`
97
+ );
98
+ writer.writeln(
99
+ ` ${writer.wrapInColor("base64 decode <base64>", CliForegroundColor.Cyan)} ${t.t("cli.base64.decode_desc", "Decode Base64 to text")}`
100
+ );
101
+ }
102
+ };
103
+ var CliHexCommandProcessor = class {
104
+ constructor() {
105
+ this.command = "hex";
106
+ this.description = "Hex encode/decode and number base conversions";
107
+ this.author = DefaultLibraryAuthor;
108
+ this.processors = [];
109
+ this.metadata = {
110
+ icon: "0\uFE0F\u20E3",
111
+ module: "misc"
112
+ };
113
+ this.processors = [
114
+ {
115
+ command: "encode",
116
+ aliases: ["enc"],
117
+ description: "Encode text to hexadecimal",
118
+ acceptsRawInput: true,
119
+ valueRequired: true,
120
+ processCommand: async (command, context) => {
121
+ const text = command.value || command.data || "";
122
+ const hex = Array.from(new TextEncoder().encode(text)).map((b) => b.toString(16).padStart(2, "0")).join("");
123
+ context.writer.writeln(hex);
124
+ context.process.output(hex);
125
+ },
126
+ writeDescription: (context) => {
127
+ const { writer } = context;
128
+ writer.writeln("Encode text to hexadecimal representation");
129
+ writer.writeln();
130
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
131
+ writer.writeln(
132
+ ` ${writer.wrapInColor("hex encode <text>", CliForegroundColor.Cyan)}`
133
+ );
134
+ }
135
+ },
136
+ {
137
+ command: "decode",
138
+ aliases: ["dec"],
139
+ description: "Decode hexadecimal to text",
140
+ acceptsRawInput: true,
141
+ valueRequired: true,
142
+ processCommand: async (command, context) => {
143
+ const hexStr = command.value || command.data || "";
144
+ try {
145
+ const bytes = new Uint8Array(
146
+ (hexStr.match(/.{1,2}/g) || []).map(
147
+ (byte) => parseInt(byte, 16)
148
+ )
149
+ );
150
+ const text = new TextDecoder().decode(bytes);
151
+ context.writer.writeln(text);
152
+ context.process.output(text);
153
+ } catch {
154
+ context.writer.writeError("Invalid hex string");
155
+ context.process.exit(-1);
156
+ }
157
+ },
158
+ writeDescription: (context) => {
159
+ const { writer } = context;
160
+ writer.writeln("Decode hexadecimal back to text");
161
+ writer.writeln();
162
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
163
+ writer.writeln(
164
+ ` ${writer.wrapInColor("hex decode <hex>", CliForegroundColor.Cyan)}`
165
+ );
166
+ }
167
+ },
168
+ {
169
+ command: "convert",
170
+ aliases: ["conv"],
171
+ description: "Convert a number between bases",
172
+ acceptsRawInput: true,
173
+ valueRequired: true,
174
+ parameters: [
175
+ {
176
+ name: "from",
177
+ description: "Source base (default: 10)",
178
+ type: "number",
179
+ required: false
180
+ },
181
+ {
182
+ name: "to",
183
+ description: "Target base (default: 16)",
184
+ type: "number",
185
+ required: false
186
+ }
187
+ ],
188
+ processCommand: async (command, context) => {
189
+ const { writer } = context;
190
+ const input = command.value || "";
191
+ const fromBase = parseInt(command.args["from"]) || 10;
192
+ const toBase = parseInt(command.args["to"]) || 16;
193
+ if (fromBase < 2 || fromBase > 36 || toBase < 2 || toBase > 36) {
194
+ writer.writeError("Base must be between 2 and 36");
195
+ context.process.exit(-1);
196
+ return;
197
+ }
198
+ try {
199
+ const num = parseInt(input, fromBase);
200
+ if (isNaN(num)) {
201
+ writer.writeError(
202
+ `Invalid number for base ${fromBase}`
203
+ );
204
+ context.process.exit(-1);
205
+ return;
206
+ }
207
+ const result = num.toString(toBase);
208
+ writer.writeln(
209
+ ` ${writer.wrapInColor(`Base ${fromBase}:`, CliForegroundColor.Cyan)} ${input}`
210
+ );
211
+ writer.writeln(
212
+ ` ${writer.wrapInColor(`Base ${toBase}:`, CliForegroundColor.Cyan)} ${result}`
213
+ );
214
+ if (fromBase !== 10 && toBase !== 10) {
215
+ writer.writeln(
216
+ ` ${writer.wrapInColor("Base 10:", CliForegroundColor.Cyan)} ${num}`
217
+ );
218
+ }
219
+ context.process.output(result);
220
+ } catch {
221
+ writer.writeError("Conversion failed");
222
+ context.process.exit(-1);
223
+ }
224
+ },
225
+ writeDescription: (context) => {
226
+ const { writer } = context;
227
+ writer.writeln(
228
+ "Convert a number between different bases (2-36)"
229
+ );
230
+ writer.writeln();
231
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
232
+ writer.writeln(
233
+ ` ${writer.wrapInColor("hex convert <number> [--from=N] [--to=N]", CliForegroundColor.Cyan)}`
234
+ );
235
+ writer.writeln();
236
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
237
+ writer.writeln(
238
+ ` hex convert 255 ${writer.wrapInColor("# Decimal \u2192 Hex (ff)", CliForegroundColor.Green)}`
239
+ );
240
+ writer.writeln(
241
+ ` hex convert ff --from=16 --to=2 ${writer.wrapInColor("# Hex \u2192 Binary (11111111)", CliForegroundColor.Green)}`
242
+ );
243
+ writer.writeln(
244
+ ` hex convert 1010 --from=2 ${writer.wrapInColor("# Binary \u2192 Hex (a)", CliForegroundColor.Green)}`
245
+ );
246
+ }
247
+ }
248
+ ];
249
+ }
250
+ async processCommand(command, context) {
251
+ context.executor.showHelp(command, context);
252
+ }
253
+ writeDescription(context) {
254
+ const { writer, translator: t } = context;
255
+ writer.writeln(
256
+ t.t("cli.hex.long_description", "Hex encode/decode text and convert numbers between bases")
257
+ );
258
+ writer.writeln();
259
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
260
+ writer.writeln(
261
+ ` ${writer.wrapInColor("hex encode <text>", CliForegroundColor.Cyan)} ${t.t("cli.hex.text_to_hex", "Text to hex")}`
262
+ );
263
+ writer.writeln(
264
+ ` ${writer.wrapInColor("hex decode <hex>", CliForegroundColor.Cyan)} ${t.t("cli.hex.hex_to_text", "Hex to text")}`
265
+ );
266
+ writer.writeln(
267
+ ` ${writer.wrapInColor("hex convert <num> [--from --to]", CliForegroundColor.Cyan)} ${t.t("cli.hex.base_conversion", "Base conversion")}`
268
+ );
269
+ }
270
+ };
271
+ var CliUrlCommandProcessor = class {
272
+ constructor() {
273
+ this.command = "url";
274
+ this.description = "Encode or decode URLs";
275
+ this.author = DefaultLibraryAuthor;
276
+ this.processors = [];
277
+ this.metadata = {
278
+ icon: "\u{1F517}",
279
+ module: "misc"
280
+ };
281
+ this.processors = [
282
+ {
283
+ command: "encode",
284
+ aliases: ["enc"],
285
+ description: "URL-encode a string",
286
+ acceptsRawInput: true,
287
+ valueRequired: true,
288
+ processCommand: async (command, context) => {
289
+ const text = command.value || command.data || "";
290
+ const encoded = encodeURIComponent(text);
291
+ context.writer.writeln(encoded);
292
+ context.process.output(encoded);
293
+ },
294
+ writeDescription: (context) => {
295
+ const { writer } = context;
296
+ writer.writeln("URL-encode a string");
297
+ writer.writeln();
298
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
299
+ writer.writeln(
300
+ ` ${writer.wrapInColor("url encode <text>", CliForegroundColor.Cyan)}`
301
+ );
302
+ writer.writeln();
303
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
304
+ writer.writeln(
305
+ ` url encode hello world ${writer.wrapInColor("# \u2192 hello%20world", CliForegroundColor.Green)}`
306
+ );
307
+ }
308
+ },
309
+ {
310
+ command: "decode",
311
+ aliases: ["dec"],
312
+ description: "URL-decode a string",
313
+ acceptsRawInput: true,
314
+ valueRequired: true,
315
+ processCommand: async (command, context) => {
316
+ const text = command.value || command.data || "";
317
+ try {
318
+ const decoded = decodeURIComponent(text);
319
+ context.writer.writeln(decoded);
320
+ context.process.output(decoded);
321
+ } catch {
322
+ context.writer.writeError("Invalid URL-encoded string");
323
+ context.process.exit(-1);
324
+ }
325
+ },
326
+ writeDescription: (context) => {
327
+ const { writer } = context;
328
+ writer.writeln("URL-decode a string");
329
+ writer.writeln();
330
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
331
+ writer.writeln(
332
+ ` ${writer.wrapInColor("url decode <text>", CliForegroundColor.Cyan)}`
333
+ );
334
+ writer.writeln();
335
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
336
+ writer.writeln(
337
+ ` url decode hello%20world ${writer.wrapInColor("# \u2192 hello world", CliForegroundColor.Green)}`
338
+ );
339
+ }
340
+ },
341
+ {
342
+ command: "parse",
343
+ description: "Parse a URL into its components",
344
+ acceptsRawInput: true,
345
+ valueRequired: true,
346
+ processCommand: async (command, context) => {
347
+ const input = command.value || command.data || "";
348
+ try {
349
+ const url = new URL(input);
350
+ const parts = {
351
+ protocol: url.protocol,
352
+ hostname: url.hostname,
353
+ port: url.port || "(default)",
354
+ pathname: url.pathname,
355
+ search: url.search || "(none)",
356
+ hash: url.hash || "(none)",
357
+ origin: url.origin
358
+ };
359
+ const { writer } = context;
360
+ Object.entries(parts).forEach(([key, value]) => {
361
+ writer.writeln(
362
+ ` ${writer.wrapInColor(key.padEnd(12), CliForegroundColor.Cyan)} ${value}`
363
+ );
364
+ });
365
+ context.process.output(parts);
366
+ } catch {
367
+ context.writer.writeError("Invalid URL");
368
+ context.process.exit(-1);
369
+ }
370
+ },
371
+ writeDescription: (context) => {
372
+ const { writer } = context;
373
+ writer.writeln("Parse a URL and display its components");
374
+ writer.writeln();
375
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
376
+ writer.writeln(
377
+ ` ${writer.wrapInColor("url parse <url>", CliForegroundColor.Cyan)}`
378
+ );
379
+ }
380
+ }
381
+ ];
382
+ }
383
+ async processCommand(command, context) {
384
+ context.executor.showHelp(command, context);
385
+ }
386
+ writeDescription(context) {
387
+ const { writer, translator: t } = context;
388
+ writer.writeln(t.t("cli.url.long_description", "Encode, decode, and parse URLs"));
389
+ writer.writeln();
390
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
391
+ writer.writeln(
392
+ ` ${writer.wrapInColor("url encode <text>", CliForegroundColor.Cyan)} ${t.t("cli.url.encode_desc", "URL-encode a string")}`
393
+ );
394
+ writer.writeln(
395
+ ` ${writer.wrapInColor("url decode <text>", CliForegroundColor.Cyan)} ${t.t("cli.url.decode_desc", "URL-decode a string")}`
396
+ );
397
+ writer.writeln(
398
+ ` ${writer.wrapInColor("url parse <url>", CliForegroundColor.Cyan)} ${t.t("cli.url.parse_desc", "Parse URL components")}`
399
+ );
400
+ }
401
+ };
402
+ var CliHashCommandProcessor = class {
403
+ constructor() {
404
+ this.command = "hash";
405
+ this.description = "Generate hash digests of text";
406
+ this.author = DefaultLibraryAuthor;
407
+ this.processors = [];
408
+ this.metadata = {
409
+ icon: "#\uFE0F\u20E3",
410
+ module: "misc"
411
+ };
412
+ const algorithms = [
413
+ { command: "sha256", algo: "SHA-256", aliases: ["sha-256"] },
414
+ { command: "sha1", algo: "SHA-1", aliases: ["sha-1"] },
415
+ { command: "sha384", algo: "SHA-384", aliases: ["sha-384"] },
416
+ { command: "sha512", algo: "SHA-512", aliases: ["sha-512"] }
417
+ ];
418
+ this.processors = algorithms.map(({ command, algo, aliases }) => ({
419
+ command,
420
+ aliases,
421
+ description: `Generate ${algo} hash`,
422
+ acceptsRawInput: true,
423
+ valueRequired: true,
424
+ processCommand: async (cmd, context) => {
425
+ const text = cmd.value || cmd.data || "";
426
+ try {
427
+ const encoded = new TextEncoder().encode(text);
428
+ const hashBuffer = await crypto.subtle.digest(
429
+ algo,
430
+ encoded
431
+ );
432
+ const hashArray = Array.from(new Uint8Array(hashBuffer));
433
+ const hex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
434
+ context.writer.writeln(hex);
435
+ context.process.output(hex);
436
+ } catch {
437
+ context.writer.writeError(`Failed to compute ${algo} hash`);
438
+ context.process.exit(-1);
439
+ }
440
+ },
441
+ writeDescription: (context) => {
442
+ const { writer } = context;
443
+ writer.writeln(
444
+ `Generate a ${algo} hash digest of the input text`
445
+ );
446
+ writer.writeln();
447
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
448
+ writer.writeln(
449
+ ` ${writer.wrapInColor(`hash ${command} <text>`, CliForegroundColor.Cyan)}`
450
+ );
451
+ }
452
+ }));
453
+ }
454
+ async processCommand(command, context) {
455
+ context.executor.showHelp(command, context);
456
+ }
457
+ writeDescription(context) {
458
+ const { writer, translator: t } = context;
459
+ writer.writeln(
460
+ t.t("cli.hash.long_description", "Generate cryptographic hash digests using the Web Crypto API")
461
+ );
462
+ writer.writeln();
463
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
464
+ writer.writeln(
465
+ ` ${writer.wrapInColor("hash sha256 <text>", CliForegroundColor.Cyan)} SHA-256 hash`
466
+ );
467
+ writer.writeln(
468
+ ` ${writer.wrapInColor("hash sha1 <text>", CliForegroundColor.Cyan)} SHA-1 hash`
469
+ );
470
+ writer.writeln(
471
+ ` ${writer.wrapInColor("hash sha384 <text>", CliForegroundColor.Cyan)} SHA-384 hash`
472
+ );
473
+ writer.writeln(
474
+ ` ${writer.wrapInColor("hash sha512 <text>", CliForegroundColor.Cyan)} SHA-512 hash`
475
+ );
476
+ writer.writeln();
477
+ writer.writeln(`\u{1F4DD} ${t.t("cli.common.examples", "Examples:")}`);
478
+ writer.writeln(
479
+ ` hash sha256 hello ${writer.wrapInColor("# \u2192 2cf24dba5fb0a30e...", CliForegroundColor.Green)}`
480
+ );
481
+ }
482
+ };
483
+ var CliJwtCommandProcessor = class {
484
+ constructor() {
485
+ this.command = "jwt";
486
+ this.description = "Decode and inspect JWT tokens";
487
+ this.author = DefaultLibraryAuthor;
488
+ this.processors = [];
489
+ this.metadata = {
490
+ icon: "\u{1F511}",
491
+ module: "misc"
492
+ };
493
+ this.processors = [
494
+ {
495
+ command: "decode",
496
+ aliases: ["d"],
497
+ description: "Decode a JWT token",
498
+ acceptsRawInput: true,
499
+ valueRequired: true,
500
+ processCommand: async (command, context) => {
501
+ const token = command.value || command.data || "";
502
+ const { writer } = context;
503
+ const parts = token.split(".");
504
+ if (parts.length !== 3) {
505
+ writer.writeError(
506
+ "Invalid JWT token (expected 3 parts separated by dots)"
507
+ );
508
+ context.process.exit(-1);
509
+ return;
510
+ }
511
+ try {
512
+ const header = JSON.parse(
513
+ this.base64UrlDecode(parts[0])
514
+ );
515
+ const payload = JSON.parse(
516
+ this.base64UrlDecode(parts[1])
517
+ );
518
+ writer.writeln(
519
+ writer.wrapInColor(
520
+ "Header:",
521
+ CliForegroundColor.Yellow
522
+ )
523
+ );
524
+ writer.writeln(JSON.stringify(header, null, 2));
525
+ writer.writeln();
526
+ writer.writeln(
527
+ writer.wrapInColor(
528
+ "Payload:",
529
+ CliForegroundColor.Yellow
530
+ )
531
+ );
532
+ writer.writeln(JSON.stringify(payload, null, 2));
533
+ writer.writeln();
534
+ if (payload.exp) {
535
+ const expDate = new Date(payload.exp * 1e3);
536
+ const isExpired = expDate.getTime() < Date.now();
537
+ writer.writeln(
538
+ `${writer.wrapInColor("Expires:", CliForegroundColor.Yellow)} ${expDate.toLocaleString()} ${isExpired ? writer.wrapInColor(
539
+ "(EXPIRED)",
540
+ CliForegroundColor.Red
541
+ ) : writer.wrapInColor(
542
+ "(valid)",
543
+ CliForegroundColor.Green
544
+ )}`
545
+ );
546
+ }
547
+ if (payload.iat) {
548
+ const iatDate = new Date(payload.iat * 1e3);
549
+ writer.writeln(
550
+ `${writer.wrapInColor("Issued:", CliForegroundColor.Yellow)} ${iatDate.toLocaleString()}`
551
+ );
552
+ }
553
+ writer.writeln();
554
+ writer.writeln(
555
+ writer.wrapInColor(
556
+ "Signature:",
557
+ CliForegroundColor.Yellow
558
+ ) + ` ${parts[2].substring(0, 20)}...`
559
+ );
560
+ context.process.output({ header, payload });
561
+ } catch {
562
+ writer.writeError("Failed to decode JWT token");
563
+ context.process.exit(-1);
564
+ }
565
+ },
566
+ writeDescription: (context) => {
567
+ const { writer } = context;
568
+ writer.writeln(
569
+ "Decode a JWT token and display its header and payload"
570
+ );
571
+ writer.writeln(
572
+ "Shows expiration status and issue date if present"
573
+ );
574
+ writer.writeln();
575
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
576
+ writer.writeln(
577
+ ` ${writer.wrapInColor("jwt decode <token>", CliForegroundColor.Cyan)}`
578
+ );
579
+ }
580
+ }
581
+ ];
582
+ }
583
+ async processCommand(command, context) {
584
+ context.executor.showHelp(command, context);
585
+ }
586
+ writeDescription(context) {
587
+ const { writer, translator: t } = context;
588
+ writer.writeln(t.t("cli.jwt.long_description", "Decode and inspect JSON Web Tokens (JWT)"));
589
+ writer.writeln();
590
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
591
+ writer.writeln(
592
+ ` ${writer.wrapInColor("jwt decode <token>", CliForegroundColor.Cyan)} ${t.t("cli.jwt.decode_display", "Decode and display JWT contents")}`
593
+ );
594
+ writer.writeln();
595
+ writer.writeln(
596
+ `\u{1F4DD} ${t.t("cli.jwt.shows", "Shows: header, payload, expiration status, issue date")}`
597
+ );
598
+ }
599
+ base64UrlDecode(str) {
600
+ str = str.replace(/-/g, "+").replace(/_/g, "/");
601
+ while (str.length % 4) {
602
+ str += "=";
603
+ }
604
+ return decodeURIComponent(
605
+ atob(str).split("").map(
606
+ (c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2)
607
+ ).join("")
608
+ );
609
+ }
610
+ };
611
+ var CliBinaryCommandProcessor = class {
612
+ constructor() {
613
+ this.command = "binary";
614
+ this.aliases = ["bin"];
615
+ this.description = "Encode or decode binary strings";
616
+ this.author = DefaultLibraryAuthor;
617
+ this.processors = [];
618
+ this.metadata = {
619
+ icon: "\u{1F4BB}",
620
+ module: "@qodalis/cli-encode"
621
+ };
622
+ this.processors = [
623
+ {
624
+ command: "encode",
625
+ aliases: ["enc", "e"],
626
+ description: "Encode text to binary",
627
+ acceptsRawInput: true,
628
+ valueRequired: true,
629
+ processCommand: async (command, context) => {
630
+ const text = command.value || command.data || "";
631
+ const binary = Array.from(new TextEncoder().encode(text)).map((b) => b.toString(2).padStart(8, "0")).join(" ");
632
+ context.writer.writeln(binary);
633
+ context.process.output(binary);
634
+ },
635
+ writeDescription: (context) => {
636
+ const { writer } = context;
637
+ writer.writeln("Encode text to binary representation");
638
+ writer.writeln();
639
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
640
+ writer.writeln(
641
+ ` ${writer.wrapInColor("binary encode <text>", CliForegroundColor.Cyan)}`
642
+ );
643
+ writer.writeln();
644
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
645
+ writer.writeln(
646
+ ` binary encode Hi ${writer.wrapInColor("# \u2192 01001000 01101001", CliForegroundColor.Green)}`
647
+ );
648
+ }
649
+ },
650
+ {
651
+ command: "decode",
652
+ aliases: ["dec", "d"],
653
+ description: "Decode binary to text",
654
+ acceptsRawInput: true,
655
+ valueRequired: true,
656
+ processCommand: async (command, context) => {
657
+ const input = command.value || command.data || "";
658
+ try {
659
+ const cleaned = input.replace(/[^01]/g, "");
660
+ if (cleaned.length === 0 || cleaned.length % 8 !== 0) {
661
+ throw new Error("Invalid binary");
662
+ }
663
+ const bytes = new Uint8Array(
664
+ (cleaned.match(/.{8}/g) || []).map(
665
+ (b) => parseInt(b, 2)
666
+ )
667
+ );
668
+ const text = new TextDecoder().decode(bytes);
669
+ context.writer.writeln(text);
670
+ context.process.output(text);
671
+ } catch {
672
+ context.writer.writeError(
673
+ "Invalid binary string (expected groups of 8 bits)"
674
+ );
675
+ context.process.exit(-1);
676
+ }
677
+ },
678
+ writeDescription: (context) => {
679
+ const { writer } = context;
680
+ writer.writeln("Decode binary string back to text");
681
+ writer.writeln();
682
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
683
+ writer.writeln(
684
+ ` ${writer.wrapInColor("binary decode <binary>", CliForegroundColor.Cyan)}`
685
+ );
686
+ writer.writeln();
687
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
688
+ writer.writeln(
689
+ ` binary decode 01001000 01101001 ${writer.wrapInColor("# \u2192 Hi", CliForegroundColor.Green)}`
690
+ );
691
+ }
692
+ }
693
+ ];
694
+ }
695
+ async processCommand(command, context) {
696
+ context.executor.showHelp(command, context);
697
+ }
698
+ writeDescription(context) {
699
+ const { writer, translator: t } = context;
700
+ writer.writeln(t.t("cli.binary.long_description", "Encode and decode binary strings"));
701
+ writer.writeln(t.t("cli.binary.utf8_note", "Supports UTF-8 text encoding"));
702
+ writer.writeln();
703
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
704
+ writer.writeln(
705
+ ` ${writer.wrapInColor("binary encode <text>", CliForegroundColor.Cyan)} ${t.t("cli.binary.encode_desc", "Text to binary")}`
706
+ );
707
+ writer.writeln(
708
+ ` ${writer.wrapInColor("binary decode <binary>", CliForegroundColor.Cyan)} ${t.t("cli.binary.decode_desc", "Binary to text")}`
709
+ );
710
+ }
711
+ };
712
+ var CliRotCommandProcessor = class {
713
+ constructor() {
714
+ this.command = "rot";
715
+ this.description = "Apply ROT cipher (letter rotation)";
716
+ this.author = DefaultLibraryAuthor;
717
+ this.metadata = {
718
+ icon: "\u{1F504}",
719
+ module: "@qodalis/cli-encode"
720
+ };
721
+ this.parameters = [
722
+ {
723
+ name: "shift",
724
+ description: "Rotation amount (default: 13)",
725
+ type: "number",
726
+ required: false
727
+ }
728
+ ];
729
+ this.acceptsRawInput = true;
730
+ this.valueRequired = true;
731
+ }
732
+ async processCommand(command, context) {
733
+ const text = command.value || command.data || "";
734
+ const shift = parseInt(command.args["shift"]) || 13;
735
+ const normalizedShift = (shift % 26 + 26) % 26;
736
+ const result = text.replace(/[a-zA-Z]/g, (char) => {
737
+ const base = char >= "a" ? 97 : 65;
738
+ return String.fromCharCode(
739
+ (char.charCodeAt(0) - base + normalizedShift) % 26 + base
740
+ );
741
+ });
742
+ context.writer.writeln(result);
743
+ context.process.output(result);
744
+ }
745
+ writeDescription(context) {
746
+ const { writer, translator: t } = context;
747
+ writer.writeln(
748
+ t.t("cli.rot.long_description", "Apply ROT (rotation) cipher to text")
749
+ );
750
+ writer.writeln(
751
+ t.t("cli.rot.note", "Default is ROT13 (self-inverse: applying twice returns original)")
752
+ );
753
+ writer.writeln();
754
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
755
+ writer.writeln(
756
+ ` ${writer.wrapInColor("rot <text>", CliForegroundColor.Cyan)} ${t.t("cli.rot.default_desc", "Apply ROT13")}`
757
+ );
758
+ writer.writeln(
759
+ ` ${writer.wrapInColor("rot <text> --shift=N", CliForegroundColor.Cyan)} ${t.t("cli.rot.shift_desc", "Apply ROT-N")}`
760
+ );
761
+ writer.writeln();
762
+ writer.writeln(`\u{1F4DD} ${t.t("cli.common.examples", "Examples:")}`);
763
+ writer.writeln(
764
+ ` rot Hello World ${writer.wrapInColor("# \u2192 Uryyb Jbeyq", CliForegroundColor.Green)}`
765
+ );
766
+ writer.writeln(
767
+ ` rot Uryyb Jbeyq ${writer.wrapInColor("# \u2192 Hello World (ROT13 is self-inverse)", CliForegroundColor.Green)}`
768
+ );
769
+ writer.writeln(
770
+ ` rot abc --shift=1 ${writer.wrapInColor("# \u2192 bcd", CliForegroundColor.Green)}`
771
+ );
772
+ }
773
+ };
774
+ var CHAR_TO_MORSE = {
775
+ A: ".-",
776
+ B: "-...",
777
+ C: "-.-.",
778
+ D: "-..",
779
+ E: ".",
780
+ F: "..-.",
781
+ G: "--.",
782
+ H: "....",
783
+ I: "..",
784
+ J: ".---",
785
+ K: "-.-",
786
+ L: ".-..",
787
+ M: "--",
788
+ N: "-.",
789
+ O: "---",
790
+ P: ".--.",
791
+ Q: "--.-",
792
+ R: ".-.",
793
+ S: "...",
794
+ T: "-",
795
+ U: "..-",
796
+ V: "...-",
797
+ W: ".--",
798
+ X: "-..-",
799
+ Y: "-.--",
800
+ Z: "--..",
801
+ "0": "-----",
802
+ "1": ".----",
803
+ "2": "..---",
804
+ "3": "...--",
805
+ "4": "....-",
806
+ "5": ".....",
807
+ "6": "-....",
808
+ "7": "--...",
809
+ "8": "---..",
810
+ "9": "----.",
811
+ ".": ".-.-.-",
812
+ ",": "--..--",
813
+ "?": "..--..",
814
+ "'": ".----.",
815
+ "!": "-.-.--",
816
+ "/": "-..-.",
817
+ "(": "-.--.",
818
+ ")": "-.--.-",
819
+ "&": ".-...",
820
+ ":": "---...",
821
+ ";": "-.-.-.",
822
+ "=": "-...-",
823
+ "+": ".-.-.",
824
+ "-": "-....-",
825
+ "_": "..--.-",
826
+ '"': ".-..-.",
827
+ "$": "...-..-",
828
+ "@": ".--.-.",
829
+ " ": "/"
830
+ };
831
+ var MORSE_TO_CHAR = {};
832
+ for (const [char, morse] of Object.entries(CHAR_TO_MORSE)) {
833
+ if (char !== " ") {
834
+ MORSE_TO_CHAR[morse] = char;
835
+ }
836
+ }
837
+ var CliMorseCommandProcessor = class {
838
+ constructor() {
839
+ this.command = "morse";
840
+ this.description = "Encode or decode Morse code";
841
+ this.author = DefaultLibraryAuthor;
842
+ this.processors = [];
843
+ this.metadata = {
844
+ icon: "\u{1F4E1}",
845
+ module: "@qodalis/cli-encode"
846
+ };
847
+ this.processors = [
848
+ {
849
+ command: "encode",
850
+ aliases: ["enc", "e"],
851
+ description: "Encode text to Morse code",
852
+ acceptsRawInput: true,
853
+ valueRequired: true,
854
+ processCommand: async (command, context) => {
855
+ const text = command.value || command.data || "";
856
+ const morse = text.toUpperCase().split("").map((c) => CHAR_TO_MORSE[c] ?? c).join(" ");
857
+ context.writer.writeln(morse);
858
+ context.process.output(morse);
859
+ },
860
+ writeDescription: (context) => {
861
+ const { writer } = context;
862
+ writer.writeln("Encode text to Morse code");
863
+ writer.writeln();
864
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
865
+ writer.writeln(
866
+ ` ${writer.wrapInColor("morse encode <text>", CliForegroundColor.Cyan)}`
867
+ );
868
+ writer.writeln();
869
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
870
+ writer.writeln(
871
+ ` morse encode SOS ${writer.wrapInColor("# \u2192 ... --- ...", CliForegroundColor.Green)}`
872
+ );
873
+ writer.writeln(
874
+ ` morse encode Hello World ${writer.wrapInColor("# \u2192 .... . .-.. .-.. --- / .-- --- .-. .-.. -..", CliForegroundColor.Green)}`
875
+ );
876
+ }
877
+ },
878
+ {
879
+ command: "decode",
880
+ aliases: ["dec", "d"],
881
+ description: "Decode Morse code to text",
882
+ acceptsRawInput: true,
883
+ valueRequired: true,
884
+ processCommand: async (command, context) => {
885
+ const input = command.value || command.data || "";
886
+ try {
887
+ const text = input.split(" ").map((code) => {
888
+ if (code === "/") return " ";
889
+ const char = MORSE_TO_CHAR[code];
890
+ if (!char) throw new Error(`Unknown morse: ${code}`);
891
+ return char;
892
+ }).join("");
893
+ context.writer.writeln(text);
894
+ context.process.output(text);
895
+ } catch {
896
+ context.writer.writeError(
897
+ "Invalid Morse code (use spaces between letters, / between words)"
898
+ );
899
+ context.process.exit(-1);
900
+ }
901
+ },
902
+ writeDescription: (context) => {
903
+ const { writer } = context;
904
+ writer.writeln("Decode Morse code back to text");
905
+ writer.writeln();
906
+ writer.writeln(`\u{1F4CB} ${context.translator.t("cli.common.usage", "Usage:")}`);
907
+ writer.writeln(
908
+ ` ${writer.wrapInColor("morse decode <morse>", CliForegroundColor.Cyan)}`
909
+ );
910
+ writer.writeln();
911
+ writer.writeln(`\u{1F4DD} ${context.translator.t("cli.common.examples", "Examples:")}`);
912
+ writer.writeln(
913
+ ` morse decode ... --- ... ${writer.wrapInColor("# \u2192 SOS", CliForegroundColor.Green)}`
914
+ );
915
+ }
916
+ }
917
+ ];
918
+ }
919
+ async processCommand(command, context) {
920
+ context.executor.showHelp(command, context);
921
+ }
922
+ writeDescription(context) {
923
+ const { writer, translator: t } = context;
924
+ writer.writeln(t.t("cli.morse.long_description", "Encode and decode Morse code"));
925
+ writer.writeln(
926
+ t.t("cli.morse.note", "Supports letters, numbers, and common punctuation")
927
+ );
928
+ writer.writeln();
929
+ writer.writeln(`\u{1F4CB} ${t.t("cli.common.usage", "Usage:")}`);
930
+ writer.writeln(
931
+ ` ${writer.wrapInColor("morse encode <text>", CliForegroundColor.Cyan)} ${t.t("cli.morse.encode_desc", "Text to Morse")}`
932
+ );
933
+ writer.writeln(
934
+ ` ${writer.wrapInColor("morse decode <morse>", CliForegroundColor.Cyan)} ${t.t("cli.morse.decode_desc", "Morse to text")}`
935
+ );
936
+ }
937
+ };
938
+
939
+ // src/lib/version.ts
940
+ var LIBRARY_VERSION = "2.0.0-beta.7";
941
+ var API_VERSION = 2;
942
+
943
+ // src/public-api.ts
944
+ var encodeModule = {
945
+ apiVersion: API_VERSION,
946
+ name: "@qodalis/cli-encode",
947
+ processors: [
948
+ new CliBase64CommandProcessor(),
949
+ new CliHexCommandProcessor(),
950
+ new CliUrlCommandProcessor(),
951
+ new CliHashCommandProcessor(),
952
+ new CliJwtCommandProcessor(),
953
+ new CliBinaryCommandProcessor(),
954
+ new CliRotCommandProcessor(),
955
+ new CliMorseCommandProcessor()
956
+ ]
957
+ };
958
+
959
+ export { API_VERSION, CliBase64CommandProcessor, CliBinaryCommandProcessor, CliHashCommandProcessor, CliHexCommandProcessor, CliJwtCommandProcessor, CliMorseCommandProcessor, CliRotCommandProcessor, CliUrlCommandProcessor, LIBRARY_VERSION, encodeModule };
960
+ //# sourceMappingURL=public-api.mjs.map
961
+ //# sourceMappingURL=public-api.mjs.map