//#region src/libs/find-request.ts
/** Convert path string like '/planets/{planetId}' to regex pattern /\/planets/([^/]+)/ */
var pathToRegex = (path) => {
	const regxStr = "^" + path.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\{([^}]+)\\\}/g, "([^/]+)") + "(\\?.*)?$";
	return new RegExp(regxStr);
};
/**
* Takes a path and method and returns the request that matches the path and method while taking
* path params into account by converting to a regex. Will also return the path params if they exist.
*
* @example path can be /planets/{planetId} OR /planets/1
*/
var findRequestByPathMethod = (path, method, requests) => {
	let pathParams = [];
	return {
		request: requests.find((r) => {
			if (r.method.toLowerCase() !== method.toLowerCase()) return false;
			if (r.path === path) return true;
			const regex = pathToRegex(r.path);
			const match = path.match(regex);
			if (match) {
				pathParams = match.slice(1).flatMap((value, index) => {
					const key = r.path.split("{")[index + 1]?.split("}")[0];
					if (!key) return [];
					return [{
						key,
						value
					}];
				});
				return true;
			}
			return false;
		}),
		pathParams
	};
};
//#endregion
export { findRequestByPathMethod };

//# sourceMappingURL=find-request.js.map