UNPKG

badge-urls

Version:

Helper functions to generate URLs for all badges / shields from shields.io

15 lines (14 loc) 439 B
/** Converts `pathOrUrl` to a URL object. If the argument is a path, it will be prefix with the `baseUrl` */ export default function createUrl(urlOrPath, prefix) { try { return new URL(urlOrPath); } catch { return new URL(prefix + (urlOrPath.length > 0 ? urlOrPath.startsWith("/") ? urlOrPath : "/" + urlOrPath : "")); } }