lodash#chain TypeScript Examples
The following examples show how to use
lodash#chain.
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: getActionOptions.ts From next-basics with GNU General Public License v3.0 | 6 votes |
export function getActionOptions(
actions: BuiltinAction[],
recommendedIds: string[]
): ActionOptions[] {
const recommendActions = {
label: i18next.t(`${NS_NEXT_BUILDER}:${K.RECOMMENDED_ACTIONS}`),
options: actions.filter((item) => recommendedIds?.includes(item.value)),
};
const restActions = chain(
actions.filter((item) => !recommendedIds?.includes(item.value))
)
.groupBy((item) => getOptionTitle(item.value))
.map((values, key) => ({ label: key, options: values }))
.value();
return [recommendActions, ...restActions];
}
Example #2
Source File: CompareUtils.ts From kfp-tekton-backend with Apache License 2.0 | 6 votes |
/**
* Given a list of run and worklow objects, returns CompareTableProps containing parameter
* names on y axis, run names on x axis, and parameter values in rows.
* runs and workflowObjects are required to be in the same order, so workflowObject[i]
* is run[i]'s parsed workflow object
*/
public static getParamsCompareProps(
runs: ApiRunDetail[],
workflowObjects: Workflow[],
): CompareTableProps {
if (runs.length !== workflowObjects.length) {
// Should never happen
logger.error('Numbers of passed in runs and workflows do not match');
}
const yLabels = chain(flatten(workflowObjects.map(w => WorkflowParser.getParameters(w))))
.countBy(p => p.name) // count by parameter name
.map((k, v) => ({ name: v, count: k })) // convert to counter objects
.orderBy('count', 'desc') // sort on count field, descending
.map(o => o.name)
.value();
const rows = yLabels.map(name => {
return workflowObjects.map(w => {
const params = WorkflowParser.getParameters(w);
const param = params.find(p => p.name === name);
return param ? param.value || '' : '';
});
});
return {
rows,
xLabels: runs.map(r => r.run!.name!),
yLabels,
};
}
Example #3
Source File: simple-wappalyzer.ts From crossfeed with Creative Commons Zero v1.0 Universal | 5 votes |
getCookies = (str) =>
chain(str)
.castArray()
.compact()
.map(parseCookie)
.map(({ key: name, ...props }) => ({ name, ...props }))
.value()
Example #4
Source File: simple-wappalyzer.ts From crossfeed with Creative Commons Zero v1.0 Universal | 5 votes |
getScripts = (scripts) =>
chain(scripts).map('src').compact().uniq().value()
Example #5
Source File: logs.ts From grafana-chinese with Apache License 2.0 | 5 votes |
getSortedCounts = (countsByValue: { [value: string]: number }, rowCount: number) => {
return chain(countsByValue)
.map((count, value) => ({ count, value, proportion: count / rowCount }))
.sortBy('count')
.reverse()
.value();
}