@nakanoaas/uuid58 0.0.6 → 0.0.8
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 -0
- package/esm/decode.d.ts.map +1 -1
- package/esm/decode.js +4 -20
- package/esm/encode.d.ts.map +1 -1
- package/esm/encode.js +4 -16
- package/package.json +1 -1
- package/script/decode.d.ts.map +1 -1
- package/script/decode.js +4 -20
- package/script/encode.d.ts.map +1 -1
- package/script/encode.js +4 -16
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ shorter, URL-safe identifiers while maintaining the uniqueness of UUIDs.
|
|
|
16
16
|
- 💪 Type-safe with TypeScript
|
|
17
17
|
- 🔒 Uses native `crypto.randomUUID()` for secure UUID generation
|
|
18
18
|
- 📦 Supports both ESM and CommonJS
|
|
19
|
+
- 🛡️ Provides safe APIs that return error objects instead of throwing exceptions
|
|
19
20
|
|
|
20
21
|
## Installation
|
|
21
22
|
|
package/esm/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CA4B3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
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,CA4B3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnD"}
|
package/esm/decode.js
CHANGED
|
@@ -67,25 +67,9 @@ export function uuid58DecodeSafe(base58) {
|
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
69
|
export function uuid58Decode(base58) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (index === undefined) {
|
|
74
|
-
throw new Uuid58DecodeError(base58);
|
|
75
|
-
}
|
|
76
|
-
num = num * ALPHABET_LENGTH + index;
|
|
77
|
-
}
|
|
78
|
-
const hex = num.toString(16).padStart(32, "0");
|
|
79
|
-
if (hex.length !== 32) {
|
|
80
|
-
throw new Uuid58DecodeError(base58);
|
|
70
|
+
const result = uuid58DecodeSafe(base58);
|
|
71
|
+
if (result instanceof Uuid58DecodeError) {
|
|
72
|
+
throw result;
|
|
81
73
|
}
|
|
82
|
-
return
|
|
83
|
-
"-" +
|
|
84
|
-
hex.slice(8, 12) +
|
|
85
|
-
"-" +
|
|
86
|
-
hex.slice(12, 16) +
|
|
87
|
-
"-" +
|
|
88
|
-
hex.slice(16, 20) +
|
|
89
|
-
"-" +
|
|
90
|
-
hex.slice(20));
|
|
74
|
+
return result;
|
|
91
75
|
}
|
package/esm/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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/esm/encode.js
CHANGED
|
@@ -70,21 +70,9 @@ export function uuid58EncodeSafe(uuid) {
|
|
|
70
70
|
* ```
|
|
71
71
|
*/
|
|
72
72
|
export function uuid58Encode(uuid) {
|
|
73
|
-
const
|
|
74
|
-
if (
|
|
75
|
-
throw
|
|
76
|
-
}
|
|
77
|
-
let num;
|
|
78
|
-
try {
|
|
79
|
-
num = BigInt("0x" + hex);
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
throw new Uuid58EncodeError(uuid);
|
|
73
|
+
const result = uuid58EncodeSafe(uuid);
|
|
74
|
+
if (result instanceof Uuid58EncodeError) {
|
|
75
|
+
throw result;
|
|
83
76
|
}
|
|
84
|
-
|
|
85
|
-
do {
|
|
86
|
-
encoded = BASE58_ALPHABET[Number(num % ALPHABET_LENGTH)] + encoded;
|
|
87
|
-
num /= ALPHABET_LENGTH;
|
|
88
|
-
} while (num > 0n);
|
|
89
|
-
return encoded;
|
|
77
|
+
return result;
|
|
90
78
|
}
|
package/package.json
CHANGED
package/script/decode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CA4B3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
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,CA4B3E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMnD"}
|
package/script/decode.js
CHANGED
|
@@ -73,25 +73,9 @@ function uuid58DecodeSafe(base58) {
|
|
|
73
73
|
* ```
|
|
74
74
|
*/
|
|
75
75
|
function uuid58Decode(base58) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (index === undefined) {
|
|
80
|
-
throw new Uuid58DecodeError(base58);
|
|
81
|
-
}
|
|
82
|
-
num = num * alphabet_js_1.ALPHABET_LENGTH + index;
|
|
83
|
-
}
|
|
84
|
-
const hex = num.toString(16).padStart(32, "0");
|
|
85
|
-
if (hex.length !== 32) {
|
|
86
|
-
throw new Uuid58DecodeError(base58);
|
|
76
|
+
const result = uuid58DecodeSafe(base58);
|
|
77
|
+
if (result instanceof Uuid58DecodeError) {
|
|
78
|
+
throw result;
|
|
87
79
|
}
|
|
88
|
-
return
|
|
89
|
-
"-" +
|
|
90
|
-
hex.slice(8, 12) +
|
|
91
|
-
"-" +
|
|
92
|
-
hex.slice(12, 16) +
|
|
93
|
-
"-" +
|
|
94
|
-
hex.slice(16, 20) +
|
|
95
|
-
"-" +
|
|
96
|
-
hex.slice(20));
|
|
80
|
+
return result;
|
|
97
81
|
}
|
package/script/encode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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
CHANGED
|
@@ -76,21 +76,9 @@ function uuid58EncodeSafe(uuid) {
|
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
78
|
function uuid58Encode(uuid) {
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
81
|
-
throw
|
|
82
|
-
}
|
|
83
|
-
let num;
|
|
84
|
-
try {
|
|
85
|
-
num = BigInt("0x" + hex);
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
88
|
-
throw new Uuid58EncodeError(uuid);
|
|
79
|
+
const result = uuid58EncodeSafe(uuid);
|
|
80
|
+
if (result instanceof Uuid58EncodeError) {
|
|
81
|
+
throw result;
|
|
89
82
|
}
|
|
90
|
-
|
|
91
|
-
do {
|
|
92
|
-
encoded = alphabet_js_1.BASE58_ALPHABET[Number(num % alphabet_js_1.ALPHABET_LENGTH)] + encoded;
|
|
93
|
-
num /= alphabet_js_1.ALPHABET_LENGTH;
|
|
94
|
-
} while (num > 0n);
|
|
95
|
-
return encoded;
|
|
83
|
+
return result;
|
|
96
84
|
}
|