UNPKG

1.81 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const _ = require("lodash");
4class HttpHepler {
5 static snakeToHump(target, depth = 10) {
6 const temp = _.cloneDeep(target);
7 return HttpHepler._snakeToHump(temp, depth);
8 }
9 static _snakeToHump(target, depth = 10) {
10 if (--depth < 0) {
11 return;
12 }
13 if (_.isArray(target)) {
14 target.forEach(item => HttpHepler._snakeToHump(item));
15 }
16 else {
17 for (const key in target) {
18 const newKey = _.camelCase(key);
19 if (key !== newKey) {
20 target[newKey] = target[key];
21 delete target[key];
22 }
23 if (typeof target[newKey] === 'object') {
24 HttpHepler._snakeToHump(target[newKey], depth);
25 }
26 }
27 }
28 return target;
29 }
30 static humpToSnake(target, depth = 10) {
31 const temp = _.cloneDeep(target);
32 return HttpHepler._humpToSnake(temp, depth);
33 }
34 static _humpToSnake(target, depth = 10) {
35 if (--depth < 0) {
36 return;
37 }
38 if (_.isArray(target)) {
39 target.forEach(item => HttpHepler._humpToSnake(item));
40 }
41 else {
42 for (const key in target) {
43 const newKey = _.snakeCase(key);
44 if (key !== newKey) {
45 target[newKey] = target[key];
46 delete target[key];
47 }
48 if (typeof target[newKey] === 'object') {
49 HttpHepler._humpToSnake(target[newKey], depth);
50 }
51 }
52 }
53 return target;
54 }
55}
56exports.HttpHepler = HttpHepler;
57//# sourceMappingURL=http.helper.js.map
\No newline at end of file