feat(commons): url validate

main
Lei OT 3 months ago
parent 80817b0e28
commit 36689676a3

@ -922,3 +922,16 @@ export const buildTree = (list, keyMap = { rootKeys: [], ignoreKeys: [] }) => {
return treeRoots; return treeRoots;
}; };
export const isValidUrl = (str) => {
if (typeof str !== "string") return false;
try {
// If no protocol, prepend "http://"
const hasProtocol = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(str);
new URL(hasProtocol ? str : `http://${str}`);
return true;
} catch {
return false;
}
}

Loading…
Cancel
Save