/**
* @description - override defaults params with external, which should skip undefined override
* @author - huang.jian <hjj491229492@hotmail.com>
*
* @param {object} params - param from cli, maybe undefined value
* @param {object} defaults - base params
*
* @todo - params validate
*/
function compose(params, defaults = {}) {
const keys = Reflect.ownKeys(params).filter((key) => Reflect.get(params, key));
const usefulParams = keys.reduce((acc, key) => Object.assign(
{}, acc, { [key]: Reflect.get(params, key) })
, {}
);
return Object.assign({}, defaults, usefulParams);
}
module.exports = compose;
|