UNPKG

@scalar/api-client

Version:

the open source API testing client

24 lines (23 loc) 696 B
const f = (e) => { const r = "^" + // start anchor e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{([^}]+)\\\}/g, "([^/]+)") + // replace {param} with capture group "(\\?.*)?$"; return new RegExp(r); }, i = (e, r, o) => { let n = []; return { request: o.find((t) => { if (t.method.toLowerCase() !== r.toLowerCase()) return !1; if (t.path === e) return !0; const u = f(t.path), s = e.match(u); return s ? (n = s.slice(1).flatMap((c, p) => { const a = t.path.split("{")[p + 1]?.split("}")[0]; return a ? [{ key: a, value: c }] : []; }), !0) : !1; }), pathParams: n }; }; export { i as findRequestByPathMethod, f as pathToRegex };