UNPKG

@scalar/api-client

Version:

the open source API testing client

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