@nakanoaas/uuid58 1.0.2 â 1.0.4
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 +1 -1
- package/esm/decode.js +5 -3
- package/esm/encode.js +6 -4
- package/esm/uuid58.d.ts +1 -1
- package/esm/uuid58.d.ts.map +1 -1
- package/esm/uuid58.js +5 -2
- package/package.json +1 -4
- package/script/decode.js +5 -3
- package/script/encode.js +6 -4
- package/script/uuid58.d.ts +1 -1
- package/script/uuid58.d.ts.map +1 -1
- package/script/uuid58.js +5 -2
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ shorter, URL-safe identifiers while maintaining the uniqueness of UUIDs.
|
|
|
14
14
|
- ð Bidirectional conversion between UUID and Base58
|
|
15
15
|
- ðŠķ Zero dependencies
|
|
16
16
|
- ðŠ Type-safe with TypeScript
|
|
17
|
-
- ð Uses native `crypto.
|
|
17
|
+
- ð Uses native `crypto.getRandomValues()` for secure UUID generation
|
|
18
18
|
- ðĶ Supports both ESM and CommonJS
|
|
19
19
|
- ðĄïļ Provides safe APIs that return error objects instead of throwing exceptions
|
|
20
20
|
|
package/esm/decode.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import { ALPHABET_LENGTH, BASE58_ALPHABET } from "./alphabet.js";
|
|
2
3
|
// Fast lookup map from alphabet characters to their indices
|
|
3
4
|
const BASE58_MAP = {};
|
|
@@ -9,10 +10,11 @@ for (let i = 0; i < BASE58_ALPHABET.length; i++) {
|
|
|
9
10
|
* This includes strings containing characters not in the Base58 alphabet.
|
|
10
11
|
*/
|
|
11
12
|
export class Uuid58DecodeError extends Error {
|
|
12
|
-
static {
|
|
13
|
-
this.prototype.name = "Uuid58DecodeError";
|
|
14
|
-
}
|
|
15
13
|
}
|
|
14
|
+
_a = Uuid58DecodeError;
|
|
15
|
+
(() => {
|
|
16
|
+
_a.prototype.name = "Uuid58DecodeError";
|
|
17
|
+
})();
|
|
16
18
|
/**
|
|
17
19
|
* Converts a 22-character Base58-encoded string back to a standard UUID format, but instead of
|
|
18
20
|
* throwing an error for invalid input, it returns an `Uuid58DecodeError`
|
package/esm/encode.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
var _a;
|
|
1
2
|
import { ALPHABET_LENGTH, BASE58_ALPHABET } from "./alphabet.js";
|
|
2
3
|
/**
|
|
3
4
|
* Error thrown when an invalid UUID string is provided for encoding.
|
|
4
5
|
* This includes strings that don't match the standard UUID format (32 hexadecimal characters with optional hyphens).
|
|
5
6
|
*/
|
|
6
7
|
export class Uuid58EncodeError extends Error {
|
|
7
|
-
static {
|
|
8
|
-
this.prototype.name = "Uuid58EncodeError";
|
|
9
|
-
}
|
|
10
8
|
}
|
|
9
|
+
_a = Uuid58EncodeError;
|
|
10
|
+
(() => {
|
|
11
|
+
_a.prototype.name = "Uuid58EncodeError";
|
|
12
|
+
})();
|
|
11
13
|
/**
|
|
12
14
|
* Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
|
|
13
15
|
* throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
|
|
@@ -30,7 +32,7 @@ export class Uuid58EncodeError extends Error {
|
|
|
30
32
|
* ```
|
|
31
33
|
*/
|
|
32
34
|
export function uuid58EncodeSafe(uuid) {
|
|
33
|
-
const hex = uuid.
|
|
35
|
+
const hex = uuid.replace(/-/g, "");
|
|
34
36
|
if (hex.length !== 32) {
|
|
35
37
|
return new Uuid58EncodeError(`Invalid UUID length: expected 32 characters (excluding hyphens), got ${hex.length} characters in "${uuid}"`);
|
|
36
38
|
}
|
package/esm/uuid58.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a new Base58-encoded UUID (always 22 characters).
|
|
3
3
|
*
|
|
4
|
-
* This function combines the standard UUID generation (using crypto.
|
|
4
|
+
* This function combines the standard UUID generation (using crypto.getRandomValues())
|
|
5
5
|
* with Base58 encoding to create a shorter, URL-safe identifier.
|
|
6
6
|
*
|
|
7
7
|
* @returns A 22-character Base58-encoded string representing a newly generated UUID
|
package/esm/uuid58.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid58.d.ts","sourceRoot":"","sources":["../src/uuid58.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"uuid58.d.ts","sourceRoot":"","sources":["../src/uuid58.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAe/B"}
|
package/esm/uuid58.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ALPHABET_LENGTH, BASE58_ALPHABET } from "./alphabet.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Generates a new Base58-encoded UUID (always 22 characters).
|
|
4
4
|
*
|
|
5
|
-
* This function combines the standard UUID generation (using crypto.
|
|
5
|
+
* This function combines the standard UUID generation (using crypto.getRandomValues())
|
|
6
6
|
* with Base58 encoding to create a shorter, URL-safe identifier.
|
|
7
7
|
*
|
|
8
8
|
* @returns A 22-character Base58-encoded string representing a newly generated UUID
|
|
@@ -13,7 +13,10 @@ import { ALPHABET_LENGTH, BASE58_ALPHABET } from "./alphabet.js";
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export function uuid58() {
|
|
16
|
-
|
|
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];
|
|
17
20
|
let encoded = "";
|
|
18
21
|
do {
|
|
19
22
|
encoded = BASE58_ALPHABET[Number(num % ALPHABET_LENGTH)] + encoded;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nakanoaas/uuid58",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A tiny, zero-dependency library for generating and converting UUIDs to Base58-encoded strings.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,8 +20,5 @@
|
|
|
20
20
|
},
|
|
21
21
|
"scripts": {},
|
|
22
22
|
"sideEffects": false,
|
|
23
|
-
"devDependencies": {
|
|
24
|
-
"@types/node": "^20.9.0"
|
|
25
|
-
},
|
|
26
23
|
"_generatedBy": "dnt@dev"
|
|
27
24
|
}
|
package/script/decode.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Uuid58DecodeError = void 0;
|
|
4
5
|
exports.uuid58DecodeSafe = uuid58DecodeSafe;
|
|
@@ -14,11 +15,12 @@ for (let i = 0; i < alphabet_js_1.BASE58_ALPHABET.length; i++) {
|
|
|
14
15
|
* This includes strings containing characters not in the Base58 alphabet.
|
|
15
16
|
*/
|
|
16
17
|
class Uuid58DecodeError extends Error {
|
|
17
|
-
static {
|
|
18
|
-
this.prototype.name = "Uuid58DecodeError";
|
|
19
|
-
}
|
|
20
18
|
}
|
|
21
19
|
exports.Uuid58DecodeError = Uuid58DecodeError;
|
|
20
|
+
_a = Uuid58DecodeError;
|
|
21
|
+
(() => {
|
|
22
|
+
_a.prototype.name = "Uuid58DecodeError";
|
|
23
|
+
})();
|
|
22
24
|
/**
|
|
23
25
|
* Converts a 22-character Base58-encoded string back to a standard UUID format, but instead of
|
|
24
26
|
* throwing an error for invalid input, it returns an `Uuid58DecodeError`
|
package/script/encode.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.Uuid58EncodeError = void 0;
|
|
4
5
|
exports.uuid58EncodeSafe = uuid58EncodeSafe;
|
|
@@ -9,11 +10,12 @@ const alphabet_js_1 = require("./alphabet.js");
|
|
|
9
10
|
* This includes strings that don't match the standard UUID format (32 hexadecimal characters with optional hyphens).
|
|
10
11
|
*/
|
|
11
12
|
class Uuid58EncodeError extends Error {
|
|
12
|
-
static {
|
|
13
|
-
this.prototype.name = "Uuid58EncodeError";
|
|
14
|
-
}
|
|
15
13
|
}
|
|
16
14
|
exports.Uuid58EncodeError = Uuid58EncodeError;
|
|
15
|
+
_a = Uuid58EncodeError;
|
|
16
|
+
(() => {
|
|
17
|
+
_a.prototype.name = "Uuid58EncodeError";
|
|
18
|
+
})();
|
|
17
19
|
/**
|
|
18
20
|
* Converts a standard UUID string to a 22-character Base58-encoded format, but instead of
|
|
19
21
|
* throwing an error for invalid input, it returns an `Uuid58EncodeError` instance.
|
|
@@ -36,7 +38,7 @@ exports.Uuid58EncodeError = Uuid58EncodeError;
|
|
|
36
38
|
* ```
|
|
37
39
|
*/
|
|
38
40
|
function uuid58EncodeSafe(uuid) {
|
|
39
|
-
const hex = uuid.
|
|
41
|
+
const hex = uuid.replace(/-/g, "");
|
|
40
42
|
if (hex.length !== 32) {
|
|
41
43
|
return new Uuid58EncodeError(`Invalid UUID length: expected 32 characters (excluding hyphens), got ${hex.length} characters in "${uuid}"`);
|
|
42
44
|
}
|
package/script/uuid58.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Generates a new Base58-encoded UUID (always 22 characters).
|
|
3
3
|
*
|
|
4
|
-
* This function combines the standard UUID generation (using crypto.
|
|
4
|
+
* This function combines the standard UUID generation (using crypto.getRandomValues())
|
|
5
5
|
* with Base58 encoding to create a shorter, URL-safe identifier.
|
|
6
6
|
*
|
|
7
7
|
* @returns A 22-character Base58-encoded string representing a newly generated UUID
|
package/script/uuid58.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uuid58.d.ts","sourceRoot":"","sources":["../src/uuid58.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"uuid58.d.ts","sourceRoot":"","sources":["../src/uuid58.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAe/B"}
|
package/script/uuid58.js
CHANGED
|
@@ -5,7 +5,7 @@ const alphabet_js_1 = require("./alphabet.js");
|
|
|
5
5
|
/**
|
|
6
6
|
* Generates a new Base58-encoded UUID (always 22 characters).
|
|
7
7
|
*
|
|
8
|
-
* This function combines the standard UUID generation (using crypto.
|
|
8
|
+
* This function combines the standard UUID generation (using crypto.getRandomValues())
|
|
9
9
|
* with Base58 encoding to create a shorter, URL-safe identifier.
|
|
10
10
|
*
|
|
11
11
|
* @returns A 22-character Base58-encoded string representing a newly generated UUID
|
|
@@ -16,7 +16,10 @@ const alphabet_js_1 = require("./alphabet.js");
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
function uuid58() {
|
|
19
|
-
|
|
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];
|
|
20
23
|
let encoded = "";
|
|
21
24
|
do {
|
|
22
25
|
encoded = alphabet_js_1.BASE58_ALPHABET[Number(num % alphabet_js_1.ALPHABET_LENGTH)] + encoded;
|