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