UNPKG

@4players/odin-common

Version:

A collection of commonly used type definitions and utility functions across ODIN web projects

24 lines (23 loc) 603 B
import { failure, success } from './result'; export function normalizeUrl(url) { let normalized = url.trim(); if (url.indexOf('://') === -1) normalized = `https://${normalized}`; try { return success(new URL(normalized)); } catch (error) { return failure(String(error)); } } export function extendUrl(base, path) { let pathname = base.pathname; if (pathname.endsWith('/') === false) pathname += '/'; try { return success(new URL(pathname + path, base)); } catch (error) { return failure(String(error)); } }