mirror of
https://github.com/hanzoai/trpc-openapi.git
synced 2026-10-30 18:18:55 +00:00
12 lines
478 B
JavaScript
12 lines
478 B
JavaScript
export const normalizePath = (path) => {
|
|
return `/${path.replace(/^\/|\/$/g, '')}`;
|
|
};
|
|
export const getPathParameters = (path) => {
|
|
return Array.from(path.matchAll(/\{(.+?)\}/g)).map(([, key]) => key);
|
|
};
|
|
export const getPathRegExp = (path) => {
|
|
const escapedPath = path.replace(/\./g, '\\.');
|
|
const groupedExp = escapedPath.replace(/\{(.+?)\}/g, (_, key) => `(?<${key}>[^/]+)`);
|
|
return new RegExp(`^${groupedExp}$`, 'i');
|
|
};
|
|
//# sourceMappingURL=path.js.map
|