camel-case.js
692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* 对象键名驼峰化
* @author: Bi Kai<kai.bi@yoho.cn>
* @date: 2016/05/09
*/
'use strict';
const _ = require('lodash');
let camelCase,
camelCaseObject,
camelCaseArray;
camelCaseObject = (obj) => {
_.forEach(Object.keys(obj), (k) => {
obj[k] = camelCase(obj[k]);
obj[_.camelCase(k)] = obj[k];
});
return obj;
};
camelCaseArray = (list) => {
_.forEach(list, (k) => {
k = camelCase(k);
});
return list;
};
camelCase = (data) => {
if (_.isObject(data)) {
data = camelCaseObject(data);
}
if (_.isArray(data)) {
data = camelCaseArray(data);
}
return data;
};
module.exports = camelCase;