UNPKG

@scalar/api-client

Version:

the open source API testing client

67 lines (66 loc) 1.22 kB
import { combineUrlAndPath as o } from "@scalar/helpers/url/merge-urls"; function S(r, t = {}) { if (!r?.length) { const e = l(t); return e ? [e] : []; } if (!Array.isArray(r)) return []; const n = r.map((e) => b(e, t)); if (n.length === 0) { const e = l(t); return e ? [e] : []; } return n; } function i(r) { try { const t = new URL(r), n = t.port ? `:${t.port}` : ""; return `${t.protocol}//${t.hostname}${n}`; } catch { return; } } function a() { if (!(typeof window > "u" || typeof window?.location?.origin != "string")) return window.location.origin; } function f(r) { return { url: r }; } function d(r) { const t = i(r); if (t) return f(t); } function m() { const r = a(); if (r) return f(r); } function U(r, t) { const { baseServerUrl: n, documentUrl: e } = t; if (n) return o(n, r); if (e) { const u = i(e); if (u) return o(u, r); } const c = a(); return c ? o(c, r) : r; } function b(r, t) { return r.url?.startsWith("/") && (r.url = U(r.url, t)), r; } function l(r) { if (r.documentUrl) { const t = d(r.documentUrl); if (t) return t; } return m(); } export { S as getServers };