remove lodash dependency

fixes #19438
This commit is contained in:
Joao Moreno
2017-01-26 14:56:08 +01:00
parent e0537cbc89
commit 5690a47892
8 changed files with 50 additions and 22747 deletions

View File

@@ -57,4 +57,35 @@ export function once<T>(event: Event<T>): Event<T> {
export function eventToPromise<T>(event: Event<T>): Promise<T> {
return new Promise(c => once(event)(c));
}
export function assign<T>(destination: T, ...sources: any[]): T {
for (const source of sources) {
Object.keys(source).forEach(key => destination[key] = source[key]);
}
return destination;
}
export function uniqBy<T>(arr: T[], fn: (el: T) => string): T[] {
const seen = Object.create(null);
return arr.filter(el => {
const key = fn(el);
if (seen[key]) {
return false;
}
seen[key] = true;
return true;
});
}
export function groupBy<T>(arr: T[], fn: (el: T) => string): { [key: string]: T[] } {
return arr.reduce((result, el) => {
const key = fn(el);
result[key] = [...(result[key] || []), el];
return result;
}, Object.create(null));
}