@nakanoaas/uuid58 0.0.2 → 0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAK/B,MAAM,EAAE,MAAM;CAG3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAuBnD"}
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAK/B,MAAM,EAAE,MAAM;CAG3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA0BnD"}
package/esm/decode.js CHANGED
@@ -31,14 +31,18 @@ _a = InvalidBase58Error;
31
31
  * ```
32
32
  */
33
33
  export function uuid58Decode(base58) {
34
- if (!/^[1-9A-HJ-NP-Za-km-z]+$/.test(base58)) {
35
- throw new InvalidBase58Error(base58);
36
- }
37
34
  let num = 0n;
38
35
  for (const char of base58) {
39
- num = num * ALPHABET_LENGTH + BASE58_MAP[char];
36
+ const index = BASE58_MAP[char];
37
+ if (index === undefined) {
38
+ throw new InvalidBase58Error(base58);
39
+ }
40
+ num = num * ALPHABET_LENGTH + index;
40
41
  }
41
42
  const hex = num.toString(16).padStart(32, "0");
43
+ if (hex.length !== 32) {
44
+ throw new InvalidBase58Error(base58);
45
+ }
42
46
  return (hex.slice(0, 8) +
43
47
  "-" +
44
48
  hex.slice(8, 12) +
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAK7B,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAejD"}
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAK7B,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBjD"}
package/esm/encode.js CHANGED
@@ -34,10 +34,16 @@ _a = InvalidUuidError;
34
34
  */
35
35
  export function uuid58Encode(uuid) {
36
36
  const hex = uuid.replace(/-/g, "").toLowerCase();
37
- if (!/^[0-9a-f]{32}$/.test(hex)) {
37
+ if (hex.length !== 32) {
38
+ throw new InvalidUuidError(uuid);
39
+ }
40
+ let num;
41
+ try {
42
+ num = BigInt("0x" + hex);
43
+ }
44
+ catch {
38
45
  throw new InvalidUuidError(uuid);
39
46
  }
40
- let num = BigInt("0x" + hex);
41
47
  let encoded = "";
42
48
  do {
43
49
  const rem = Number(num % ALPHABET_LENGTH);
package/esm/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { uuid58Decode } from "./decode.js";
2
- export { uuid58Encode } from "./encode.js";
3
- export { uuid58 } from "./uuid58.js";
1
+ export * from "./decode.js";
2
+ export * from "./encode.js";
3
+ export * from "./uuid58.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { uuid58Decode } from "./decode.js";
2
- export { uuid58Encode } from "./encode.js";
3
- export { uuid58 } from "./uuid58.js";
1
+ export * from "./decode.js";
2
+ export * from "./encode.js";
3
+ export * from "./uuid58.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakanoaas/uuid58",
3
- "version": "0.0.2",
3
+ "version": "0.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",
@@ -1 +1 @@
1
- {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAK/B,MAAM,EAAE,MAAM;CAG3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAuBnD"}
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAK/B,MAAM,EAAE,MAAM;CAG3B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA0BnD"}
package/script/decode.js CHANGED
@@ -36,14 +36,18 @@ _a = InvalidBase58Error;
36
36
  * ```
37
37
  */
38
38
  function uuid58Decode(base58) {
39
- if (!/^[1-9A-HJ-NP-Za-km-z]+$/.test(base58)) {
40
- throw new InvalidBase58Error(base58);
41
- }
42
39
  let num = 0n;
43
40
  for (const char of base58) {
44
- num = num * alphabet_js_1.ALPHABET_LENGTH + BASE58_MAP[char];
41
+ const index = BASE58_MAP[char];
42
+ if (index === undefined) {
43
+ throw new InvalidBase58Error(base58);
44
+ }
45
+ num = num * alphabet_js_1.ALPHABET_LENGTH + index;
45
46
  }
46
47
  const hex = num.toString(16).padStart(32, "0");
48
+ if (hex.length !== 32) {
49
+ throw new InvalidBase58Error(base58);
50
+ }
47
51
  return (hex.slice(0, 8) +
48
52
  "-" +
49
53
  hex.slice(8, 12) +
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAK7B,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAejD"}
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAK7B,IAAI,EAAE,MAAM;CAGzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBjD"}
package/script/encode.js CHANGED
@@ -39,10 +39,16 @@ _a = InvalidUuidError;
39
39
  */
40
40
  function uuid58Encode(uuid) {
41
41
  const hex = uuid.replace(/-/g, "").toLowerCase();
42
- if (!/^[0-9a-f]{32}$/.test(hex)) {
42
+ if (hex.length !== 32) {
43
+ throw new InvalidUuidError(uuid);
44
+ }
45
+ let num;
46
+ try {
47
+ num = BigInt("0x" + hex);
48
+ }
49
+ catch {
43
50
  throw new InvalidUuidError(uuid);
44
51
  }
45
- let num = BigInt("0x" + hex);
46
52
  let encoded = "";
47
53
  do {
48
54
  const rem = Number(num % alphabet_js_1.ALPHABET_LENGTH);
package/script/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { uuid58Decode } from "./decode.js";
2
- export { uuid58Encode } from "./encode.js";
3
- export { uuid58 } from "./uuid58.js";
1
+ export * from "./decode.js";
2
+ export * from "./encode.js";
3
+ export * from "./uuid58.js";
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/script/index.js CHANGED
@@ -1,9 +1,19 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuid58 = exports.uuid58Encode = exports.uuid58Decode = void 0;
4
- var decode_js_1 = require("./decode.js");
5
- Object.defineProperty(exports, "uuid58Decode", { enumerable: true, get: function () { return decode_js_1.uuid58Decode; } });
6
- var encode_js_1 = require("./encode.js");
7
- Object.defineProperty(exports, "uuid58Encode", { enumerable: true, get: function () { return encode_js_1.uuid58Encode; } });
8
- var uuid58_js_1 = require("./uuid58.js");
9
- Object.defineProperty(exports, "uuid58", { enumerable: true, get: function () { return uuid58_js_1.uuid58; } });
17
+ __exportStar(require("./decode.js"), exports);
18
+ __exportStar(require("./encode.js"), exports);
19
+ __exportStar(require("./uuid58.js"), exports);