@nakanoaas/uuid58 1.2.0 → 1.2.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/esm/check.d.ts +19 -19
- package/esm/check.d.ts.map +1 -1
- package/esm/check.js +21 -51
- package/package.json +1 -1
- package/script/check.d.ts +19 -19
- package/script/check.d.ts.map +1 -1
- package/script/check.js +21 -51
package/esm/check.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
3
|
+
*
|
|
4
|
+
* This regex ensures that a string:
|
|
5
|
+
* - Contains exactly 22 characters
|
|
6
|
+
* - Uses only characters from the Base58 alphabet
|
|
7
|
+
*
|
|
8
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
9
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
10
|
+
* checking, use {@link isUuid58} instead.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
15
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
16
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const UUID58_REGEX: RegExp;
|
|
1
20
|
/**
|
|
2
21
|
* Checks if a given string is a valid UUID58-encodable string.
|
|
3
22
|
* This function efficiently validates without performing full decoding.
|
|
@@ -18,23 +37,4 @@
|
|
|
18
37
|
* ```
|
|
19
38
|
*/
|
|
20
39
|
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
40
|
//# sourceMappingURL=check.d.ts.map
|
package/esm/check.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,EAAE,MAAsC,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD"}
|
package/esm/check.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
const MAX_UUID58_CODES = Array.from(
|
|
2
1
|
// UUID max value encoded in Base58 (length 22)
|
|
3
|
-
"YcVfxkQb6JRzqk5kF2tNLv"
|
|
4
|
-
|
|
2
|
+
const MAX_UUID58 = "YcVfxkQb6JRzqk5kF2tNLv"; // cspell:disable-line
|
|
3
|
+
/**
|
|
4
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
5
|
+
*
|
|
6
|
+
* This regex ensures that a string:
|
|
7
|
+
* - Contains exactly 22 characters
|
|
8
|
+
* - Uses only characters from the Base58 alphabet
|
|
9
|
+
*
|
|
10
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
11
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
12
|
+
* checking, use {@link isUuid58} instead.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
17
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
18
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const UUID58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{22}$/u;
|
|
5
22
|
/**
|
|
6
23
|
* Checks if a given string is a valid UUID58-encodable string.
|
|
7
24
|
* This function efficiently validates without performing full decoding.
|
|
@@ -22,52 +39,5 @@ const MAX_UUID58_CODES = Array.from(
|
|
|
22
39
|
* ```
|
|
23
40
|
*/
|
|
24
41
|
export function isUuid58(uuid58) {
|
|
25
|
-
|
|
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;
|
|
42
|
+
return UUID58_REGEX.test(uuid58) && uuid58 <= MAX_UUID58;
|
|
54
43
|
}
|
|
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/package.json
CHANGED
package/script/check.d.ts
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
3
|
+
*
|
|
4
|
+
* This regex ensures that a string:
|
|
5
|
+
* - Contains exactly 22 characters
|
|
6
|
+
* - Uses only characters from the Base58 alphabet
|
|
7
|
+
*
|
|
8
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
9
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
10
|
+
* checking, use {@link isUuid58} instead.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
15
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
16
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const UUID58_REGEX: RegExp;
|
|
1
20
|
/**
|
|
2
21
|
* Checks if a given string is a valid UUID58-encodable string.
|
|
3
22
|
* This function efficiently validates without performing full decoding.
|
|
@@ -18,23 +37,4 @@
|
|
|
18
37
|
* ```
|
|
19
38
|
*/
|
|
20
39
|
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
40
|
//# sourceMappingURL=check.d.ts.map
|
package/script/check.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,EAAE,MAAsC,CAAC;AAElE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAEhD"}
|
package/script/check.js
CHANGED
|
@@ -2,10 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UUID58_REGEX = void 0;
|
|
4
4
|
exports.isUuid58 = isUuid58;
|
|
5
|
-
const MAX_UUID58_CODES = Array.from(
|
|
6
5
|
// UUID max value encoded in Base58 (length 22)
|
|
7
|
-
"YcVfxkQb6JRzqk5kF2tNLv"
|
|
8
|
-
|
|
6
|
+
const MAX_UUID58 = "YcVfxkQb6JRzqk5kF2tNLv"; // cspell:disable-line
|
|
7
|
+
/**
|
|
8
|
+
* Regular expression pattern for validating UUID58 strings.
|
|
9
|
+
*
|
|
10
|
+
* This regex ensures that a string:
|
|
11
|
+
* - Contains exactly 22 characters
|
|
12
|
+
* - Uses only characters from the Base58 alphabet
|
|
13
|
+
*
|
|
14
|
+
* **Note:** This regex does NOT validate that the decoded value fits within
|
|
15
|
+
* 128 bits (UUID size). For complete validation including 128-bit range
|
|
16
|
+
* checking, use {@link isUuid58} instead.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const isValid = UUID58_REGEX.test("XDY9dmBbcMBXqcRvYw8xJ2"); // true
|
|
21
|
+
* const isValid = UUID58_REGEX.test("invalid"); // false
|
|
22
|
+
* const isValid = UUID58_REGEX.test("123"); // false (too short)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
exports.UUID58_REGEX = /^[1-9A-HJ-NP-Za-km-z]{22}$/u;
|
|
9
26
|
/**
|
|
10
27
|
* Checks if a given string is a valid UUID58-encodable string.
|
|
11
28
|
* This function efficiently validates without performing full decoding.
|
|
@@ -26,52 +43,5 @@ const MAX_UUID58_CODES = Array.from(
|
|
|
26
43
|
* ```
|
|
27
44
|
*/
|
|
28
45
|
function isUuid58(uuid58) {
|
|
29
|
-
|
|
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;
|
|
46
|
+
return exports.UUID58_REGEX.test(uuid58) && uuid58 <= MAX_UUID58;
|
|
58
47
|
}
|
|
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;
|