mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-04-27 17:15:51 +00:00
36 lines
700 B
JavaScript
36 lines
700 B
JavaScript
"use strict";
|
|
|
|
/**
|
|
* Returns a normalized http(s) or mailto URL suitable for shell.openExternal,
|
|
* or null if the input must not be handed to the OS shell.
|
|
* @param {unknown} raw
|
|
* @returns {string|null}
|
|
*/
|
|
function normalizeExternalUrlForOpen(raw) {
|
|
if (typeof raw !== "string") {
|
|
return null;
|
|
}
|
|
const s = raw.trim();
|
|
if (!s) {
|
|
return null;
|
|
}
|
|
let u;
|
|
try {
|
|
u = new URL(s);
|
|
} catch {
|
|
return null;
|
|
}
|
|
const p = u.protocol;
|
|
if (p === "http:" || p === "https:") {
|
|
return u.href;
|
|
}
|
|
if (p === "mailto:") {
|
|
return u.href;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
module.exports = {
|
|
normalizeExternalUrlForOpen,
|
|
};
|