lodash-es#reduce TypeScript Examples
The following examples show how to use
lodash-es#reduce.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts From yarn-audit-fix with MIT License | 7 votes |
formatFlags = (flags: TFlags, ...picklist: string[]): string[] =>
Object.keys(flags).reduce<string[]>((memo, key: string) => {
const omitlist = ['_', '--']
const value = flags[key]
const flag = formatFlag(key)
if (checkValue(key, value, omitlist, picklist)) {
memo.push(flag)
if (value !== true) {
memo.push(value)
}
}
return memo
}, [])
Example #2
Source File: util.ts From yarn-audit-fix with MIT License | 7 votes |
mapFlags = (flags: TFlags, mapping: TFlagsMapping): TFlags =>
reduce(
flags,
(memo: TFlags, value: any, key: string) => {
const repl = mapping[key]
let k = key
let v = value
if (repl) {
if (typeof repl === 'string') {
k = repl
} else {
k = repl?.key ?? k
v = repl?.value ?? repl?.values?.[value] ?? v
}
}
memo[k] = v
return memo
},
{},
)
Example #3
Source File: util.ts From yarn-audit-fix with MIT License | 6 votes |
normalizeFlags = (flags: TFlags): TFlags =>
Object.keys(flags).reduce<TFlags>((m, key) => {
m[camelToKebab(key)] = flags[key]
return m
}, {})