UNPKG

@nodearch/express

Version:
54 lines 1.54 kB
import { ComponentFactory } from '@nodearch/core/components'; import { ExpressDecorator } from './enums.js'; export function httpPathFactory(path) { return ComponentFactory.classDecorator({ id: ExpressDecorator.HTTP_PATH, fn: (target) => { return { httpPath: getPath(path) }; } }); } export function httpMethodFactory(httpMethod, path) { return ComponentFactory.methodDecorator({ id: ExpressDecorator.HTTP_METHOD, fn: (target, propKey) => { return { name: propKey, httpMethod, httpPath: getPath(path) }; } }); } export function handlerParamFactory(paramType, key) { return ComponentFactory.parameterDecorator({ id: ExpressDecorator.HTTP_PARAM, fn: (target, propKey, paramIndex) => { return { index: paramIndex, type: paramType, key }; } }); } export function getPath(path) { let routePath = '/'; if (path) { routePath = path.charAt(0) === '/' ? path : '/' + path; } return routePath; } export function getRouterPrefix(path) { if (path === '') { return path; } else { let routePath = path.charAt(path.length - 1) === '/' ? path.slice(0, path.length - 1) : path; routePath = routePath.charAt(0) === '/' ? routePath : '/' + routePath; return routePath; } } //# sourceMappingURL=helpers.js.map