X-Git-Url: https://git.xangelo.ca/?a=blobdiff_plain;f=src%2Flib%2Futil.ts;h=03aed1557bdc804fb2034529067b87f007eb87a8;hb=c8be7767524bb249b44cc05bb2cd8be15ae7bc85;hp=ebe84e5a4fac8d734d211d64f4034c7df27146fe;hpb=516deaa637cb322ddbb4fb9121d56d23fef5d7a8;p=browser-rts.git diff --git a/src/lib/util.ts b/src/lib/util.ts index ebe84e5..03aed15 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -1,9 +1,20 @@ -export function coalesce(...args: any[]): any { +import { isEmpty } from 'lodash'; + +export function coalesce(...args) { let found; while(args.length) { found = args.shift(); - if(found !== null && found !== undefined && found !== '') { + if(found !== null && found !== undefined && !isEmpty(found)) { return found; } } -} \ No newline at end of file +} + +export function pluck(arr: T[], field: string): Map { + const map = new Map(); + arr.forEach(obj => { + map[obj[field]] = obj; + }); + + return map; +}