From 5768ac93d908a99bf0c5e030891cf7d240fe5359 Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Mon, 22 Nov 2021 14:50:37 +0100 Subject: [PATCH] If the URL is simple, don't turn it into an object. + handle null values properly --- stolen-data-entry.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/stolen-data-entry.ts b/stolen-data-entry.ts index 53aac79..3b6b2b1 100644 --- a/stolen-data-entry.ts +++ b/stolen-data-entry.ts @@ -103,18 +103,24 @@ export class StolenDataEntry extends EventEmitter { ); } } + const searchParams = Object.fromEntries( + ((url.searchParams as unknown) as { + entries: () => Iterable<[string, string]>; + }).entries() + ); + if (typeof hash !== "object" && Object.keys(searchParams).length === 0) { + return value; // just a string; + } const object = { [Symbol.for("originalString")]: value, // so it doesn't appear raw in the table but can be easily retrieved later host: url.host, path: url.pathname, - ...Object.fromEntries( - ((url.searchParams as unknown) as { - entries: () => Iterable<[string, string]>; - }).entries() - ), + searchParams, ...(hash === "" ? {} : typeof hash === "string" ? { hash } : hash), }; return object; + } else if (value === null) { + return "null"; } else { return value.toString(); }