@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 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
 
@@ -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,CA0BnD"}
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
- let num = 0n;
71
- for (const char of base58) {
72
- const index = BASE58_MAP[char];
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 (hex.slice(0, 8) +
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
  }
@@ -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,CAoBjD"}
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 hex = uuid.replaceAll("-", "");
74
- if (hex.length !== 32) {
75
- throw new Uuid58EncodeError(uuid);
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
- let encoded = "";
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakanoaas/uuid58",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A tiny, zero-dependency library for generating and converting UUIDs to Base58-encoded strings.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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,CA0BnD"}
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
- let num = 0n;
77
- for (const char of base58) {
78
- const index = BASE58_MAP[char];
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 (hex.slice(0, 8) +
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
  }
@@ -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,CAoBjD"}
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 hex = uuid.replaceAll("-", "");
80
- if (hex.length !== 32) {
81
- throw new Uuid58EncodeError(uuid);
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
- let encoded = "";
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
  }