@nakanoaas/uuid58 1.1.0 → 1.2.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 +42 -0
- package/esm/alphabet.d.ts +0 -16
- package/esm/alphabet.d.ts.map +1 -1
- package/esm/alphabet.js +0 -16
- package/esm/check.d.ts +40 -0
- package/esm/check.d.ts.map +1 -0
- package/esm/check.js +73 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +2 -1
- package/package.json +1 -1
- package/script/alphabet.d.ts +0 -16
- package/script/alphabet.d.ts.map +1 -1
- package/script/alphabet.js +1 -17
- package/script/check.d.ts +40 -0
- package/script/check.d.ts.map +1 -0
- package/script/check.js +77 -0
- package/script/index.d.ts +2 -1
- package/script/index.d.ts.map +1 -1
- package/script/index.js +2 -2
package/README.md
CHANGED
|
@@ -94,6 +94,15 @@ if (decodedSafe instanceof Uuid58DecodeError) {
|
|
|
94
94
|
}
|
|
95
95
|
// use decoded UUID
|
|
96
96
|
console.log(decodedSafe);
|
|
97
|
+
|
|
98
|
+
import { isUuid58, UUID58_REGEX } from "@nakanoaas/uuid58";
|
|
99
|
+
|
|
100
|
+
// Validate UUID58 string without decoding
|
|
101
|
+
const isValid = isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
102
|
+
const isValid2 = isUuid58("invalid"); // false
|
|
103
|
+
|
|
104
|
+
// Or use regex pattern for validation
|
|
105
|
+
const isValid3 = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
97
106
|
```
|
|
98
107
|
|
|
99
108
|
## API Reference
|
|
@@ -187,6 +196,34 @@ that are not exactly 22 characters long.
|
|
|
187
196
|
class Uuid58DecodeError extends Error;
|
|
188
197
|
```
|
|
189
198
|
|
|
199
|
+
### `isUuid58(uuid58: string)`
|
|
200
|
+
|
|
201
|
+
Checks if a given string is a valid UUID58-encodable string. This function
|
|
202
|
+
efficiently validates without performing full decoding.
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
function isUuid58(uuid58: string): boolean;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
- **Parameters:**
|
|
209
|
+
- `uuid58`: The string to check
|
|
210
|
+
- **Returns:** `true` if the string is a valid UUID58 string, `false` otherwise
|
|
211
|
+
- **Note:** This function validates:
|
|
212
|
+
- Length (must be exactly 22 characters)
|
|
213
|
+
- Base58 alphabet characters only
|
|
214
|
+
- That the decoded value fits within 128 bits (UUID size)
|
|
215
|
+
|
|
216
|
+
**Example:**
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { isUuid58 } from "@nakanoaas/uuid58";
|
|
220
|
+
|
|
221
|
+
isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
222
|
+
isUuid58("invalid"); // false
|
|
223
|
+
isUuid58("O0lI"); // false (contains invalid characters)
|
|
224
|
+
isUuid58("short"); // false (too short)
|
|
225
|
+
```
|
|
226
|
+
|
|
190
227
|
### Alphabet and Utilities
|
|
191
228
|
|
|
192
229
|
#### `UUID58_ALPHABET`
|
|
@@ -211,6 +248,11 @@ Base58 alphabet.
|
|
|
211
248
|
const UUID58_REGEX: RegExp; // /^[1-9A-HJ-NP-Za-km-z]{22}$/
|
|
212
249
|
```
|
|
213
250
|
|
|
251
|
+
**Note:** While `UUID58_REGEX` can validate the format, `isUuid58()` provides
|
|
252
|
+
more comprehensive validation by also checking that the decoded value fits
|
|
253
|
+
within 128 bits. For simple format checks, the regex is sufficient; for complete
|
|
254
|
+
validation, use `isUuid58()`.
|
|
255
|
+
|
|
214
256
|
**Example:**
|
|
215
257
|
|
|
216
258
|
```typescript
|
package/esm/alphabet.d.ts
CHANGED
|
@@ -21,20 +21,4 @@ export declare const UUID58_ALPHABET: string;
|
|
|
21
21
|
* This is exported for internal use but not part of the public API.
|
|
22
22
|
*/
|
|
23
23
|
export declare const UUID58_LENGTH: bigint;
|
|
24
|
-
/**
|
|
25
|
-
* Regular expression pattern for validating UUID58 strings.
|
|
26
|
-
*
|
|
27
|
-
* This regex ensures that a string:
|
|
28
|
-
* - Contains exactly 22 characters
|
|
29
|
-
* - Uses only characters from the Base58 alphabet
|
|
30
|
-
* - Does not start with leading zeros (represented as "1" in Base58)
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
35
|
-
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
36
|
-
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare const UUID58_REGEX: RegExp;
|
|
40
24
|
//# sourceMappingURL=alphabet.d.ts.map
|
package/esm/alphabet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alphabet.d.ts","sourceRoot":"","sources":["../src/alphabet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,MACgC,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,MAAuC,CAAC
|
|
1
|
+
{"version":3,"file":"alphabet.d.ts","sourceRoot":"","sources":["../src/alphabet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,MACgC,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,MAAuC,CAAC"}
|
package/esm/alphabet.js
CHANGED
|
@@ -21,19 +21,3 @@ export const UUID58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnop
|
|
|
21
21
|
* This is exported for internal use but not part of the public API.
|
|
22
22
|
*/
|
|
23
23
|
export const UUID58_LENGTH = BigInt(UUID58_ALPHABET.length);
|
|
24
|
-
/**
|
|
25
|
-
* Regular expression pattern for validating UUID58 strings.
|
|
26
|
-
*
|
|
27
|
-
* This regex ensures that a string:
|
|
28
|
-
* - Contains exactly 22 characters
|
|
29
|
-
* - Uses only characters from the Base58 alphabet
|
|
30
|
-
* - Does not start with leading zeros (represented as "1" in Base58)
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
35
|
-
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
36
|
-
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export const UUID58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{22}$/u;
|
package/esm/check.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string is a valid UUID58-encodable string.
|
|
3
|
+
* This function efficiently validates without performing full decoding.
|
|
4
|
+
*
|
|
5
|
+
* A valid UUID58 string must:
|
|
6
|
+
* - Be exactly 22 characters long
|
|
7
|
+
* - Contain only characters from the Base58 alphabet
|
|
8
|
+
* - Decode to a value that fits within 128 bits (UUID size)
|
|
9
|
+
*
|
|
10
|
+
* @param uuid58 - The string to check
|
|
11
|
+
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
16
|
+
* isUuid58("invalid"); // false
|
|
17
|
+
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isUuid58(uuid58: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
23
|
+
*
|
|
24
|
+
* This regex ensures that a string:
|
|
25
|
+
* - Contains exactly 22 characters
|
|
26
|
+
* - Uses only characters from the Base58 alphabet
|
|
27
|
+
*
|
|
28
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
29
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
30
|
+
* checking, use {@link isUuid58} instead.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
35
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
36
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const UUID58_REGEX: RegExp;
|
|
40
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAmChD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,EAAE,MAAsC,CAAC"}
|
package/esm/check.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const MAX_UUID58_CODES = Array.from(
|
|
2
|
+
// UUID max value encoded in Base58 (length 22)
|
|
3
|
+
"YcVfxkQb6JRzqk5kF2tNLv", // cspell:disable-line
|
|
4
|
+
(char) => char.charCodeAt(0));
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a given string is a valid UUID58-encodable string.
|
|
7
|
+
* This function efficiently validates without performing full decoding.
|
|
8
|
+
*
|
|
9
|
+
* A valid UUID58 string must:
|
|
10
|
+
* - Be exactly 22 characters long
|
|
11
|
+
* - Contain only characters from the Base58 alphabet
|
|
12
|
+
* - Decode to a value that fits within 128 bits (UUID size)
|
|
13
|
+
*
|
|
14
|
+
* @param uuid58 - The string to check
|
|
15
|
+
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
20
|
+
* isUuid58("invalid"); // false
|
|
21
|
+
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function isUuid58(uuid58) {
|
|
25
|
+
// Check length: UUID58 strings must be exactly 22 characters
|
|
26
|
+
if (uuid58.length !== 22) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
// Compare chars against the max-UUID Base58 string using ASCII order
|
|
30
|
+
let isBelowMax = false;
|
|
31
|
+
for (let i = 0; i < 22; i++) {
|
|
32
|
+
const code = uuid58.charCodeAt(i);
|
|
33
|
+
// Check if character is in the Bitcoin Base58 alphabet
|
|
34
|
+
if (code < 49 ||
|
|
35
|
+
(code >= 58 && code <= 64) || // ':'..'@'
|
|
36
|
+
code === 73 || // 'I'
|
|
37
|
+
code === 79 || // 'O'
|
|
38
|
+
(code >= 91 && code <= 96) || // '['..'`'
|
|
39
|
+
code === 108 || // 'l'
|
|
40
|
+
code > 122) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (!isBelowMax) {
|
|
44
|
+
const maxCode = MAX_UUID58_CODES[i];
|
|
45
|
+
if (code < maxCode) {
|
|
46
|
+
isBelowMax = true;
|
|
47
|
+
}
|
|
48
|
+
else if (code > maxCode) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
57
|
+
*
|
|
58
|
+
* This regex ensures that a string:
|
|
59
|
+
* - Contains exactly 22 characters
|
|
60
|
+
* - Uses only characters from the Base58 alphabet
|
|
61
|
+
*
|
|
62
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
63
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
64
|
+
* checking, use {@link isUuid58} instead.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
69
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
70
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const UUID58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{22}$/u;
|
package/esm/index.d.ts
CHANGED
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
package/esm/index.js
CHANGED
package/package.json
CHANGED
package/script/alphabet.d.ts
CHANGED
|
@@ -21,20 +21,4 @@ export declare const UUID58_ALPHABET: string;
|
|
|
21
21
|
* This is exported for internal use but not part of the public API.
|
|
22
22
|
*/
|
|
23
23
|
export declare const UUID58_LENGTH: bigint;
|
|
24
|
-
/**
|
|
25
|
-
* Regular expression pattern for validating UUID58 strings.
|
|
26
|
-
*
|
|
27
|
-
* This regex ensures that a string:
|
|
28
|
-
* - Contains exactly 22 characters
|
|
29
|
-
* - Uses only characters from the Base58 alphabet
|
|
30
|
-
* - Does not start with leading zeros (represented as "1" in Base58)
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```typescript
|
|
34
|
-
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
35
|
-
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
36
|
-
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export declare const UUID58_REGEX: RegExp;
|
|
40
24
|
//# sourceMappingURL=alphabet.d.ts.map
|
package/script/alphabet.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alphabet.d.ts","sourceRoot":"","sources":["../src/alphabet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,MACgC,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,MAAuC,CAAC
|
|
1
|
+
{"version":3,"file":"alphabet.d.ts","sourceRoot":"","sources":["../src/alphabet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,eAAe,EAAE,MACgC,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,MAAuC,CAAC"}
|
package/script/alphabet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.UUID58_LENGTH = exports.UUID58_ALPHABET = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Character set for Base58 encoding (Bitcoin compatible).
|
|
6
6
|
*
|
|
@@ -24,19 +24,3 @@ exports.UUID58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstu
|
|
|
24
24
|
* This is exported for internal use but not part of the public API.
|
|
25
25
|
*/
|
|
26
26
|
exports.UUID58_LENGTH = BigInt(exports.UUID58_ALPHABET.length);
|
|
27
|
-
/**
|
|
28
|
-
* Regular expression pattern for validating UUID58 strings.
|
|
29
|
-
*
|
|
30
|
-
* This regex ensures that a string:
|
|
31
|
-
* - Contains exactly 22 characters
|
|
32
|
-
* - Uses only characters from the Base58 alphabet
|
|
33
|
-
* - Does not start with leading zeros (represented as "1" in Base58)
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
38
|
-
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
39
|
-
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
exports.UUID58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{22}$/u;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a given string is a valid UUID58-encodable string.
|
|
3
|
+
* This function efficiently validates without performing full decoding.
|
|
4
|
+
*
|
|
5
|
+
* A valid UUID58 string must:
|
|
6
|
+
* - Be exactly 22 characters long
|
|
7
|
+
* - Contain only characters from the Base58 alphabet
|
|
8
|
+
* - Decode to a value that fits within 128 bits (UUID size)
|
|
9
|
+
*
|
|
10
|
+
* @param uuid58 - The string to check
|
|
11
|
+
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
16
|
+
* isUuid58("invalid"); // false
|
|
17
|
+
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function isUuid58(uuid58: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
23
|
+
*
|
|
24
|
+
* This regex ensures that a string:
|
|
25
|
+
* - Contains exactly 22 characters
|
|
26
|
+
* - Uses only characters from the Base58 alphabet
|
|
27
|
+
*
|
|
28
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
29
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
30
|
+
* checking, use {@link isUuid58} instead.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
35
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
36
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const UUID58_REGEX: RegExp;
|
|
40
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAmChD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,EAAE,MAAsC,CAAC"}
|
package/script/check.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UUID58_REGEX = void 0;
|
|
4
|
+
exports.isUuid58 = isUuid58;
|
|
5
|
+
const MAX_UUID58_CODES = Array.from(
|
|
6
|
+
// UUID max value encoded in Base58 (length 22)
|
|
7
|
+
"YcVfxkQb6JRzqk5kF2tNLv", // cspell:disable-line
|
|
8
|
+
(char) => char.charCodeAt(0));
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a given string is a valid UUID58-encodable string.
|
|
11
|
+
* This function efficiently validates without performing full decoding.
|
|
12
|
+
*
|
|
13
|
+
* A valid UUID58 string must:
|
|
14
|
+
* - Be exactly 22 characters long
|
|
15
|
+
* - Contain only characters from the Base58 alphabet
|
|
16
|
+
* - Decode to a value that fits within 128 bits (UUID size)
|
|
17
|
+
*
|
|
18
|
+
* @param uuid58 - The string to check
|
|
19
|
+
* @returns `true` if the string is a valid UUID58 string, `false` otherwise
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
24
|
+
* isUuid58("invalid"); // false
|
|
25
|
+
* isUuid58("O0lI"); // false (contains invalid characters)
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function isUuid58(uuid58) {
|
|
29
|
+
// Check length: UUID58 strings must be exactly 22 characters
|
|
30
|
+
if (uuid58.length !== 22) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Compare chars against the max-UUID Base58 string using ASCII order
|
|
34
|
+
let isBelowMax = false;
|
|
35
|
+
for (let i = 0; i < 22; i++) {
|
|
36
|
+
const code = uuid58.charCodeAt(i);
|
|
37
|
+
// Check if character is in the Bitcoin Base58 alphabet
|
|
38
|
+
if (code < 49 ||
|
|
39
|
+
(code >= 58 && code <= 64) || // ':'..'@'
|
|
40
|
+
code === 73 || // 'I'
|
|
41
|
+
code === 79 || // 'O'
|
|
42
|
+
(code >= 91 && code <= 96) || // '['..'`'
|
|
43
|
+
code === 108 || // 'l'
|
|
44
|
+
code > 122) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (!isBelowMax) {
|
|
48
|
+
const maxCode = MAX_UUID58_CODES[i];
|
|
49
|
+
if (code < maxCode) {
|
|
50
|
+
isBelowMax = true;
|
|
51
|
+
}
|
|
52
|
+
else if (code > maxCode) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
61
|
+
*
|
|
62
|
+
* This regex ensures that a string:
|
|
63
|
+
* - Contains exactly 22 characters
|
|
64
|
+
* - Uses only characters from the Base58 alphabet
|
|
65
|
+
*
|
|
66
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
67
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
68
|
+
* checking, use {@link isUuid58} instead.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
73
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
74
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
exports.UUID58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{22}$/u;
|
package/script/index.d.ts
CHANGED
package/script/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
|
package/script/index.js
CHANGED
|
@@ -14,10 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.UUID58_ALPHABET = void 0;
|
|
18
18
|
var alphabet_js_1 = require("./alphabet.js");
|
|
19
19
|
Object.defineProperty(exports, "UUID58_ALPHABET", { enumerable: true, get: function () { return alphabet_js_1.UUID58_ALPHABET; } });
|
|
20
|
-
|
|
20
|
+
__exportStar(require("./check.js"), exports);
|
|
21
21
|
__exportStar(require("./decode.js"), exports);
|
|
22
22
|
__exportStar(require("./encode.js"), exports);
|
|
23
23
|
__exportStar(require("./generate.js"), exports);
|