import { match, pathToRegexp } from 'path-to-regexp' import {MockContext, MockMethod} from "./types"; interface MockItemNormalized { url: string method: string regex: RegExp match: (path: string) => Record | null timeout?: number statusCode?: number response?: (ctx: MockContext) => T } const mockItems: MockItemNormalized[] = [] export function setMockData(data: MockMethod) { mockItems.push({ ...data, method: ((data.method ?? 'get') as string).toUpperCase(), regex: pathToRegexp(data.url), match(path: string): Record | null { const urlMatch = match(data.url, { decode: decodeURIComponent }) const res = urlMatch(path) if (!res) return null return res.params as Record }, }) }