mirror of
https://github.com/Lissy93/web-check.git
synced 2026-05-15 04:00:04 -04:00
18 lines
516 B
JavaScript
18 lines
516 B
JavaScript
// Normalise a user-supplied target, stripping :port for DNS lookups
|
|
export const parseTarget = (input) => {
|
|
if (!input) throw new Error('No target provided');
|
|
const normalised = /^https?:\/\//i.test(input) ? input : `https://${input}`;
|
|
let u;
|
|
try { u = new URL(normalised); }
|
|
catch { throw new Error(`Invalid URL: ${input}`); }
|
|
return {
|
|
hostname: u.hostname,
|
|
port: u.port || null,
|
|
protocol: u.protocol,
|
|
pathname: u.pathname || '/',
|
|
href: u.href,
|
|
};
|
|
};
|
|
|
|
export default parseTarget;
|