@4players/odin-common
Version:
A collection of commonly used type definitions and utility functions across ODIN web projects
28 lines (27 loc) • 783 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeUrl = normalizeUrl;
exports.extendUrl = extendUrl;
const result_1 = require("./result");
function normalizeUrl(url) {
let normalized = url.trim();
if (url.indexOf('://') === -1)
normalized = `https://${normalized}`;
try {
return (0, result_1.success)(new URL(normalized));
}
catch (error) {
return (0, result_1.failure)(String(error));
}
}
function extendUrl(base, path) {
let pathname = base.pathname;
if (pathname.endsWith('/') === false)
pathname += '/';
try {
return (0, result_1.success)(new URL(pathname + path, base));
}
catch (error) {
return (0, result_1.failure)(String(error));
}
}