no-hassle
Version:
Makes Node.js route handling easy with support for [Joi schema](https://github.com/hapijs/joi) validation and automatic Swagger generation based on these schema definitions. Uses Expressjs routing mechanism.
24 lines (23 loc) • 898 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertNever = exports.getTransformedPath = exports.makeRemovePrefix = exports.cleanPath = void 0;
const cleanPath = (path) => path.replace(/:+/g, '{').replace(/({+\w+)()/g, '$1}$2');
exports.cleanPath = cleanPath;
const makeRemovePrefix = (prefix) => (path) => {
const prefixRegex = new RegExp(`^${prefix}`);
const newPath = path.replace(prefixRegex, '');
if (newPath === '') {
return '/';
}
return newPath;
};
exports.makeRemovePrefix = makeRemovePrefix;
const getTransformedPath = (path, transformPath = path => path) => {
const cleanedPath = (0, exports.cleanPath)(path);
return transformPath(cleanedPath);
};
exports.getTransformedPath = getTransformedPath;
const assertNever = (x) => {
throw new Error(`Unexpected object: ${x}`);
};
exports.assertNever = assertNever;