Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -2,8 +2,6 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
/**
* An interface for a JavaScript object that
@@ -47,7 +45,7 @@ export function size<T>(from: IStringDictionary<T> | INumberDictionary<T>): numb
return count;
}
export function first<T>(from: IStringDictionary<T> | INumberDictionary<T>): T {
export function first<T>(from: IStringDictionary<T> | INumberDictionary<T>): T | undefined {
for (let key in from) {
if (hasOwnProperty.call(from, key)) {
return from[key];
@@ -73,18 +71,6 @@ export function forEach<T>(from: IStringDictionary<T> | INumberDictionary<T>, ca
}
}
/**
* Removes an element from the dictionary. Returns {{false}} if the property
* does not exists.
*/
export function remove<T>(from: IStringDictionary<T> | INumberDictionary<T>, key: string): boolean {
if (!hasOwnProperty.call(from, key)) {
return false;
}
delete (from as any)[key];
return true;
}
/**
* Groups the collection into a dictionary based on the provided
* group function.
@@ -101,3 +87,13 @@ export function groupBy<T>(data: T[], groupFn: (element: T) => string): IStringD
}
return result;
}
export function fromMap<T>(original: Map<string, T>): IStringDictionary<T> {
const result: IStringDictionary<T> = Object.create(null);
if (original) {
original.forEach((value, key) => {
result[key] = value;
});
}
return result;
}