@nakanoaas/uuid58 1.1.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/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
@@ -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;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,EAAE,MAAsC,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
+ * 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;
20
+ /**
21
+ * Checks if a given string is a valid UUID58-encodable string.
22
+ * This function efficiently validates without performing full decoding.
23
+ *
24
+ * A valid UUID58 string must:
25
+ * - Be exactly 22 characters long
26
+ * - Contain only characters from the Base58 alphabet
27
+ * - Decode to a value that fits within 128 bits (UUID size)
28
+ *
29
+ * @param uuid58 - The string to check
30
+ * @returns `true` if the string is a valid UUID58 string, `false` otherwise
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
35
+ * isUuid58("invalid"); // false
36
+ * isUuid58("O0lI"); // false (contains invalid characters)
37
+ * ```
38
+ */
39
+ export declare function isUuid58(uuid58: string): boolean;
40
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,43 @@
1
+ // UUID max value encoded in Base58 (length 22)
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;
22
+ /**
23
+ * Checks if a given string is a valid UUID58-encodable string.
24
+ * This function efficiently validates without performing full decoding.
25
+ *
26
+ * A valid UUID58 string must:
27
+ * - Be exactly 22 characters long
28
+ * - Contain only characters from the Base58 alphabet
29
+ * - Decode to a value that fits within 128 bits (UUID size)
30
+ *
31
+ * @param uuid58 - The string to check
32
+ * @returns `true` if the string is a valid UUID58 string, `false` otherwise
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
37
+ * isUuid58("invalid"); // false
38
+ * isUuid58("O0lI"); // false (contains invalid characters)
39
+ * ```
40
+ */
41
+ export function isUuid58(uuid58) {
42
+ return UUID58_REGEX.test(uuid58) && uuid58 <= MAX_UUID58;
43
+ }
package/esm/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { UUID58_ALPHABET, UUID58_REGEX } from "./alphabet.js";
1
+ export { UUID58_ALPHABET } from "./alphabet.js";
2
+ export * from "./check.js";
2
3
  export * from "./decode.js";
3
4
  export * from "./encode.js";
4
5
  export * from "./generate.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
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
@@ -1,4 +1,5 @@
1
- export { UUID58_ALPHABET, UUID58_REGEX } from "./alphabet.js";
1
+ export { UUID58_ALPHABET } from "./alphabet.js";
2
+ export * from "./check.js";
2
3
  export * from "./decode.js";
3
4
  export * from "./encode.js";
4
5
  export * from "./generate.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakanoaas/uuid58",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "A tiny, zero-dependency library for generating and converting UUIDs to Base58-encoded strings.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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
@@ -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;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,EAAE,MAAsC,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"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UUID58_REGEX = exports.UUID58_LENGTH = exports.UUID58_ALPHABET = void 0;
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
+ * 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;
20
+ /**
21
+ * Checks if a given string is a valid UUID58-encodable string.
22
+ * This function efficiently validates without performing full decoding.
23
+ *
24
+ * A valid UUID58 string must:
25
+ * - Be exactly 22 characters long
26
+ * - Contain only characters from the Base58 alphabet
27
+ * - Decode to a value that fits within 128 bits (UUID size)
28
+ *
29
+ * @param uuid58 - The string to check
30
+ * @returns `true` if the string is a valid UUID58 string, `false` otherwise
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
35
+ * isUuid58("invalid"); // false
36
+ * isUuid58("O0lI"); // false (contains invalid characters)
37
+ * ```
38
+ */
39
+ export declare function isUuid58(uuid58: string): boolean;
40
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UUID58_REGEX = void 0;
4
+ exports.isUuid58 = isUuid58;
5
+ // UUID max value encoded in Base58 (length 22)
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;
26
+ /**
27
+ * Checks if a given string is a valid UUID58-encodable string.
28
+ * This function efficiently validates without performing full decoding.
29
+ *
30
+ * A valid UUID58 string must:
31
+ * - Be exactly 22 characters long
32
+ * - Contain only characters from the Base58 alphabet
33
+ * - Decode to a value that fits within 128 bits (UUID size)
34
+ *
35
+ * @param uuid58 - The string to check
36
+ * @returns `true` if the string is a valid UUID58 string, `false` otherwise
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * isUuid58("XDY9dmBbcMBXqcRvYw8xJ2"); // true
41
+ * isUuid58("invalid"); // false
42
+ * isUuid58("O0lI"); // false (contains invalid characters)
43
+ * ```
44
+ */
45
+ function isUuid58(uuid58) {
46
+ return exports.UUID58_REGEX.test(uuid58) && uuid58 <= MAX_UUID58;
47
+ }
package/script/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { UUID58_ALPHABET, UUID58_REGEX } from "./alphabet.js";
1
+ export { UUID58_ALPHABET } from "./alphabet.js";
2
+ export * from "./check.js";
2
3
  export * from "./decode.js";
3
4
  export * from "./encode.js";
4
5
  export * from "./generate.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC9D,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC"}
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.UUID58_REGEX = exports.UUID58_ALPHABET = void 0;
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
- Object.defineProperty(exports, "UUID58_REGEX", { enumerable: true, get: function () { return alphabet_js_1.UUID58_REGEX; } });
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);