UNPKG

@scalar/api-client

Version:

the open source API testing client

43 lines (42 loc) 1.12 kB
import { REGEX as l, isDefined as a } from "@scalar/oas-utils/helpers"; function i(c, o) { const s = c.split(".").reduce((u, r) => u?.[r], o); return typeof s == "string" ? s : JSON.stringify(s); } function p(c, o) { let t = c; const s = /* @__PURE__ */ new Set(); return t = t.replace(l.VARIABLES, (u, r) => { const e = r.trim(); s.add(e); const n = i(e, o); return a(n) && n !== "" ? n : `{{${e}}}`; }), t = t.replace(l.PATH, (u, r) => { const e = r.trim(); if (s.has(e)) return `{${e}}`; const n = i(e, o); return a(n) && n !== "" ? n : `{${e}}`; }), t = t.replace(/:\b[\w.]+\b/g, (u) => { const r = u.slice(1); if (s.has(r)) return u; const e = i(r, o); return a(e) && e !== "" ? e : u; }), t; } function y(c) { function o(t, s) { const u = Object.keys(t), r = []; return u.forEach((e) => { const n = s ? `${s}.${e}` : e; typeof t[e] == "object" ? r.push(...o(t[e], n)) : r.push([n, String(t[e])]); }), r; } return o(c); } export { y as flattenEnvVars, i as getDotPathValue, p as replaceTemplateVariables };