From a637a2ec9ad964ae2a701c85c606fc8715ee4b28 Mon Sep 17 00:00:00 2001 From: Nityam Savaliya Date: Fri, 4 Sep 2026 09:08:15 +0530 Subject: [PATCH 1/3] test: add parseId to smoke tests --- scripts/browser-smoke.html | 25 +++++++++++++++++++++++++ scripts/smoke.cjs | 19 +++++++++++++++++++ scripts/smoke.mjs | 17 +++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/scripts/browser-smoke.html b/scripts/browser-smoke.html index 8cfc21c..14f3085 100644 --- a/scripts/browser-smoke.html +++ b/scripts/browser-smoke.html @@ -12,24 +12,29 @@ padding: 2rem; line-height: 1.6; } + #status { font-size: 1.25rem; font-weight: bold; } + pre { background: #1e293b; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; } + .ok { color: #4ade80; } + .fail { color: #f87171; } +
Running…

@@ -42,6 +47,7 @@
         getTimestamp,
         id,
         isId,
+        parseId,
         sortableId,
         template,
       } from "../dist/index.js";
@@ -56,6 +62,25 @@
         if (!isId(uid, "user")) throw new Error("id() failed");
         lines.push(`id("user")            -> ${uid}`);
         lines.push(`getPrefix(...)        -> ${getPrefix(uid)}`);
+
+        const parsed = parseId(uid);
+        if (
+          !parsed ||
+          parsed.prefix !== "user" ||
+          parsed.id !== uid.substring(5)
+        ) {
+          throw new Error("parseId() round-trip failed");
+        }
+        if (parseId("nosep") !== undefined) {
+          throw new Error("parseId() nosep failed");
+        }
+        if (parseId(null) !== undefined) {
+          throw new Error("parseId() null failed");
+        }
+        lines.push(
+          `parseId(...)          -> { prefix: "${parsed.prefix}", id: "${parsed.id}" }`,
+        );
+
         lines.push(
           `createId({ size: 8 }) -> ${createId({ size: 8 })("order")}`,
         );
diff --git a/scripts/smoke.cjs b/scripts/smoke.cjs
index f52e73b..fe89b49 100644
--- a/scripts/smoke.cjs
+++ b/scripts/smoke.cjs
@@ -1,6 +1,7 @@
 const {
   id,
   isId,
+  parseId,
   getPrefix,
   sortableId,
   getTimestamp,
@@ -15,6 +16,24 @@ if (!isId(uid, "user") || getPrefix(uid) !== "user") {
   process.exit(1);
 }
 
+const parsed = parseId(uid);
+if (!parsed || parsed.prefix !== "user" || parsed.id !== uid.substring(5)) {
+  console.error("smoke failed: parseId() should round-trip a generated id");
+  process.exit(1);
+}
+if (parseId("nosep") !== undefined) {
+  console.error(
+    "smoke failed: parseId() should return undefined when separator is missing",
+  );
+  process.exit(1);
+}
+if (parseId(null) !== undefined) {
+  console.error(
+    "smoke failed: parseId() should return undefined for non-string input",
+  );
+  process.exit(1);
+}
+
 const sid = sortableId("evt");
 if (
   !isId(sid, "evt") ||
diff --git a/scripts/smoke.mjs b/scripts/smoke.mjs
index 0f307c8..9671033 100644
--- a/scripts/smoke.mjs
+++ b/scripts/smoke.mjs
@@ -9,6 +9,7 @@ import {
   getTimestampOrThrow,
   id,
   isId,
+  parseId,
   sortableId,
   template,
 } from "prefid";
@@ -30,6 +31,22 @@ const uid = id("user");
 assert(isId(uid, "user"), "id() should produce a user_ id");
 assert(getPrefix(uid) === "user", "getPrefix() should return the prefix");
 
+const parsed = parseId(uid);
+assert(
+  parsed !== undefined &&
+    parsed.prefix === "user" &&
+    parsed.id === uid.substring(5),
+  "parseId() should round-trip a generated id",
+);
+assert(
+  parseId("nosep") === undefined,
+  "parseId() should return undefined when separator is missing",
+);
+assert(
+  parseId(null) === undefined,
+  "parseId() should return undefined for non-string input",
+);
+
 const short = createId({ size: 8 })("order");
 assert(short.length === "order_".length + 8, "createId({ size }) length");
 

From 4e5d340373a02bfcd9873d693c7f01f35aa41ecf Mon Sep 17 00:00:00 2001
From: Nityam Savaliya 
Date: Fri, 4 Sep 2026 10:18:29 +0530
Subject: [PATCH 2/3] style: remove extra spaces in browser-smoke.html

---
 scripts/browser-smoke.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/browser-smoke.html b/scripts/browser-smoke.html
index 14f3085..e05482c 100644
--- a/scripts/browser-smoke.html
+++ b/scripts/browser-smoke.html
@@ -78,7 +78,7 @@
           throw new Error("parseId() null failed");
         }
         lines.push(
-          `parseId(...)          -> { prefix: "${parsed.prefix}", id: "${parsed.id}" }`,
+          `parseId(...)        -> { prefix: "${parsed.prefix}", id: "${parsed.id}" }`,
         );
 
         lines.push(

From fe59e6ca4e5148923a77831f229cca059ede41cb Mon Sep 17 00:00:00 2001
From: suhailopensource 
Date: Fri, 4 Sep 2026 10:22:33 +0530
Subject: [PATCH 3/3] style: drop unrelated blank lines from browser-smoke.html

---
 scripts/browser-smoke.html | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/scripts/browser-smoke.html b/scripts/browser-smoke.html
index e05482c..ceedb76 100644
--- a/scripts/browser-smoke.html
+++ b/scripts/browser-smoke.html
@@ -12,29 +12,24 @@
         padding: 2rem;
         line-height: 1.6;
       }
-
       #status {
         font-size: 1.25rem;
         font-weight: bold;
       }
-
       pre {
         background: #1e293b;
         padding: 1rem;
         border-radius: 0.5rem;
         overflow-x: auto;
       }
-
       .ok {
         color: #4ade80;
       }
-
       .fail {
         color: #f87171;
       }
     
   
-
   
     
Running…