@nakanoaas/uuid58 1.2.2 → 2.0.0
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 +87 -17
- package/dist/index.cjs +233 -86
- package/dist/index.d.cts +144 -50
- package/dist/index.d.ts +144 -50
- package/dist/index.js +230 -87
- package/package.json +5 -3
package/dist/index.d.cts
CHANGED
|
@@ -16,49 +16,33 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export declare const UUID58_ALPHABET: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
33
|
-
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare const UUID58_REGEX: RegExp;
|
|
37
|
-
/**
|
|
38
|
-
* Checks if a given string is a valid UUID58-encodable string.
|
|
39
|
-
* This function efficiently validates without performing full decoding.
|
|
40
|
-
*
|
|
41
|
-
* A valid UUID58 string must:
|
|
42
|
-
* - Be exactly 22 characters long
|
|
43
|
-
* - Contain only characters from the Base58 alphabet
|
|
44
|
-
* - Decode to a value that fits within 128 bits (UUID size)
|
|
45
|
-
*
|
|
46
|
-
* @param uuid58 - The string to check
|
|
47
|
-
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```typescript
|
|
51
|
-
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
52
|
-
* isUuid58("invalid"); // false
|
|
53
|
-
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
54
|
-
* ```
|
|
19
|
+
* The kind of an encoding or decoding error, as defined by the uuid58
|
|
20
|
+
* specification (Section 7).
|
|
21
|
+
*
|
|
22
|
+
* - `"invalid_length"`: the input has the wrong length (a UUID string that is
|
|
23
|
+
* neither 32 nor 36 characters, a uuid58 string that is not 22 characters,
|
|
24
|
+
* or a byte array that is not 16 bytes long).
|
|
25
|
+
* - `"invalid_character"`: the input has the right length but contains a
|
|
26
|
+
* character not allowed in its position.
|
|
27
|
+
* - `"overflow"`: (decoding only) the uuid58 string is well formed, but its
|
|
28
|
+
* value is greater than 2^128 - 1.
|
|
29
|
+
*
|
|
30
|
+
* Inputs containing non-ASCII characters may report either
|
|
31
|
+
* `"invalid_length"` or `"invalid_character"`.
|
|
55
32
|
*/
|
|
56
|
-
|
|
33
|
+
type Uuid58ErrorKind = "invalid_length" | "invalid_character" | "overflow";
|
|
57
34
|
/**
|
|
58
|
-
* Error thrown when an invalid
|
|
59
|
-
*
|
|
35
|
+
* Error thrown when an invalid uuid58 string is provided for decoding.
|
|
36
|
+
* Its {@link Uuid58DecodeError.kind | kind} tells why.
|
|
60
37
|
*/
|
|
61
|
-
export declare class Uuid58DecodeError extends Error {
|
|
38
|
+
export declare class Uuid58DecodeError extends Error {
|
|
39
|
+
/**
|
|
40
|
+
* Why the input was rejected: `"invalid_length"`, `"invalid_character"`,
|
|
41
|
+
* or `"overflow"`.
|
|
42
|
+
*/
|
|
43
|
+
readonly kind: Uuid58ErrorKind;
|
|
44
|
+
constructor(message: string, kind: Uuid58ErrorKind);
|
|
45
|
+
}
|
|
62
46
|
/**
|
|
63
47
|
* Converts a 22-character Base58-encoded string back to a standard UUID format, but instead of
|
|
64
48
|
* throwing an error for invalid input, it returns an `Uuid58DecodeError`
|
|
@@ -72,7 +56,7 @@ export declare class Uuid58DecodeError extends Error {}
|
|
|
72
56
|
* @example
|
|
73
57
|
* ```typescript
|
|
74
58
|
* const uuid = uuid58DecodeSafe("XDY9dmBbcMBXqcRvYw8xJ2"); // returns "f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"
|
|
75
|
-
* const error = uuid58DecodeSafe("invalid"); // returns Uuid58DecodeError
|
|
59
|
+
* const error = uuid58DecodeSafe("invalid"); // returns Uuid58DecodeError (kind: "invalid_length")
|
|
76
60
|
* ```
|
|
77
61
|
*/
|
|
78
62
|
export declare function uuid58DecodeSafe(uuid58: string): string | Uuid58DecodeError;
|
|
@@ -90,15 +74,25 @@ export declare function uuid58DecodeSafe(uuid58: string): string | Uuid58DecodeE
|
|
|
90
74
|
*/
|
|
91
75
|
export declare function uuid58Decode(uuid58: string): string;
|
|
92
76
|
/**
|
|
93
|
-
* Error thrown when an invalid UUID string is provided for
|
|
94
|
-
*
|
|
77
|
+
* Error thrown when an invalid UUID string or byte array is provided for
|
|
78
|
+
* encoding. Its {@link Uuid58EncodeError.kind | kind} tells why.
|
|
95
79
|
*/
|
|
96
|
-
export declare class Uuid58EncodeError extends Error {
|
|
80
|
+
export declare class Uuid58EncodeError extends Error {
|
|
81
|
+
/**
|
|
82
|
+
* Why the input was rejected: `"invalid_length"` or `"invalid_character"`.
|
|
83
|
+
*/
|
|
84
|
+
readonly kind: Exclude<Uuid58ErrorKind, "overflow">;
|
|
85
|
+
constructor(message: string, kind: Exclude<Uuid58ErrorKind, "overflow">);
|
|
86
|
+
}
|
|
97
87
|
/**
|
|
98
88
|
* Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
|
|
99
89
|
* throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
|
|
100
90
|
*
|
|
101
|
-
*
|
|
91
|
+
* Only two forms are accepted, in any letter case: the hyphenated form
|
|
92
|
+
* (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`) and 32 hexadecimal digits. Braces,
|
|
93
|
+
* `urn:uuid:`, whitespace, and hyphens in other positions are rejected.
|
|
94
|
+
*
|
|
95
|
+
* @param uuid - The UUID string to encode (hyphenated, or 32 hexadecimal digits)
|
|
102
96
|
* @returns A 22-character Base58-encoded string, or an `Uuid58EncodeError` if the input is
|
|
103
97
|
* not a valid UUID
|
|
104
98
|
* @note This function does not throw; it returns the error object instead.
|
|
@@ -112,16 +106,17 @@ export declare class Uuid58EncodeError extends Error {}
|
|
|
112
106
|
* // Uppercase UUID is also accepted
|
|
113
107
|
* const base58 = uuid58EncodeSafe("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
|
|
114
108
|
* // Invalid UUID format
|
|
115
|
-
* const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError
|
|
109
|
+
* const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError (kind: "invalid_length")
|
|
116
110
|
* ```
|
|
117
111
|
*/
|
|
118
112
|
export declare function uuid58EncodeSafe(uuid: string): string | Uuid58EncodeError;
|
|
119
113
|
/**
|
|
120
114
|
* Converts a standard UUID string to a 22-character Base58-encoded format.
|
|
121
115
|
*
|
|
122
|
-
* @param uuid - The UUID string to encode
|
|
123
|
-
* (
|
|
124
|
-
*
|
|
116
|
+
* @param uuid - The UUID string to encode, either hyphenated
|
|
117
|
+
* ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") or as 32 hexadecimal digits
|
|
118
|
+
* ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"). Hexadecimal digits may be in any case.
|
|
119
|
+
* Other forms, including hyphens in other positions, are rejected.
|
|
125
120
|
* @returns A 22-character Base58-encoded string representation of the UUID
|
|
126
121
|
* @throws {Uuid58EncodeError} If the input string is not a valid UUID format
|
|
127
122
|
*
|
|
@@ -136,6 +131,104 @@ export declare function uuid58EncodeSafe(uuid: string): string | Uuid58EncodeErr
|
|
|
136
131
|
* ```
|
|
137
132
|
*/
|
|
138
133
|
export declare function uuid58Encode(uuid: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Encodes 16 bytes, in big-endian (RFC 9562) order, as a 22-character uuid58
|
|
136
|
+
* string, but instead of throwing an error for invalid input, it returns an
|
|
137
|
+
* `Uuid58EncodeError` instance.
|
|
138
|
+
*
|
|
139
|
+
* @param bytes - The 16 bytes of the UUID
|
|
140
|
+
* @returns A 22-character uuid58 string, or an `Uuid58EncodeError` (kind
|
|
141
|
+
* `"invalid_length"`) if `bytes` is not exactly 16 bytes long
|
|
142
|
+
* @note This function does not throw; it returns the error object instead.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const bytes = new Uint8Array(16); // nil UUID
|
|
147
|
+
* uuid58EncodeBytesSafe(bytes); // returns "1111111111111111111111"
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function uuid58EncodeBytesSafe(bytes: Uint8Array): string | Uuid58EncodeError;
|
|
151
|
+
/**
|
|
152
|
+
* Encodes 16 bytes, in big-endian (RFC 9562) order, as a 22-character uuid58
|
|
153
|
+
* string.
|
|
154
|
+
*
|
|
155
|
+
* @param bytes - The 16 bytes of the UUID
|
|
156
|
+
* @returns A 22-character uuid58 string
|
|
157
|
+
* @throws {Uuid58EncodeError} If `bytes` is not exactly 16 bytes long
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* uuid58EncodeBytes(new Uint8Array(16)); // returns "1111111111111111111111"
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export declare function uuid58EncodeBytes(bytes: Uint8Array): string;
|
|
165
|
+
/**
|
|
166
|
+
* Decodes a uuid58 string to 16 bytes in big-endian (RFC 9562) order, but
|
|
167
|
+
* instead of throwing an error for invalid input, it returns an
|
|
168
|
+
* `Uuid58DecodeError` instance.
|
|
169
|
+
*
|
|
170
|
+
* @param uuid58 - The 22-character uuid58 string to decode
|
|
171
|
+
* @returns A new 16-byte `Uint8Array`, or an `Uuid58DecodeError`
|
|
172
|
+
* @note This function does not throw; it returns the error object instead.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* uuid58DecodeBytesSafe("1111111111111111111111"); // returns Uint8Array(16) of zeros
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function uuid58DecodeBytesSafe(uuid58: string): Uint8Array | Uuid58DecodeError;
|
|
180
|
+
/**
|
|
181
|
+
* Decodes a uuid58 string to 16 bytes in big-endian (RFC 9562) order.
|
|
182
|
+
*
|
|
183
|
+
* @param uuid58 - The 22-character uuid58 string to decode
|
|
184
|
+
* @returns A new 16-byte `Uint8Array`
|
|
185
|
+
* @throws {Uuid58DecodeError} If the input is not a valid uuid58 string
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const bytes = uuid58DecodeBytes("XDY9dmBbcMBXqcRvYw8xJ2");
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function uuid58DecodeBytes(uuid58: string): Uint8Array;
|
|
193
|
+
/**
|
|
194
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
195
|
+
*
|
|
196
|
+
* This regex ensures that a string:
|
|
197
|
+
* - Contains exactly 22 characters
|
|
198
|
+
* - Uses only characters from the Base58 alphabet
|
|
199
|
+
*
|
|
200
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
201
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
202
|
+
* checking, use {@link isUuid58} instead.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
207
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
208
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export declare const UUID58_REGEX: RegExp;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if a given string is a valid UUID58-encodable string.
|
|
214
|
+
* This function efficiently validates without performing full decoding.
|
|
215
|
+
*
|
|
216
|
+
* A valid UUID58 string must:
|
|
217
|
+
* - Be exactly 22 characters long
|
|
218
|
+
* - Contain only characters from the Base58 alphabet
|
|
219
|
+
* - Decode to a value that fits within 128 bits (UUID size)
|
|
220
|
+
*
|
|
221
|
+
* @param uuid58 - The string to check
|
|
222
|
+
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
227
|
+
* isUuid58("invalid"); // false
|
|
228
|
+
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export declare function isUuid58(uuid58: string): boolean;
|
|
139
232
|
/**
|
|
140
233
|
* Generates a new Base58-encoded UUID (always 22 characters).
|
|
141
234
|
*
|
|
@@ -149,4 +242,5 @@ export declare function uuid58Encode(uuid: string): string;
|
|
|
149
242
|
* const id = uuid58(); // returns a 22-character string like "XDY9dmBbcMBXqcRvYw8xJ2"
|
|
150
243
|
* ```
|
|
151
244
|
*/
|
|
152
|
-
export declare function uuid58(): string;
|
|
245
|
+
export declare function uuid58(): string;
|
|
246
|
+
export type { Uuid58ErrorKind };
|
package/dist/index.d.ts
CHANGED
|
@@ -16,49 +16,33 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export declare const UUID58_ALPHABET: string;
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
33
|
-
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare const UUID58_REGEX: RegExp;
|
|
37
|
-
/**
|
|
38
|
-
* Checks if a given string is a valid UUID58-encodable string.
|
|
39
|
-
* This function efficiently validates without performing full decoding.
|
|
40
|
-
*
|
|
41
|
-
* A valid UUID58 string must:
|
|
42
|
-
* - Be exactly 22 characters long
|
|
43
|
-
* - Contain only characters from the Base58 alphabet
|
|
44
|
-
* - Decode to a value that fits within 128 bits (UUID size)
|
|
45
|
-
*
|
|
46
|
-
* @param uuid58 - The string to check
|
|
47
|
-
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```typescript
|
|
51
|
-
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
52
|
-
* isUuid58("invalid"); // false
|
|
53
|
-
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
54
|
-
* ```
|
|
19
|
+
* The kind of an encoding or decoding error, as defined by the uuid58
|
|
20
|
+
* specification (Section 7).
|
|
21
|
+
*
|
|
22
|
+
* - `"invalid_length"`: the input has the wrong length (a UUID string that is
|
|
23
|
+
* neither 32 nor 36 characters, a uuid58 string that is not 22 characters,
|
|
24
|
+
* or a byte array that is not 16 bytes long).
|
|
25
|
+
* - `"invalid_character"`: the input has the right length but contains a
|
|
26
|
+
* character not allowed in its position.
|
|
27
|
+
* - `"overflow"`: (decoding only) the uuid58 string is well formed, but its
|
|
28
|
+
* value is greater than 2^128 - 1.
|
|
29
|
+
*
|
|
30
|
+
* Inputs containing non-ASCII characters may report either
|
|
31
|
+
* `"invalid_length"` or `"invalid_character"`.
|
|
55
32
|
*/
|
|
56
|
-
|
|
33
|
+
type Uuid58ErrorKind = "invalid_length" | "invalid_character" | "overflow";
|
|
57
34
|
/**
|
|
58
|
-
* Error thrown when an invalid
|
|
59
|
-
*
|
|
35
|
+
* Error thrown when an invalid uuid58 string is provided for decoding.
|
|
36
|
+
* Its {@link Uuid58DecodeError.kind | kind} tells why.
|
|
60
37
|
*/
|
|
61
|
-
export declare class Uuid58DecodeError extends Error {
|
|
38
|
+
export declare class Uuid58DecodeError extends Error {
|
|
39
|
+
/**
|
|
40
|
+
* Why the input was rejected: `"invalid_length"`, `"invalid_character"`,
|
|
41
|
+
* or `"overflow"`.
|
|
42
|
+
*/
|
|
43
|
+
readonly kind: Uuid58ErrorKind;
|
|
44
|
+
constructor(message: string, kind: Uuid58ErrorKind);
|
|
45
|
+
}
|
|
62
46
|
/**
|
|
63
47
|
* Converts a 22-character Base58-encoded string back to a standard UUID format, but instead of
|
|
64
48
|
* throwing an error for invalid input, it returns an `Uuid58DecodeError`
|
|
@@ -72,7 +56,7 @@ export declare class Uuid58DecodeError extends Error {}
|
|
|
72
56
|
* @example
|
|
73
57
|
* ```typescript
|
|
74
58
|
* const uuid = uuid58DecodeSafe("XDY9dmBbcMBXqcRvYw8xJ2"); // returns "f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"
|
|
75
|
-
* const error = uuid58DecodeSafe("invalid"); // returns Uuid58DecodeError
|
|
59
|
+
* const error = uuid58DecodeSafe("invalid"); // returns Uuid58DecodeError (kind: "invalid_length")
|
|
76
60
|
* ```
|
|
77
61
|
*/
|
|
78
62
|
export declare function uuid58DecodeSafe(uuid58: string): string | Uuid58DecodeError;
|
|
@@ -90,15 +74,25 @@ export declare function uuid58DecodeSafe(uuid58: string): string | Uuid58DecodeE
|
|
|
90
74
|
*/
|
|
91
75
|
export declare function uuid58Decode(uuid58: string): string;
|
|
92
76
|
/**
|
|
93
|
-
* Error thrown when an invalid UUID string is provided for
|
|
94
|
-
*
|
|
77
|
+
* Error thrown when an invalid UUID string or byte array is provided for
|
|
78
|
+
* encoding. Its {@link Uuid58EncodeError.kind | kind} tells why.
|
|
95
79
|
*/
|
|
96
|
-
export declare class Uuid58EncodeError extends Error {
|
|
80
|
+
export declare class Uuid58EncodeError extends Error {
|
|
81
|
+
/**
|
|
82
|
+
* Why the input was rejected: `"invalid_length"` or `"invalid_character"`.
|
|
83
|
+
*/
|
|
84
|
+
readonly kind: Exclude<Uuid58ErrorKind, "overflow">;
|
|
85
|
+
constructor(message: string, kind: Exclude<Uuid58ErrorKind, "overflow">);
|
|
86
|
+
}
|
|
97
87
|
/**
|
|
98
88
|
* Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
|
|
99
89
|
* throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
|
|
100
90
|
*
|
|
101
|
-
*
|
|
91
|
+
* Only two forms are accepted, in any letter case: the hyphenated form
|
|
92
|
+
* (`xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`) and 32 hexadecimal digits. Braces,
|
|
93
|
+
* `urn:uuid:`, whitespace, and hyphens in other positions are rejected.
|
|
94
|
+
*
|
|
95
|
+
* @param uuid - The UUID string to encode (hyphenated, or 32 hexadecimal digits)
|
|
102
96
|
* @returns A 22-character Base58-encoded string, or an `Uuid58EncodeError` if the input is
|
|
103
97
|
* not a valid UUID
|
|
104
98
|
* @note This function does not throw; it returns the error object instead.
|
|
@@ -112,16 +106,17 @@ export declare class Uuid58EncodeError extends Error {}
|
|
|
112
106
|
* // Uppercase UUID is also accepted
|
|
113
107
|
* const base58 = uuid58EncodeSafe("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
|
|
114
108
|
* // Invalid UUID format
|
|
115
|
-
* const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError
|
|
109
|
+
* const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError (kind: "invalid_length")
|
|
116
110
|
* ```
|
|
117
111
|
*/
|
|
118
112
|
export declare function uuid58EncodeSafe(uuid: string): string | Uuid58EncodeError;
|
|
119
113
|
/**
|
|
120
114
|
* Converts a standard UUID string to a 22-character Base58-encoded format.
|
|
121
115
|
*
|
|
122
|
-
* @param uuid - The UUID string to encode
|
|
123
|
-
* (
|
|
124
|
-
*
|
|
116
|
+
* @param uuid - The UUID string to encode, either hyphenated
|
|
117
|
+
* ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") or as 32 hexadecimal digits
|
|
118
|
+
* ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"). Hexadecimal digits may be in any case.
|
|
119
|
+
* Other forms, including hyphens in other positions, are rejected.
|
|
125
120
|
* @returns A 22-character Base58-encoded string representation of the UUID
|
|
126
121
|
* @throws {Uuid58EncodeError} If the input string is not a valid UUID format
|
|
127
122
|
*
|
|
@@ -136,6 +131,104 @@ export declare function uuid58EncodeSafe(uuid: string): string | Uuid58EncodeErr
|
|
|
136
131
|
* ```
|
|
137
132
|
*/
|
|
138
133
|
export declare function uuid58Encode(uuid: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Encodes 16 bytes, in big-endian (RFC 9562) order, as a 22-character uuid58
|
|
136
|
+
* string, but instead of throwing an error for invalid input, it returns an
|
|
137
|
+
* `Uuid58EncodeError` instance.
|
|
138
|
+
*
|
|
139
|
+
* @param bytes - The 16 bytes of the UUID
|
|
140
|
+
* @returns A 22-character uuid58 string, or an `Uuid58EncodeError` (kind
|
|
141
|
+
* `"invalid_length"`) if `bytes` is not exactly 16 bytes long
|
|
142
|
+
* @note This function does not throw; it returns the error object instead.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const bytes = new Uint8Array(16); // nil UUID
|
|
147
|
+
* uuid58EncodeBytesSafe(bytes); // returns "1111111111111111111111"
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export declare function uuid58EncodeBytesSafe(bytes: Uint8Array): string | Uuid58EncodeError;
|
|
151
|
+
/**
|
|
152
|
+
* Encodes 16 bytes, in big-endian (RFC 9562) order, as a 22-character uuid58
|
|
153
|
+
* string.
|
|
154
|
+
*
|
|
155
|
+
* @param bytes - The 16 bytes of the UUID
|
|
156
|
+
* @returns A 22-character uuid58 string
|
|
157
|
+
* @throws {Uuid58EncodeError} If `bytes` is not exactly 16 bytes long
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* uuid58EncodeBytes(new Uint8Array(16)); // returns "1111111111111111111111"
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export declare function uuid58EncodeBytes(bytes: Uint8Array): string;
|
|
165
|
+
/**
|
|
166
|
+
* Decodes a uuid58 string to 16 bytes in big-endian (RFC 9562) order, but
|
|
167
|
+
* instead of throwing an error for invalid input, it returns an
|
|
168
|
+
* `Uuid58DecodeError` instance.
|
|
169
|
+
*
|
|
170
|
+
* @param uuid58 - The 22-character uuid58 string to decode
|
|
171
|
+
* @returns A new 16-byte `Uint8Array`, or an `Uuid58DecodeError`
|
|
172
|
+
* @note This function does not throw; it returns the error object instead.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* uuid58DecodeBytesSafe("1111111111111111111111"); // returns Uint8Array(16) of zeros
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function uuid58DecodeBytesSafe(uuid58: string): Uint8Array | Uuid58DecodeError;
|
|
180
|
+
/**
|
|
181
|
+
* Decodes a uuid58 string to 16 bytes in big-endian (RFC 9562) order.
|
|
182
|
+
*
|
|
183
|
+
* @param uuid58 - The 22-character uuid58 string to decode
|
|
184
|
+
* @returns A new 16-byte `Uint8Array`
|
|
185
|
+
* @throws {Uuid58DecodeError} If the input is not a valid uuid58 string
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const bytes = uuid58DecodeBytes("XDY9dmBbcMBXqcRvYw8xJ2");
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function uuid58DecodeBytes(uuid58: string): Uint8Array;
|
|
193
|
+
/**
|
|
194
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
195
|
+
*
|
|
196
|
+
* This regex ensures that a string:
|
|
197
|
+
* - Contains exactly 22 characters
|
|
198
|
+
* - Uses only characters from the Base58 alphabet
|
|
199
|
+
*
|
|
200
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
201
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
202
|
+
* checking, use {@link isUuid58} instead.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
207
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
208
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export declare const UUID58_REGEX: RegExp;
|
|
212
|
+
/**
|
|
213
|
+
* Checks if a given string is a valid UUID58-encodable string.
|
|
214
|
+
* This function efficiently validates without performing full decoding.
|
|
215
|
+
*
|
|
216
|
+
* A valid UUID58 string must:
|
|
217
|
+
* - Be exactly 22 characters long
|
|
218
|
+
* - Contain only characters from the Base58 alphabet
|
|
219
|
+
* - Decode to a value that fits within 128 bits (UUID size)
|
|
220
|
+
*
|
|
221
|
+
* @param uuid58 - The string to check
|
|
222
|
+
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
227
|
+
* isUuid58("invalid"); // false
|
|
228
|
+
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export declare function isUuid58(uuid58: string): boolean;
|
|
139
232
|
/**
|
|
140
233
|
* Generates a new Base58-encoded UUID (always 22 characters).
|
|
141
234
|
*
|
|
@@ -149,4 +242,5 @@ export declare function uuid58Encode(uuid: string): string;
|
|
|
149
242
|
* const id = uuid58(); // returns a 22-character string like "XDY9dmBbcMBXqcRvYw8xJ2"
|
|
150
243
|
* ```
|
|
151
244
|
*/
|
|
152
|
-
export declare function uuid58(): string;
|
|
245
|
+
export declare function uuid58(): string;
|
|
246
|
+
export type { Uuid58ErrorKind };
|