If the URL is simple, don't turn it into an object. + handle null

values properly
This commit is contained in:
Kuba Orlik 2021-11-22 14:50:37 +01:00
parent 492332802f
commit 5768ac93d9

View File

@ -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 = { const object = {
[Symbol.for("originalString")]: value, // so it doesn't appear raw in the table but can be easily retrieved later [Symbol.for("originalString")]: value, // so it doesn't appear raw in the table but can be easily retrieved later
host: url.host, host: url.host,
path: url.pathname, path: url.pathname,
...Object.fromEntries( searchParams,
((url.searchParams as unknown) as {
entries: () => Iterable<[string, string]>;
}).entries()
),
...(hash === "" ? {} : typeof hash === "string" ? { hash } : hash), ...(hash === "" ? {} : typeof hash === "string" ? { hash } : hash),
}; };
return object; return object;
} else if (value === null) {
return "null";
} else { } else {
return value.toString(); return value.toString();
} }