import { sortBy as lodashSort } from 'lodash'; import angularExpressions from 'angular-expressions'; export function findElement(input: T[], attribute: string, value: K): T | string { if (!input) return ''; return input.find((obj: any) => obj[attribute] === value) || ''; } export function sortBy(input: T[], ...fields: any[]) { // In our example fields is ["price"] // Make sure that if your input is undefined, your // output will be undefined as well and will not // throw an error if (!input) return input; return lodashSort(input, fields); } export function where(input: T[], query: any) { return input.filter(function (item) { return angularExpressions.compile(query)(item); }); }