UNPKG

aspida-mock

Version:

TypeScript friendly RESTful API mock for aspida

32 lines 1.09 kB
export const createPathRegExp = (path) => new RegExp(`^${path.replace(/\/_[^./]+/g, '/[^/]+').replace('.', '\\.')}$`); export const httpMethods = [ 'get', 'post', 'put', 'delete', 'head', 'options', 'patch', ]; export const copyData = (res) => { const { resBody } = res; return resBody === null || typeof resBody !== 'object' || (!Array.isArray(resBody) && Object.getPrototypeOf(resBody) !== Object.prototype) ? res : { ...res, resBody: JSON.parse(JSON.stringify(resBody)) }; }; export const createValues = (path, relativePath) => { const values = {}; const dirList = path.split('/'); const parsedRequestUrl = relativePath.split('/'); parsedRequestUrl.forEach((dir, i) => { if (dirList[i].startsWith('_')) { const [valueName, type = 'number'] = dirList[i].slice(1).split('@'); const val = dir.split('.')[0]; values[valueName.split('.')[0]] = isNaN(+val) || type !== 'number' ? val : +val; } }); return values; }; //# sourceMappingURL=utils.js.map