@nakanoaas/uuid58 1.2.1 → 1.2.3

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/encode.js DELETED
@@ -1,78 +0,0 @@
1
- var _a;
2
- import { UUID58_ALPHABET, UUID58_LENGTH } from "./alphabet.js";
3
- /**
4
- * Error thrown when an invalid UUID string is provided for encoding.
5
- * This includes strings that don't match the standard UUID format (32 hexadecimal characters with optional hyphens).
6
- */
7
- export class Uuid58EncodeError extends Error {
8
- }
9
- _a = Uuid58EncodeError;
10
- (() => {
11
- _a.prototype.name = "Uuid58EncodeError";
12
- })();
13
- /**
14
- * Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
15
- * throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
16
- *
17
- * @param uuid - The UUID string to encode (with or without hyphens)
18
- * @returns A 22-character Base58-encoded string, or an `Uuid58EncodeError` if the input is
19
- * not a valid UUID
20
- * @note This function does not throw; it returns the error object instead.
21
- *
22
- * @example
23
- * ```typescript
24
- * // With hyphens
25
- * const base58 = uuid58EncodeSafe("f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
26
- * // Without hyphens
27
- * const base58 = uuid58EncodeSafe("f4b247fd1f8745d4aa061c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
28
- * // Uppercase UUID is also accepted
29
- * const base58 = uuid58EncodeSafe("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
30
- * // Invalid UUID format
31
- * const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError
32
- * ```
33
- */
34
- export function uuid58EncodeSafe(uuid) {
35
- const hex = uuid.replace(/-/g, "");
36
- if (hex.length !== 32) {
37
- return new Uuid58EncodeError(`Invalid UUID length: expected 32 characters (excluding hyphens), got ${hex.length} characters in "${uuid}"`);
38
- }
39
- let num;
40
- try {
41
- num = BigInt("0x" + hex);
42
- }
43
- catch {
44
- return new Uuid58EncodeError(`Invalid UUID format: "${uuid}" contains non-hexadecimal characters`);
45
- }
46
- let encoded = "";
47
- do {
48
- encoded = UUID58_ALPHABET[Number(num % UUID58_LENGTH)] + encoded;
49
- num /= UUID58_LENGTH;
50
- } while (num > 0n);
51
- return encoded.padStart(22, UUID58_ALPHABET[0]);
52
- }
53
- /**
54
- * Converts a standard UUID string to a 22-character Base58-encoded format.
55
- *
56
- * @param uuid - The UUID string to encode. Can be provided with or without hyphens
57
- * (format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").
58
- * The input is case-insensitive, so both uppercase and lowercase hexadecimal characters are accepted.
59
- * @returns A 22-character Base58-encoded string representation of the UUID
60
- * @throws {Uuid58EncodeError} If the input string is not a valid UUID format
61
- *
62
- * @example
63
- * ```typescript
64
- * // With hyphens
65
- * const base58 = uuid58Encode("f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
66
- * // Without hyphens
67
- * const base58 = uuid58Encode("f4b247fd1f8745d4aa061c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
68
- * // Uppercase UUID is also accepted
69
- * const base58 = uuid58Encode("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
70
- * ```
71
- */
72
- export function uuid58Encode(uuid) {
73
- const result = uuid58EncodeSafe(uuid);
74
- if (result instanceof Uuid58EncodeError) {
75
- throw result;
76
- }
77
- return result;
78
- }
package/esm/generate.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Generates a new Base58-encoded UUID (always 22 characters).
3
- *
4
- * This function combines the standard UUID generation (using crypto.getRandomValues())
5
- * with Base58 encoding to create a shorter, URL-safe identifier.
6
- *
7
- * @returns A 22-character Base58-encoded string representing a newly generated UUID
8
- *
9
- * @example
10
- * ```typescript
11
- * const id = uuid58(); // returns a 22-character string like "XDY9dmBbcMBXqcRvYw8xJ2"
12
- * ```
13
- */
14
- export declare function uuid58(): string;
15
- //# sourceMappingURL=generate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAe/B"}
package/esm/generate.js DELETED
@@ -1,26 +0,0 @@
1
- import { UUID58_ALPHABET, UUID58_LENGTH } from "./alphabet.js";
2
- /**
3
- * Generates a new Base58-encoded UUID (always 22 characters).
4
- *
5
- * This function combines the standard UUID generation (using crypto.getRandomValues())
6
- * with Base58 encoding to create a shorter, URL-safe identifier.
7
- *
8
- * @returns A 22-character Base58-encoded string representing a newly generated UUID
9
- *
10
- * @example
11
- * ```typescript
12
- * const id = uuid58(); // returns a 22-character string like "XDY9dmBbcMBXqcRvYw8xJ2"
13
- * ```
14
- */
15
- export function uuid58() {
16
- const bytes = crypto.getRandomValues(new BigUint64Array(2));
17
- bytes[0] = (bytes[0] & 0xffffffffffff0fffn) | 0x0000000000004000n;
18
- bytes[1] = (bytes[1] & 0x3fffffffffffffffn) | 0x8000000000000000n;
19
- let num = bytes[0] << 64n | bytes[1];
20
- let encoded = "";
21
- do {
22
- encoded = UUID58_ALPHABET[Number(num % UUID58_LENGTH)] + encoded;
23
- num /= UUID58_LENGTH;
24
- } while (num > 0n);
25
- return encoded.padStart(22, UUID58_ALPHABET[0]);
26
- }
package/esm/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export { UUID58_ALPHABET } from "./alphabet.js";
2
- export * from "./check.js";
3
- export * from "./decode.js";
4
- export * from "./encode.js";
5
- export * from "./generate.js";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,5 +0,0 @@
1
- export { UUID58_ALPHABET } from "./alphabet.js";
2
- export * from "./check.js";
3
- export * from "./decode.js";
4
- export * from "./encode.js";
5
- export * from "./generate.js";
package/esm/package.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Character set for Base58 encoding (Bitcoin compatible).
3
- *
4
- * This alphabet excludes characters that can be easily confused:
5
- * - `0` (zero) and `O` (capital O)
6
- * - `I` (capital i) and `l` (lowercase L)
7
- *
8
- * The alphabet consists of 58 characters: digits 1-9 and letters A-Z, a-z
9
- * (excluding the ambiguous characters mentioned above).
10
- *
11
- * @example
12
- * ```typescript
13
- * const char = UUID58_ALPHABET[0]; // "1"
14
- * const char = UUID58_ALPHABET[9]; // "A"
15
- * ```
16
- */
17
- export declare const UUID58_ALPHABET: string;
18
- /**
19
- * @internal
20
- * The length of the Base58 alphabet as BigInt for encoding/decoding operations.
21
- * This is exported for internal use but not part of the public API.
22
- */
23
- export declare const UUID58_LENGTH: bigint;
24
- //# sourceMappingURL=alphabet.d.ts.map
@@ -1 +0,0 @@
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,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UUID58_LENGTH = exports.UUID58_ALPHABET = void 0;
4
- /**
5
- * Character set for Base58 encoding (Bitcoin compatible).
6
- *
7
- * This alphabet excludes characters that can be easily confused:
8
- * - `0` (zero) and `O` (capital O)
9
- * - `I` (capital i) and `l` (lowercase L)
10
- *
11
- * The alphabet consists of 58 characters: digits 1-9 and letters A-Z, a-z
12
- * (excluding the ambiguous characters mentioned above).
13
- *
14
- * @example
15
- * ```typescript
16
- * const char = UUID58_ALPHABET[0]; // "1"
17
- * const char = UUID58_ALPHABET[9]; // "A"
18
- * ```
19
- */
20
- exports.UUID58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
21
- /**
22
- * @internal
23
- * The length of the Base58 alphabet as BigInt for encoding/decoding operations.
24
- * This is exported for internal use but not part of the public API.
25
- */
26
- exports.UUID58_LENGTH = BigInt(exports.UUID58_ALPHABET.length);
package/script/check.d.ts DELETED
@@ -1,40 +0,0 @@
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
@@ -1 +0,0 @@
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 DELETED
@@ -1,47 +0,0 @@
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
- }
@@ -1,37 +0,0 @@
1
- /**
2
- * Error thrown when an invalid Base58 string is provided for decoding.
3
- * This includes strings containing characters not in the Base58 alphabet.
4
- */
5
- export declare class Uuid58DecodeError extends Error {
6
- }
7
- /**
8
- * Converts a 22-character Base58-encoded string back to a standard UUID format, but instead of
9
- * throwing an error for invalid input, it returns an `Uuid58DecodeError`
10
- * instance.
11
- *
12
- * @param uuid58 - The 22-character Base58-encoded UUID string to decode
13
- * @returns A standard UUID string (lowercase, with hyphens), or an
14
- * `Uuid58DecodeError` if the input is not a valid 22-character Base58 string
15
- * @note This function does not throw; it returns the error object instead.
16
- *
17
- * @example
18
- * ```typescript
19
- * const uuid = uuid58DecodeSafe("XDY9dmBbcMBXqcRvYw8xJ2"); // returns "f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"
20
- * const error = uuid58DecodeSafe("invalid"); // returns Uuid58DecodeError
21
- * ```
22
- */
23
- export declare function uuid58DecodeSafe(uuid58: string): string | Uuid58DecodeError;
24
- /**
25
- * Converts a 22-character Base58-encoded string back to a standard UUID string format.
26
- *
27
- * @param uuid58 - The 22-character Base58-encoded string to decode
28
- * @returns A standard UUID string in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" (always in lowercase)
29
- * @throws {Uuid58DecodeError} If the input string is not a valid 22-character Base58 string
30
- *
31
- * @example
32
- * ```typescript
33
- * const uuid = uuid58Decode("XDY9dmBbcMBXqcRvYw8xJ2"); // returns "f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"
34
- * ```
35
- */
36
- export declare function uuid58Decode(uuid58: string): string;
37
- //# sourceMappingURL=decode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;CAI3C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAoC3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnD"}
package/script/decode.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Uuid58DecodeError = void 0;
5
- exports.uuid58DecodeSafe = uuid58DecodeSafe;
6
- exports.uuid58Decode = uuid58Decode;
7
- const alphabet_js_1 = require("./alphabet.js");
8
- // Fast lookup map from alphabet characters to their indices
9
- const BASE58_MAP = {};
10
- for (let i = 0; i < alphabet_js_1.UUID58_ALPHABET.length; i++) {
11
- BASE58_MAP[alphabet_js_1.UUID58_ALPHABET[i]] = BigInt(i);
12
- }
13
- /**
14
- * Error thrown when an invalid Base58 string is provided for decoding.
15
- * This includes strings containing characters not in the Base58 alphabet.
16
- */
17
- class Uuid58DecodeError extends Error {
18
- }
19
- exports.Uuid58DecodeError = Uuid58DecodeError;
20
- _a = Uuid58DecodeError;
21
- (() => {
22
- _a.prototype.name = "Uuid58DecodeError";
23
- })();
24
- /**
25
- * Converts a 22-character Base58-encoded string back to a standard UUID format, but instead of
26
- * throwing an error for invalid input, it returns an `Uuid58DecodeError`
27
- * instance.
28
- *
29
- * @param uuid58 - The 22-character Base58-encoded UUID string to decode
30
- * @returns A standard UUID string (lowercase, with hyphens), or an
31
- * `Uuid58DecodeError` if the input is not a valid 22-character Base58 string
32
- * @note This function does not throw; it returns the error object instead.
33
- *
34
- * @example
35
- * ```typescript
36
- * const uuid = uuid58DecodeSafe("XDY9dmBbcMBXqcRvYw8xJ2"); // returns "f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"
37
- * const error = uuid58DecodeSafe("invalid"); // returns Uuid58DecodeError
38
- * ```
39
- */
40
- function uuid58DecodeSafe(uuid58) {
41
- if (uuid58.length !== 22) {
42
- return new Uuid58DecodeError(`Expected Base58 string of length 22, but received string of length ${uuid58.length}: ${uuid58}`);
43
- }
44
- let num = 0n;
45
- for (const char of uuid58) {
46
- const index = BASE58_MAP[char];
47
- if (index === undefined) {
48
- return new Uuid58DecodeError(`Invalid Base58 character '${char}' found in input: ${uuid58}`);
49
- }
50
- num = num * alphabet_js_1.UUID58_LENGTH + index;
51
- }
52
- const hex = num.toString(16).padStart(32, "0");
53
- if (hex.length !== 32) {
54
- return new Uuid58DecodeError(`Decoded value exceeds 128 bits of UUID: ${uuid58}`);
55
- }
56
- return (hex.slice(0, 8) +
57
- "-" +
58
- hex.slice(8, 12) +
59
- "-" +
60
- hex.slice(12, 16) +
61
- "-" +
62
- hex.slice(16, 20) +
63
- "-" +
64
- hex.slice(20));
65
- }
66
- /**
67
- * Converts a 22-character Base58-encoded string back to a standard UUID string format.
68
- *
69
- * @param uuid58 - The 22-character Base58-encoded string to decode
70
- * @returns A standard UUID string in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" (always in lowercase)
71
- * @throws {Uuid58DecodeError} If the input string is not a valid 22-character Base58 string
72
- *
73
- * @example
74
- * ```typescript
75
- * const uuid = uuid58Decode("XDY9dmBbcMBXqcRvYw8xJ2"); // returns "f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"
76
- * ```
77
- */
78
- function uuid58Decode(uuid58) {
79
- const result = uuid58DecodeSafe(uuid58);
80
- if (result instanceof Uuid58DecodeError) {
81
- throw result;
82
- }
83
- return result;
84
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * Error thrown when an invalid UUID string is provided for encoding.
3
- * This includes strings that don't match the standard UUID format (32 hexadecimal characters with optional hyphens).
4
- */
5
- export declare class Uuid58EncodeError extends Error {
6
- }
7
- /**
8
- * Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
9
- * throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
10
- *
11
- * @param uuid - The UUID string to encode (with or without hyphens)
12
- * @returns A 22-character Base58-encoded string, or an `Uuid58EncodeError` if the input is
13
- * not a valid UUID
14
- * @note This function does not throw; it returns the error object instead.
15
- *
16
- * @example
17
- * ```typescript
18
- * // With hyphens
19
- * const base58 = uuid58EncodeSafe("f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
20
- * // Without hyphens
21
- * const base58 = uuid58EncodeSafe("f4b247fd1f8745d4aa061c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
22
- * // Uppercase UUID is also accepted
23
- * const base58 = uuid58EncodeSafe("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
24
- * // Invalid UUID format
25
- * const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError
26
- * ```
27
- */
28
- export declare function uuid58EncodeSafe(uuid: string): string | Uuid58EncodeError;
29
- /**
30
- * Converts a standard UUID string to a 22-character Base58-encoded format.
31
- *
32
- * @param uuid - The UUID string to encode. Can be provided with or without hyphens
33
- * (format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").
34
- * The input is case-insensitive, so both uppercase and lowercase hexadecimal characters are accepted.
35
- * @returns A 22-character Base58-encoded string representation of the UUID
36
- * @throws {Uuid58EncodeError} If the input string is not a valid UUID format
37
- *
38
- * @example
39
- * ```typescript
40
- * // With hyphens
41
- * const base58 = uuid58Encode("f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
42
- * // Without hyphens
43
- * const base58 = uuid58Encode("f4b247fd1f8745d4aa061c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
44
- * // Uppercase UUID is also accepted
45
- * const base58 = uuid58Encode("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
46
- * ```
47
- */
48
- export declare function uuid58Encode(uuid: string): string;
49
- //# sourceMappingURL=encode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;CAI3C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAwBzE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD"}
package/script/encode.js DELETED
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Uuid58EncodeError = void 0;
5
- exports.uuid58EncodeSafe = uuid58EncodeSafe;
6
- exports.uuid58Encode = uuid58Encode;
7
- const alphabet_js_1 = require("./alphabet.js");
8
- /**
9
- * Error thrown when an invalid UUID string is provided for encoding.
10
- * This includes strings that don't match the standard UUID format (32 hexadecimal characters with optional hyphens).
11
- */
12
- class Uuid58EncodeError extends Error {
13
- }
14
- exports.Uuid58EncodeError = Uuid58EncodeError;
15
- _a = Uuid58EncodeError;
16
- (() => {
17
- _a.prototype.name = "Uuid58EncodeError";
18
- })();
19
- /**
20
- * Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
21
- * throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
22
- *
23
- * @param uuid - The UUID string to encode (with or without hyphens)
24
- * @returns A 22-character Base58-encoded string, or an `Uuid58EncodeError` if the input is
25
- * not a valid UUID
26
- * @note This function does not throw; it returns the error object instead.
27
- *
28
- * @example
29
- * ```typescript
30
- * // With hyphens
31
- * const base58 = uuid58EncodeSafe("f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
32
- * // Without hyphens
33
- * const base58 = uuid58EncodeSafe("f4b247fd1f8745d4aa061c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
34
- * // Uppercase UUID is also accepted
35
- * const base58 = uuid58EncodeSafe("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
36
- * // Invalid UUID format
37
- * const error = uuid58EncodeSafe("invalid"); // returns Uuid58EncodeError
38
- * ```
39
- */
40
- function uuid58EncodeSafe(uuid) {
41
- const hex = uuid.replace(/-/g, "");
42
- if (hex.length !== 32) {
43
- return new Uuid58EncodeError(`Invalid UUID length: expected 32 characters (excluding hyphens), got ${hex.length} characters in "${uuid}"`);
44
- }
45
- let num;
46
- try {
47
- num = BigInt("0x" + hex);
48
- }
49
- catch {
50
- return new Uuid58EncodeError(`Invalid UUID format: "${uuid}" contains non-hexadecimal characters`);
51
- }
52
- let encoded = "";
53
- do {
54
- encoded = alphabet_js_1.UUID58_ALPHABET[Number(num % alphabet_js_1.UUID58_LENGTH)] + encoded;
55
- num /= alphabet_js_1.UUID58_LENGTH;
56
- } while (num > 0n);
57
- return encoded.padStart(22, alphabet_js_1.UUID58_ALPHABET[0]);
58
- }
59
- /**
60
- * Converts a standard UUID string to a 22-character Base58-encoded format.
61
- *
62
- * @param uuid - The UUID string to encode. Can be provided with or without hyphens
63
- * (format: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" or "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx").
64
- * The input is case-insensitive, so both uppercase and lowercase hexadecimal characters are accepted.
65
- * @returns A 22-character Base58-encoded string representation of the UUID
66
- * @throws {Uuid58EncodeError} If the input string is not a valid UUID format
67
- *
68
- * @example
69
- * ```typescript
70
- * // With hyphens
71
- * const base58 = uuid58Encode("f4b247fd-1f87-45d4-aa06-1c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
72
- * // Without hyphens
73
- * const base58 = uuid58Encode("f4b247fd1f8745d4aa061c6fc0a8dfaf"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
74
- * // Uppercase UUID is also accepted
75
- * const base58 = uuid58Encode("F4B247FD-1F87-45D4-AA06-1C6FC0A8DFAF"); // returns "XDY9dmBbcMBXqcRvYw8xJ2"
76
- * ```
77
- */
78
- function uuid58Encode(uuid) {
79
- const result = uuid58EncodeSafe(uuid);
80
- if (result instanceof Uuid58EncodeError) {
81
- throw result;
82
- }
83
- return result;
84
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Generates a new Base58-encoded UUID (always 22 characters).
3
- *
4
- * This function combines the standard UUID generation (using crypto.getRandomValues())
5
- * with Base58 encoding to create a shorter, URL-safe identifier.
6
- *
7
- * @returns A 22-character Base58-encoded string representing a newly generated UUID
8
- *
9
- * @example
10
- * ```typescript
11
- * const id = uuid58(); // returns a 22-character string like "XDY9dmBbcMBXqcRvYw8xJ2"
12
- * ```
13
- */
14
- export declare function uuid58(): string;
15
- //# sourceMappingURL=generate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAe/B"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuid58 = uuid58;
4
- const alphabet_js_1 = require("./alphabet.js");
5
- /**
6
- * Generates a new Base58-encoded UUID (always 22 characters).
7
- *
8
- * This function combines the standard UUID generation (using crypto.getRandomValues())
9
- * with Base58 encoding to create a shorter, URL-safe identifier.
10
- *
11
- * @returns A 22-character Base58-encoded string representing a newly generated UUID
12
- *
13
- * @example
14
- * ```typescript
15
- * const id = uuid58(); // returns a 22-character string like "XDY9dmBbcMBXqcRvYw8xJ2"
16
- * ```
17
- */
18
- function uuid58() {
19
- const bytes = crypto.getRandomValues(new BigUint64Array(2));
20
- bytes[0] = (bytes[0] & 0xffffffffffff0fffn) | 0x0000000000004000n;
21
- bytes[1] = (bytes[1] & 0x3fffffffffffffffn) | 0x8000000000000000n;
22
- let num = bytes[0] << 64n | bytes[1];
23
- let encoded = "";
24
- do {
25
- encoded = alphabet_js_1.UUID58_ALPHABET[Number(num % alphabet_js_1.UUID58_LENGTH)] + encoded;
26
- num /= alphabet_js_1.UUID58_LENGTH;
27
- } while (num > 0n);
28
- return encoded.padStart(22, alphabet_js_1.UUID58_ALPHABET[0]);
29
- }
package/script/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- export { UUID58_ALPHABET } from "./alphabet.js";
2
- export * from "./check.js";
3
- export * from "./decode.js";
4
- export * from "./encode.js";
5
- export * from "./generate.js";
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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 DELETED
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.UUID58_ALPHABET = void 0;
18
- var alphabet_js_1 = require("./alphabet.js");
19
- Object.defineProperty(exports, "UUID58_ALPHABET", { enumerable: true, get: function () { return alphabet_js_1.UUID58_ALPHABET; } });
20
- __exportStar(require("./check.js"), exports);
21
- __exportStar(require("./decode.js"), exports);
22
- __exportStar(require("./encode.js"), exports);
23
- __exportStar(require("./generate.js"), exports);
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }