camel-case.js 719 Bytes
/**
 * 对象键名驼峰化
 * @author: Bi Kai<kai.bi@yoho.cn>
 * @date: 2016/05/09
 */

const _ = require('lodash');

/**
 * 对象键值驼峰化(未测试)
 * @param  {[object]} obj
 * @return {[object]}
 */
const camelCase = (obj) => {
    _.forEach(obj, (k) => {
        obj[_.camelCase(k)] = obj[k]; // 下划线变量名转换为驼峰
    });

    return obj;
};

/**
 * 对象数组,对象键值驼峰化
 * @param  {[type]} list
 * @return {[type]}
 */
const listCamelCase = (list) => {
    _.forEach(Object.keys(list), (k) => {
        list[_.camelCase(k)] = list[k]; // 下划线变量名转换为驼峰
    });

    return list;
};

exports.camelCase = camelCase;
exports.listCamelCase = listCamelCase;