@qodalis/cli-guid 1.0.8 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -22
- package/public-api.d.mts +45 -0
- package/public-api.d.ts +45 -3
- package/public-api.js +541 -0
- package/public-api.js.map +1 -0
- package/public-api.mjs +532 -0
- package/public-api.mjs.map +1 -0
- package/umd/cli-entrypoint.global.js +3208 -0
- package/README.md +0 -18
- package/esm2022/lib/cli-guid.module.mjs +0 -19
- package/esm2022/lib/processors/cli-guid-command-processor.mjs +0 -93
- package/esm2022/lib/utilities/index.mjs +0 -14
- package/esm2022/lib/version.mjs +0 -3
- package/esm2022/public-api.mjs +0 -7
- package/esm2022/qodalis-cli-guid.mjs +0 -5
- package/fesm2022/qodalis-cli-guid.mjs +0 -137
- package/fesm2022/qodalis-cli-guid.mjs.map +0 -1
- package/index.d.ts +0 -5
- package/lib/cli-guid.module.d.ts +0 -6
- package/lib/processors/cli-guid-command-processor.d.ts +0 -15
- package/lib/utilities/index.d.ts +0 -2
- package/lib/version.d.ts +0 -1
- package/umd/index.js +0 -120
package/package.json
CHANGED
|
@@ -1,44 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qodalis/cli-guid",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
|
+
"description": "@qodalis/cli extension for generating and validating GUIDs.",
|
|
5
5
|
"author": "Nicolae Lupei, Qodalis Solutions",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "https://github.com/qodalis-solutions/
|
|
9
|
+
"url": "https://github.com/qodalis-solutions/web-cli"
|
|
10
10
|
},
|
|
11
11
|
"homepage": "https://qodalis.com",
|
|
12
12
|
"keywords": [
|
|
13
|
-
"angular",
|
|
14
13
|
"cli",
|
|
15
14
|
"qodalis",
|
|
16
15
|
"terminal",
|
|
17
|
-
"guid"
|
|
16
|
+
"guid",
|
|
17
|
+
"uuid",
|
|
18
|
+
"generator"
|
|
18
19
|
],
|
|
19
20
|
"umd": "./umd/index.js",
|
|
20
21
|
"unpkg": "./umd/index.js",
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"@angular/common": "^16.2.0",
|
|
23
|
-
"@angular/core": "^16.2.0"
|
|
24
|
-
},
|
|
25
22
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"@qodalis/cli-core": "^0.0.5",
|
|
28
|
-
"@qodalis/angular-cli": "^1.0.14"
|
|
23
|
+
"@qodalis/cli-core": "2.0.0-beta.1"
|
|
29
24
|
},
|
|
30
25
|
"sideEffects": false,
|
|
31
|
-
"
|
|
32
|
-
"
|
|
26
|
+
"main": "./public-api.js",
|
|
27
|
+
"module": "./public-api.mjs",
|
|
28
|
+
"types": "./public-api.d.ts",
|
|
33
29
|
"exports": {
|
|
34
|
-
"./package.json": {
|
|
35
|
-
"default": "./package.json"
|
|
36
|
-
},
|
|
37
30
|
".": {
|
|
38
|
-
"types": "./
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"default": "./fesm2022/qodalis-cli-guid.mjs"
|
|
31
|
+
"types": "./public-api.d.ts",
|
|
32
|
+
"import": "./public-api.mjs",
|
|
33
|
+
"require": "./public-api.js"
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
|
-
}
|
|
36
|
+
}
|
package/public-api.d.mts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as _qodalis_cli_core from '@qodalis/cli-core';
|
|
2
|
+
import { ICliCommandProcessor, CliProcessorMetadata, CliProcessCommand, ICliExecutionContext, ICliModule } from '@qodalis/cli-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generates a v4 UUID using crypto.getRandomValues when available,
|
|
6
|
+
* falling back to Math.random.
|
|
7
|
+
*/
|
|
8
|
+
declare const generateGUID: () => string;
|
|
9
|
+
/**
|
|
10
|
+
* Validates a UUID v4 string.
|
|
11
|
+
*/
|
|
12
|
+
declare const validateGUID: (guid: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Validates any UUID version (v1-v5, nil).
|
|
15
|
+
*/
|
|
16
|
+
declare const validateAnyGUID: (guid: string) => boolean;
|
|
17
|
+
/** The nil UUID (all zeros). */
|
|
18
|
+
declare const NIL_GUID = "00000000-0000-0000-0000-000000000000";
|
|
19
|
+
/**
|
|
20
|
+
* Detects the version of a UUID string.
|
|
21
|
+
* Returns the version number (1-5) or 0 for nil, or null if invalid.
|
|
22
|
+
*/
|
|
23
|
+
declare const detectGUIDVersion: (guid: string) => number | null;
|
|
24
|
+
type GuidFormat = 'default' | 'uppercase' | 'braces' | 'parentheses' | 'digits' | 'urn';
|
|
25
|
+
/**
|
|
26
|
+
* Formats a UUID string into different representations.
|
|
27
|
+
*/
|
|
28
|
+
declare const formatGUID: (guid: string, format: GuidFormat) => string;
|
|
29
|
+
|
|
30
|
+
declare class CliGuidCommandProcessor implements ICliCommandProcessor {
|
|
31
|
+
command: string;
|
|
32
|
+
aliases: string[];
|
|
33
|
+
description: string;
|
|
34
|
+
author: _qodalis_cli_core.ICliCommandAuthor;
|
|
35
|
+
version: string;
|
|
36
|
+
processors?: ICliCommandProcessor[];
|
|
37
|
+
metadata?: CliProcessorMetadata;
|
|
38
|
+
constructor();
|
|
39
|
+
processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
|
|
40
|
+
writeDescription(context: ICliExecutionContext): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare const guidModule: ICliModule;
|
|
44
|
+
|
|
45
|
+
export { CliGuidCommandProcessor, type GuidFormat, NIL_GUID, detectGUIDVersion, formatGUID, generateGUID, guidModule, validateAnyGUID, validateGUID };
|
package/public-api.d.ts
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import * as _qodalis_cli_core from '@qodalis/cli-core';
|
|
2
|
+
import { ICliCommandProcessor, CliProcessorMetadata, CliProcessCommand, ICliExecutionContext, ICliModule } from '@qodalis/cli-core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generates a v4 UUID using crypto.getRandomValues when available,
|
|
6
|
+
* falling back to Math.random.
|
|
7
|
+
*/
|
|
8
|
+
declare const generateGUID: () => string;
|
|
9
|
+
/**
|
|
10
|
+
* Validates a UUID v4 string.
|
|
11
|
+
*/
|
|
12
|
+
declare const validateGUID: (guid: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Validates any UUID version (v1-v5, nil).
|
|
15
|
+
*/
|
|
16
|
+
declare const validateAnyGUID: (guid: string) => boolean;
|
|
17
|
+
/** The nil UUID (all zeros). */
|
|
18
|
+
declare const NIL_GUID = "00000000-0000-0000-0000-000000000000";
|
|
19
|
+
/**
|
|
20
|
+
* Detects the version of a UUID string.
|
|
21
|
+
* Returns the version number (1-5) or 0 for nil, or null if invalid.
|
|
22
|
+
*/
|
|
23
|
+
declare const detectGUIDVersion: (guid: string) => number | null;
|
|
24
|
+
type GuidFormat = 'default' | 'uppercase' | 'braces' | 'parentheses' | 'digits' | 'urn';
|
|
25
|
+
/**
|
|
26
|
+
* Formats a UUID string into different representations.
|
|
27
|
+
*/
|
|
28
|
+
declare const formatGUID: (guid: string, format: GuidFormat) => string;
|
|
29
|
+
|
|
30
|
+
declare class CliGuidCommandProcessor implements ICliCommandProcessor {
|
|
31
|
+
command: string;
|
|
32
|
+
aliases: string[];
|
|
33
|
+
description: string;
|
|
34
|
+
author: _qodalis_cli_core.ICliCommandAuthor;
|
|
35
|
+
version: string;
|
|
36
|
+
processors?: ICliCommandProcessor[];
|
|
37
|
+
metadata?: CliProcessorMetadata;
|
|
38
|
+
constructor();
|
|
39
|
+
processCommand(command: CliProcessCommand, context: ICliExecutionContext): Promise<void>;
|
|
40
|
+
writeDescription(context: ICliExecutionContext): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare const guidModule: ICliModule;
|
|
44
|
+
|
|
45
|
+
export { CliGuidCommandProcessor, type GuidFormat, NIL_GUID, detectGUIDVersion, formatGUID, generateGUID, guidModule, validateAnyGUID, validateGUID };
|
package/public-api.js
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var cliCore = require('@qodalis/cli-core');
|
|
4
|
+
|
|
5
|
+
// src/lib/utilities/index.ts
|
|
6
|
+
var generateGUID = () => {
|
|
7
|
+
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
8
|
+
const bytes = new Uint8Array(16);
|
|
9
|
+
crypto.getRandomValues(bytes);
|
|
10
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
11
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
12
|
+
const hex = Array.from(
|
|
13
|
+
bytes,
|
|
14
|
+
(b) => b.toString(16).padStart(2, "0")
|
|
15
|
+
).join("");
|
|
16
|
+
return [
|
|
17
|
+
hex.slice(0, 8),
|
|
18
|
+
hex.slice(8, 12),
|
|
19
|
+
hex.slice(12, 16),
|
|
20
|
+
hex.slice(16, 20),
|
|
21
|
+
hex.slice(20, 32)
|
|
22
|
+
].join("-");
|
|
23
|
+
}
|
|
24
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (char) => {
|
|
25
|
+
const random = Math.random() * 16 | 0;
|
|
26
|
+
const value = char === "x" ? random : random & 3 | 8;
|
|
27
|
+
return value.toString(16);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var validateGUID = (guid) => {
|
|
31
|
+
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$/;
|
|
32
|
+
return guidRegex.test(guid);
|
|
33
|
+
};
|
|
34
|
+
var validateAnyGUID = (guid) => {
|
|
35
|
+
const guidRegex = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
36
|
+
return guidRegex.test(guid);
|
|
37
|
+
};
|
|
38
|
+
var NIL_GUID = "00000000-0000-0000-0000-000000000000";
|
|
39
|
+
var detectGUIDVersion = (guid) => {
|
|
40
|
+
if (!validateAnyGUID(guid)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (guid === NIL_GUID) {
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
const versionChar = guid.charAt(14);
|
|
47
|
+
const version = parseInt(versionChar, 16);
|
|
48
|
+
return version >= 1 && version <= 5 ? version : null;
|
|
49
|
+
};
|
|
50
|
+
var formatGUID = (guid, format) => {
|
|
51
|
+
const clean = guid.replace(/[-{}() ]/g, "").toLowerCase();
|
|
52
|
+
const d = `${clean.slice(0, 8)}-${clean.slice(8, 12)}-${clean.slice(12, 16)}-${clean.slice(16, 20)}-${clean.slice(20, 32)}`;
|
|
53
|
+
switch (format) {
|
|
54
|
+
case "uppercase":
|
|
55
|
+
return d.toUpperCase();
|
|
56
|
+
case "braces":
|
|
57
|
+
return `{${d}}`;
|
|
58
|
+
case "parentheses":
|
|
59
|
+
return `(${d})`;
|
|
60
|
+
case "digits":
|
|
61
|
+
return clean;
|
|
62
|
+
case "urn":
|
|
63
|
+
return `urn:uuid:${d}`;
|
|
64
|
+
case "default":
|
|
65
|
+
default:
|
|
66
|
+
return d;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/lib/version.ts
|
|
71
|
+
var LIBRARY_VERSION = "2.0.0-beta.1";
|
|
72
|
+
var API_VERSION = 2;
|
|
73
|
+
|
|
74
|
+
// src/lib/processors/cli-guid-command-processor.ts
|
|
75
|
+
var GUID_FORMATS = [
|
|
76
|
+
"default",
|
|
77
|
+
"uppercase",
|
|
78
|
+
"braces",
|
|
79
|
+
"parentheses",
|
|
80
|
+
"digits",
|
|
81
|
+
"urn"
|
|
82
|
+
];
|
|
83
|
+
var CliGuidCommandProcessor = class {
|
|
84
|
+
constructor() {
|
|
85
|
+
this.command = "guid";
|
|
86
|
+
this.aliases = ["uuid"];
|
|
87
|
+
this.description = "Generate, validate, format, and inspect UUIDs";
|
|
88
|
+
this.author = cliCore.DefaultLibraryAuthor;
|
|
89
|
+
this.version = LIBRARY_VERSION;
|
|
90
|
+
this.processors = [];
|
|
91
|
+
this.metadata = {
|
|
92
|
+
icon: "\u{1F194}",
|
|
93
|
+
module: "guid"
|
|
94
|
+
};
|
|
95
|
+
this.processors = [
|
|
96
|
+
// --- new ---
|
|
97
|
+
{
|
|
98
|
+
command: "new",
|
|
99
|
+
aliases: ["gen", "generate"],
|
|
100
|
+
description: "Generate one or more UUIDs",
|
|
101
|
+
parameters: [
|
|
102
|
+
{
|
|
103
|
+
name: "copy",
|
|
104
|
+
aliases: ["c"],
|
|
105
|
+
description: "Copy the result to the clipboard",
|
|
106
|
+
required: false,
|
|
107
|
+
type: "boolean"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "count",
|
|
111
|
+
aliases: ["n"],
|
|
112
|
+
description: "Number of UUIDs to generate",
|
|
113
|
+
defaultValue: "1",
|
|
114
|
+
required: false,
|
|
115
|
+
type: "number"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "format",
|
|
119
|
+
aliases: ["f"],
|
|
120
|
+
description: `Output format: ${GUID_FORMATS.join(", ")}`,
|
|
121
|
+
defaultValue: "default",
|
|
122
|
+
required: false,
|
|
123
|
+
type: "string"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
processCommand: async (command, context) => {
|
|
127
|
+
const count = command.args["count"] ? parseInt(command.args["count"]) : 1;
|
|
128
|
+
if (isNaN(count) || count < 1 || count > 1e3) {
|
|
129
|
+
context.writer.writeError(
|
|
130
|
+
"Count must be a number between 1 and 1000"
|
|
131
|
+
);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const format = command.args["format"] || "default";
|
|
135
|
+
if (!GUID_FORMATS.includes(format)) {
|
|
136
|
+
context.writer.writeError(
|
|
137
|
+
`Unknown format "${format}". Available: ${GUID_FORMATS.join(", ")}`
|
|
138
|
+
);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const copyToClipboard = command.args["copy"] || command.args["c"];
|
|
142
|
+
const items = [];
|
|
143
|
+
for (let i = 0; i < count; i++) {
|
|
144
|
+
const guid = formatGUID(generateGUID(), format);
|
|
145
|
+
context.writer.writeln(guid);
|
|
146
|
+
items.push(guid);
|
|
147
|
+
}
|
|
148
|
+
if (copyToClipboard) {
|
|
149
|
+
await context.clipboard.write(items.join("\n"));
|
|
150
|
+
context.writer.writeInfo(
|
|
151
|
+
items.length === 1 ? "Copied to clipboard" : `${items.length} UUIDs copied to clipboard`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
context.process.output(
|
|
155
|
+
items.length === 1 ? items[0] : items
|
|
156
|
+
);
|
|
157
|
+
},
|
|
158
|
+
writeDescription: (context) => {
|
|
159
|
+
const { writer } = context;
|
|
160
|
+
writer.writeln("Generate one or more UUIDs (v4)");
|
|
161
|
+
writer.writeln();
|
|
162
|
+
writer.writeln("\u{1F4CB} Usage:");
|
|
163
|
+
writer.writeln(
|
|
164
|
+
` ${writer.wrapInColor("guid new", cliCore.CliForegroundColor.Cyan)} Generate a single UUID`
|
|
165
|
+
);
|
|
166
|
+
writer.writeln(
|
|
167
|
+
` ${writer.wrapInColor("guid new --count=5", cliCore.CliForegroundColor.Cyan)} Generate 5 UUIDs`
|
|
168
|
+
);
|
|
169
|
+
writer.writeln(
|
|
170
|
+
` ${writer.wrapInColor("guid new --copy", cliCore.CliForegroundColor.Cyan)} Generate and copy`
|
|
171
|
+
);
|
|
172
|
+
writer.writeln(
|
|
173
|
+
` ${writer.wrapInColor("guid new --format=uppercase", cliCore.CliForegroundColor.Cyan)} Uppercase output`
|
|
174
|
+
);
|
|
175
|
+
writer.writeln(
|
|
176
|
+
` ${writer.wrapInColor("guid new --format=braces", cliCore.CliForegroundColor.Cyan)} {wrapped} format`
|
|
177
|
+
);
|
|
178
|
+
writer.writeln();
|
|
179
|
+
writer.writeln(
|
|
180
|
+
`Formats: ${writer.wrapInColor(GUID_FORMATS.join(", "), cliCore.CliForegroundColor.Yellow)}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
// --- validate ---
|
|
185
|
+
{
|
|
186
|
+
command: "validate",
|
|
187
|
+
aliases: ["check"],
|
|
188
|
+
description: "Validate a UUID string",
|
|
189
|
+
acceptsRawInput: true,
|
|
190
|
+
valueRequired: true,
|
|
191
|
+
parameters: [
|
|
192
|
+
{
|
|
193
|
+
name: "strict",
|
|
194
|
+
description: "Only accept v4 UUIDs (default: accept any version)",
|
|
195
|
+
required: false,
|
|
196
|
+
type: "boolean"
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
processCommand: async (command, context) => {
|
|
200
|
+
const input = command.value;
|
|
201
|
+
const strict = command.args["strict"];
|
|
202
|
+
const isValid = strict ? validateGUID(input) : validateAnyGUID(input);
|
|
203
|
+
if (isValid) {
|
|
204
|
+
const version = detectGUIDVersion(input);
|
|
205
|
+
const versionLabel = version === 0 ? "nil" : version ? `v${version}` : "unknown version";
|
|
206
|
+
context.writer.writeSuccess(
|
|
207
|
+
`Valid UUID (${versionLabel})`
|
|
208
|
+
);
|
|
209
|
+
context.process.output({ valid: true, version });
|
|
210
|
+
} else {
|
|
211
|
+
context.writer.writeError(
|
|
212
|
+
`Invalid UUID: ${input}`
|
|
213
|
+
);
|
|
214
|
+
context.process.output({
|
|
215
|
+
valid: false,
|
|
216
|
+
version: null
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
writeDescription: (context) => {
|
|
221
|
+
const { writer } = context;
|
|
222
|
+
writer.writeln("Validate a UUID string and detect its version");
|
|
223
|
+
writer.writeln();
|
|
224
|
+
writer.writeln("\u{1F4CB} Usage:");
|
|
225
|
+
writer.writeln(
|
|
226
|
+
` ${writer.wrapInColor("guid validate <uuid>", cliCore.CliForegroundColor.Cyan)} Check any UUID`
|
|
227
|
+
);
|
|
228
|
+
writer.writeln(
|
|
229
|
+
` ${writer.wrapInColor("guid validate <uuid> --strict", cliCore.CliForegroundColor.Cyan)} Only accept v4`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
// --- format ---
|
|
234
|
+
{
|
|
235
|
+
command: "format",
|
|
236
|
+
aliases: ["fmt"],
|
|
237
|
+
description: "Convert a UUID to a different format",
|
|
238
|
+
acceptsRawInput: true,
|
|
239
|
+
valueRequired: true,
|
|
240
|
+
parameters: [
|
|
241
|
+
{
|
|
242
|
+
name: "to",
|
|
243
|
+
aliases: ["t"],
|
|
244
|
+
description: `Target format: ${GUID_FORMATS.join(", ")}`,
|
|
245
|
+
defaultValue: "default",
|
|
246
|
+
required: false,
|
|
247
|
+
type: "string"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "copy",
|
|
251
|
+
aliases: ["c"],
|
|
252
|
+
description: "Copy the result to the clipboard",
|
|
253
|
+
required: false,
|
|
254
|
+
type: "boolean"
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
processCommand: async (command, context) => {
|
|
258
|
+
const input = command.value;
|
|
259
|
+
const clean = input.replace(/[-{}()urn:uuid ]/g, "");
|
|
260
|
+
if (!/^[0-9a-fA-F]{32}$/.test(clean)) {
|
|
261
|
+
context.writer.writeError(
|
|
262
|
+
`Cannot parse as UUID: ${input}`
|
|
263
|
+
);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const format = command.args["to"] || "default";
|
|
267
|
+
if (!GUID_FORMATS.includes(format)) {
|
|
268
|
+
context.writer.writeError(
|
|
269
|
+
`Unknown format "${format}". Available: ${GUID_FORMATS.join(", ")}`
|
|
270
|
+
);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const normalized = `${clean.slice(0, 8)}-${clean.slice(8, 12)}-${clean.slice(12, 16)}-${clean.slice(16, 20)}-${clean.slice(20, 32)}`.toLowerCase();
|
|
274
|
+
const result = formatGUID(normalized, format);
|
|
275
|
+
context.writer.writeln(result);
|
|
276
|
+
if (command.args["copy"] || command.args["c"]) {
|
|
277
|
+
await context.clipboard.write(result);
|
|
278
|
+
context.writer.writeInfo("Copied to clipboard");
|
|
279
|
+
}
|
|
280
|
+
context.process.output(result);
|
|
281
|
+
},
|
|
282
|
+
writeDescription: (context) => {
|
|
283
|
+
const { writer } = context;
|
|
284
|
+
writer.writeln("Convert a UUID between different formats");
|
|
285
|
+
writer.writeln();
|
|
286
|
+
writer.writeln("\u{1F4CB} Usage:");
|
|
287
|
+
writer.writeln(
|
|
288
|
+
` ${writer.wrapInColor("guid format <uuid> --to=braces", cliCore.CliForegroundColor.Cyan)}`
|
|
289
|
+
);
|
|
290
|
+
writer.writeln(
|
|
291
|
+
` ${writer.wrapInColor("guid format <uuid> --to=urn", cliCore.CliForegroundColor.Cyan)}`
|
|
292
|
+
);
|
|
293
|
+
writer.writeln();
|
|
294
|
+
writer.writeln(
|
|
295
|
+
`Formats: ${writer.wrapInColor(GUID_FORMATS.join(", "), cliCore.CliForegroundColor.Yellow)}`
|
|
296
|
+
);
|
|
297
|
+
writer.writeln();
|
|
298
|
+
writer.writeln("\u{1F4DD} Examples:");
|
|
299
|
+
writer.writeln(
|
|
300
|
+
` guid format 550e8400-e29b-41d4-a716-446655440000 --to=braces`
|
|
301
|
+
);
|
|
302
|
+
writer.writeln(
|
|
303
|
+
` ${writer.wrapInColor("\u2192 {550e8400-e29b-41d4-a716-446655440000}", cliCore.CliForegroundColor.Green)}`
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
// --- inspect ---
|
|
308
|
+
{
|
|
309
|
+
command: "inspect",
|
|
310
|
+
aliases: ["info", "parse"],
|
|
311
|
+
description: "Show detailed information about a UUID",
|
|
312
|
+
acceptsRawInput: true,
|
|
313
|
+
valueRequired: true,
|
|
314
|
+
processCommand: async (command, context) => {
|
|
315
|
+
const input = command.value;
|
|
316
|
+
const { writer } = context;
|
|
317
|
+
if (!validateAnyGUID(input)) {
|
|
318
|
+
writer.writeError(`Invalid UUID: ${input}`);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const version = detectGUIDVersion(input);
|
|
322
|
+
const isNil = input === NIL_GUID;
|
|
323
|
+
const lower = input.toLowerCase();
|
|
324
|
+
const variantBits = parseInt(lower.charAt(19), 16);
|
|
325
|
+
let variant;
|
|
326
|
+
if ((variantBits & 8) === 0) {
|
|
327
|
+
variant = "NCS (reserved)";
|
|
328
|
+
} else if ((variantBits & 12) === 8) {
|
|
329
|
+
variant = "RFC 4122";
|
|
330
|
+
} else if ((variantBits & 14) === 12) {
|
|
331
|
+
variant = "Microsoft (reserved)";
|
|
332
|
+
} else {
|
|
333
|
+
variant = "Future (reserved)";
|
|
334
|
+
}
|
|
335
|
+
writer.writeln(
|
|
336
|
+
writer.wrapInColor(
|
|
337
|
+
"\u2500\u2500 UUID Details \u2500\u2500",
|
|
338
|
+
cliCore.CliForegroundColor.Cyan
|
|
339
|
+
)
|
|
340
|
+
);
|
|
341
|
+
writer.writeln();
|
|
342
|
+
writer.writeln(
|
|
343
|
+
` ${writer.wrapInColor("Input:", cliCore.CliForegroundColor.Yellow)} ${input}`
|
|
344
|
+
);
|
|
345
|
+
writer.writeln(
|
|
346
|
+
` ${writer.wrapInColor("Version:", cliCore.CliForegroundColor.Yellow)} ${isNil ? "nil" : version !== null ? `v${version}` : "unknown"}`
|
|
347
|
+
);
|
|
348
|
+
writer.writeln(
|
|
349
|
+
` ${writer.wrapInColor("Variant:", cliCore.CliForegroundColor.Yellow)} ${variant}`
|
|
350
|
+
);
|
|
351
|
+
writer.writeln();
|
|
352
|
+
writer.writeln(
|
|
353
|
+
` ${writer.wrapInColor("Formats:", cliCore.CliForegroundColor.Yellow)}`
|
|
354
|
+
);
|
|
355
|
+
for (const fmt of GUID_FORMATS) {
|
|
356
|
+
const formatted = formatGUID(lower, fmt);
|
|
357
|
+
writer.writeln(
|
|
358
|
+
` ${writer.wrapInColor(fmt.padEnd(14), cliCore.CliForegroundColor.Cyan)} ${formatted}`
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
context.process.output({
|
|
362
|
+
input,
|
|
363
|
+
version,
|
|
364
|
+
variant,
|
|
365
|
+
isNil,
|
|
366
|
+
formats: Object.fromEntries(
|
|
367
|
+
GUID_FORMATS.map((fmt) => [
|
|
368
|
+
fmt,
|
|
369
|
+
formatGUID(lower, fmt)
|
|
370
|
+
])
|
|
371
|
+
)
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
writeDescription: (context) => {
|
|
375
|
+
const { writer } = context;
|
|
376
|
+
writer.writeln(
|
|
377
|
+
"Display version, variant, and all format representations of a UUID"
|
|
378
|
+
);
|
|
379
|
+
writer.writeln();
|
|
380
|
+
writer.writeln("\u{1F4CB} Usage:");
|
|
381
|
+
writer.writeln(
|
|
382
|
+
` ${writer.wrapInColor("guid inspect <uuid>", cliCore.CliForegroundColor.Cyan)}`
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
// --- nil ---
|
|
387
|
+
{
|
|
388
|
+
command: "nil",
|
|
389
|
+
aliases: ["empty", "zero"],
|
|
390
|
+
description: "Output the nil UUID (all zeros)",
|
|
391
|
+
parameters: [
|
|
392
|
+
{
|
|
393
|
+
name: "copy",
|
|
394
|
+
aliases: ["c"],
|
|
395
|
+
description: "Copy to clipboard",
|
|
396
|
+
required: false,
|
|
397
|
+
type: "boolean"
|
|
398
|
+
}
|
|
399
|
+
],
|
|
400
|
+
processCommand: async (_, context) => {
|
|
401
|
+
context.writer.writeln(NIL_GUID);
|
|
402
|
+
if (_.args["copy"] || _.args["c"]) {
|
|
403
|
+
await context.clipboard.write(NIL_GUID);
|
|
404
|
+
context.writer.writeInfo("Copied to clipboard");
|
|
405
|
+
}
|
|
406
|
+
context.process.output(NIL_GUID);
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
// --- compare ---
|
|
410
|
+
{
|
|
411
|
+
command: "compare",
|
|
412
|
+
aliases: ["eq", "equals"],
|
|
413
|
+
description: "Check if two UUIDs are equal (case/format insensitive)",
|
|
414
|
+
acceptsRawInput: true,
|
|
415
|
+
processCommand: async (command, context) => {
|
|
416
|
+
const raw = (command.value || "").trim();
|
|
417
|
+
const parts = raw.split(/\s+/);
|
|
418
|
+
if (parts.length !== 2) {
|
|
419
|
+
context.writer.writeError(
|
|
420
|
+
"Provide exactly two UUIDs to compare"
|
|
421
|
+
);
|
|
422
|
+
context.writer.writeln();
|
|
423
|
+
context.writer.writeln(
|
|
424
|
+
` Usage: ${context.writer.wrapInColor("guid compare <uuid1> <uuid2>", cliCore.CliForegroundColor.Cyan)}`
|
|
425
|
+
);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const [a, b] = parts;
|
|
429
|
+
const cleanA = a.replace(/[-{}()urn:uuid ]/g, "").toLowerCase();
|
|
430
|
+
const cleanB = b.replace(/[-{}()urn:uuid ]/g, "").toLowerCase();
|
|
431
|
+
if (!/^[0-9a-f]{32}$/.test(cleanA) || !/^[0-9a-f]{32}$/.test(cleanB)) {
|
|
432
|
+
context.writer.writeError(
|
|
433
|
+
"One or both inputs are not valid UUIDs"
|
|
434
|
+
);
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
const equal = cleanA === cleanB;
|
|
438
|
+
if (equal) {
|
|
439
|
+
context.writer.writeSuccess("The UUIDs are equal");
|
|
440
|
+
} else {
|
|
441
|
+
context.writer.writeError("The UUIDs are different");
|
|
442
|
+
}
|
|
443
|
+
context.process.output({ equal, a, b });
|
|
444
|
+
},
|
|
445
|
+
writeDescription: (context) => {
|
|
446
|
+
const { writer } = context;
|
|
447
|
+
writer.writeln(
|
|
448
|
+
"Compare two UUIDs for equality regardless of case or format"
|
|
449
|
+
);
|
|
450
|
+
writer.writeln();
|
|
451
|
+
writer.writeln("\u{1F4CB} Usage:");
|
|
452
|
+
writer.writeln(
|
|
453
|
+
` ${writer.wrapInColor("guid compare <uuid1> <uuid2>", cliCore.CliForegroundColor.Cyan)}`
|
|
454
|
+
);
|
|
455
|
+
writer.writeln();
|
|
456
|
+
writer.writeln("\u{1F4DD} Examples:");
|
|
457
|
+
writer.writeln(
|
|
458
|
+
` guid compare 550e8400-e29b-41d4-a716-446655440000 550E8400-E29B-41D4-A716-446655440000`
|
|
459
|
+
);
|
|
460
|
+
writer.writeln(
|
|
461
|
+
` ${writer.wrapInColor("\u2192 The UUIDs are equal", cliCore.CliForegroundColor.Green)}`
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
];
|
|
466
|
+
}
|
|
467
|
+
async processCommand(command, context) {
|
|
468
|
+
await context.executor.showHelp(command, context);
|
|
469
|
+
}
|
|
470
|
+
writeDescription(context) {
|
|
471
|
+
const { writer } = context;
|
|
472
|
+
writer.writeln(this.description);
|
|
473
|
+
writer.writeln();
|
|
474
|
+
writer.writeln("\u{1F4CB} Commands:");
|
|
475
|
+
writer.writeln(
|
|
476
|
+
` ${writer.wrapInColor("guid new", cliCore.CliForegroundColor.Cyan)} Generate UUIDs`
|
|
477
|
+
);
|
|
478
|
+
writer.writeln(
|
|
479
|
+
` ${writer.wrapInColor("guid validate <uuid>", cliCore.CliForegroundColor.Cyan)} Validate and detect version`
|
|
480
|
+
);
|
|
481
|
+
writer.writeln(
|
|
482
|
+
` ${writer.wrapInColor("guid format <uuid> --to=<fmt>", cliCore.CliForegroundColor.Cyan)} Convert format`
|
|
483
|
+
);
|
|
484
|
+
writer.writeln(
|
|
485
|
+
` ${writer.wrapInColor("guid inspect <uuid>", cliCore.CliForegroundColor.Cyan)} Show detailed info`
|
|
486
|
+
);
|
|
487
|
+
writer.writeln(
|
|
488
|
+
` ${writer.wrapInColor("guid compare <a> <b>", cliCore.CliForegroundColor.Cyan)} Compare two UUIDs`
|
|
489
|
+
);
|
|
490
|
+
writer.writeln(
|
|
491
|
+
` ${writer.wrapInColor("guid nil", cliCore.CliForegroundColor.Cyan)} Output nil UUID`
|
|
492
|
+
);
|
|
493
|
+
writer.writeln();
|
|
494
|
+
writer.writeln("\u{1F4DD} Examples:");
|
|
495
|
+
writer.writeln(
|
|
496
|
+
` guid new --count=5 --copy ${writer.wrapInColor("# 5 UUIDs, copied", cliCore.CliForegroundColor.Green)}`
|
|
497
|
+
);
|
|
498
|
+
writer.writeln(
|
|
499
|
+
` guid new --format=uppercase ${writer.wrapInColor("# A1B2C3D4-...", cliCore.CliForegroundColor.Green)}`
|
|
500
|
+
);
|
|
501
|
+
writer.writeln(
|
|
502
|
+
` guid validate 550e8400-e29b-41d4-a716-446655440000 ${writer.wrapInColor("# Valid UUID (v4)", cliCore.CliForegroundColor.Green)}`
|
|
503
|
+
);
|
|
504
|
+
writer.writeln(
|
|
505
|
+
` guid inspect 550e8400-e29b-41d4-a716-446655440000 ${writer.wrapInColor("# Version, variant, formats", cliCore.CliForegroundColor.Green)}`
|
|
506
|
+
);
|
|
507
|
+
writer.writeln(
|
|
508
|
+
` guid format <uuid> --to=urn ${writer.wrapInColor("# urn:uuid:...", cliCore.CliForegroundColor.Green)}`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
// src/public-api.ts
|
|
514
|
+
var guidModule = {
|
|
515
|
+
apiVersion: API_VERSION,
|
|
516
|
+
name: "@qodalis/cli-guid",
|
|
517
|
+
processors: [new CliGuidCommandProcessor()],
|
|
518
|
+
translations: {
|
|
519
|
+
es: { "cli.guid.description": "Generar, validar, formatear e inspeccionar UUIDs" },
|
|
520
|
+
fr: { "cli.guid.description": "G\xE9n\xE9rer, valider, formater et inspecter des UUIDs" },
|
|
521
|
+
de: { "cli.guid.description": "UUIDs generieren, validieren, formatieren und inspizieren" },
|
|
522
|
+
pt: { "cli.guid.description": "Gerar, validar, formatar e inspecionar UUIDs" },
|
|
523
|
+
it: { "cli.guid.description": "Generare, validare, formattare e ispezionare UUID" },
|
|
524
|
+
ja: { "cli.guid.description": "UUID\u306E\u751F\u6210\u3001\u691C\u8A3C\u3001\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8\u3001\u691C\u67FB" },
|
|
525
|
+
ko: { "cli.guid.description": "UUID \uC0DD\uC131, \uAC80\uC99D, \uD3EC\uB9F7 \uBC0F \uAC80\uC0AC" },
|
|
526
|
+
zh: { "cli.guid.description": "\u751F\u6210\u3001\u9A8C\u8BC1\u3001\u683C\u5F0F\u5316\u548C\u68C0\u67E5 UUID" },
|
|
527
|
+
ru: { "cli.guid.description": "\u0413\u0435\u043D\u0435\u0440\u0430\u0446\u0438\u044F, \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0430, \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435 \u0438 \u0430\u043D\u0430\u043B\u0438\u0437 UUID" },
|
|
528
|
+
ro: { "cli.guid.description": "Generare, validare, formatare \u0219i inspectare UUID-uri" }
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
exports.CliGuidCommandProcessor = CliGuidCommandProcessor;
|
|
533
|
+
exports.NIL_GUID = NIL_GUID;
|
|
534
|
+
exports.detectGUIDVersion = detectGUIDVersion;
|
|
535
|
+
exports.formatGUID = formatGUID;
|
|
536
|
+
exports.generateGUID = generateGUID;
|
|
537
|
+
exports.guidModule = guidModule;
|
|
538
|
+
exports.validateAnyGUID = validateAnyGUID;
|
|
539
|
+
exports.validateGUID = validateGUID;
|
|
540
|
+
//# sourceMappingURL=public-api.js.map
|
|
541
|
+
//# sourceMappingURL=public-api.js.map
|