UNPKG

@scalar/api-client

Version:

the open source API testing client

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