function getValueByKeys(
value,
keys,
filterFn = (v) => v !== void 0
) {
if (keys.length === 0) return value;
return keys.reduce((res, key) => {
console.log(key,'keys')
if ((key) instanceof Array) {
const v = getFirstNoUndefinedValue(
getValueByKeys(value, key),
key
);
console.log(v,'v',filterFn(v),'filterFn(v) ')
filterFn(v) && (res[key[0]] = v);
return res;
}
if (value.hasOwnProperty(key)) {
filterFn(value[key]) &&
(res[key] = value[key]);
console.log(value,'value',key,'key')
}
console.log(res,'res')
return res;
}, {});
}
function getFirstNoUndefinedValue(
value,
sortKeys
) {
const isArray = Array.isArray(value);
const keys = (
isArray ? value : sortKeys || Object.keys(value)
);
console.log(keys, 'get first no undefined')
if (!keys) return "";
for (let i = 0, len = keys.length; i < len; i++) {
const key = isArray ? i : keys[i];
if (value[key] !== undefined) {
console.log(keys[i],'keys[i]',i,'isArry')
return value[key];
}
}
}
const envArgs = {d:'描述啊啊啊',qrf:'二维码生成样式',qrd:'C:\\/Users/data/output',p:'/pages/index/index',q:["key","value"]}
getValueByKeys(envArgs, [
["desc", "d"],
["robot", "r"],
["qrcodeFormat", "qrFormat", "qrf"],
["qrcodeOutputDest", "qrDest", "qrd"],
["pagePath", "pp", "p"],
["searchQuery", "sq", "q"],
])
console