All files util.js

77.78% Statements 7/9
0% Branches 0/1
60% Functions 3/5
83.33% Lines 5/6
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            1x 1x               1x               1x               1x                
/**
 * 合并普通的js对象
 * @param prev
 * @param next
 * @return {{}}
 */
const mergePlainObject = function (prev, next) {
    return ({...prev, ...next})
}
 
/**
 * 循环key
 * @param target
 * @return {string[]}
 */
const mapKeys = (target) => Object.keys(target)
 
/**
 * 创建新的key
 * @param namespace
 * @param key
 * @return {string}
 */
const createNewKeyStr = (namespace, key) => `${namespace}/${key}`
 
/**
 * 根据namespace重命名普通的js对象的key
 * @param namespace
 * @param plainObject
 * @return {{[p: string]: *}}
 */
const renamePlainObjectKey = (namespace, plainObject = {}) =>
    mapKeys(plainObject).map((key) => ({[createNewKeyStr(namespace, key)]: plainObject[key]})).reduce(mergePlainObject, {})
 
export {
    mergePlainObject,
    mapKeys,
    createNewKeyStr,
    renamePlainObjectKey
}