UNPKG

@jiaxinjiang/nest-http

Version:

Http request component for NestJs.

57 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _ = require("lodash"); class HttpHepler { static snakeToHump(target, depth = 10) { const temp = _.cloneDeep(target); return HttpHepler._snakeToHump(temp, depth); } static _snakeToHump(target, depth = 10) { if (--depth < 0) { return; } if (_.isArray(target)) { target.forEach(item => HttpHepler._snakeToHump(item)); } else { for (const key in target) { const newKey = _.camelCase(key); if (key !== newKey) { target[newKey] = target[key]; delete target[key]; } if (typeof target[newKey] === 'object') { HttpHepler._snakeToHump(target[newKey], depth); } } } return target; } static humpToSnake(target, depth = 10) { const temp = _.cloneDeep(target); return HttpHepler._humpToSnake(temp, depth); } static _humpToSnake(target, depth = 10) { if (--depth < 0) { return; } if (_.isArray(target)) { target.forEach(item => HttpHepler._humpToSnake(item)); } else { for (const key in target) { const newKey = _.snakeCase(key); if (key !== newKey) { target[newKey] = target[key]; delete target[key]; } if (typeof target[newKey] === 'object') { HttpHepler._humpToSnake(target[newKey], depth); } } } return target; } } exports.HttpHepler = HttpHepler; //# sourceMappingURL=http.helper.js.map