@azure-tools/linq
Advanced tools
Comparing version 3.1.201 to 3.1.203
@@ -18,2 +18,5 @@ import { IndexOf, Dictionary } from './common'; | ||
results(): Promise<void>; | ||
toDictionary<TValue>(keySelector: (each: T) => string, selector: (each: T) => TValue): Dictionary<TValue>; | ||
toMap<TKey, TValue>(keySelector: (each: T) => TKey, selector: (each: T) => TValue): Map<TKey, TValue>; | ||
groupBy<TKey, TValue>(keySelector: (each: T) => TKey, selector: (each: T) => TValue): Map<TKey, Array<TValue>>; | ||
/** | ||
@@ -30,3 +33,6 @@ * Gets or sets the length of the iterable. This is a number one higher than the highest element defined in an array. | ||
/** returns an IterableWithLinq<> for keys in the collection */ | ||
export declare function keys<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T>)>(source: (TSrc & (Array<T> | Dictionary<T> | Map<K, T>)) | null | undefined): IterableWithLinq<IndexOf<TSrc>>; | ||
export declare function keys<K, T>(source: Map<K, T> | null | undefined): IterableWithLinq<K>; | ||
export declare function keys<T, TSrc extends Dictionary<T>>(source: Dictionary<T> | null | undefined): IterableWithLinq<string>; | ||
export declare function keys<T, TSrc extends Array<T>>(source: Array<T> | null | undefined): IterableWithLinq<number>; | ||
export declare function keys<K, T, TSrc>(source: any | undefined | null): IterableWithLinq<any>; | ||
/** returns an IterableWithLinq<> for values in the collection | ||
@@ -33,0 +39,0 @@ * |
@@ -31,2 +31,5 @@ "use strict"; | ||
results: results.bind(iterable), | ||
toDictionary: toDictionary.bind(iterable), | ||
toMap: toMap.bind(iterable), | ||
groupBy: groupBy.bind(iterable), | ||
}; | ||
@@ -39,4 +42,4 @@ r.linq = r; | ||
} | ||
/** returns an IterableWithLinq<> for keys in the collection */ | ||
function keys(source) { | ||
//export function keys<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T>)>(source: TSrc & (Array<T> | Dictionary<T> | Map<K, T>) | null | undefined): IterableWithLinq<IndexOf<TSrc>> { | ||
if (source) { | ||
@@ -146,2 +149,28 @@ if (Array.isArray(source)) { | ||
exports.length = length; | ||
function toDictionary(keySelector, selector) { | ||
const result = new common_1.Dictionary(); | ||
for (const each of this) { | ||
result[keySelector(each)] = selector(each); | ||
} | ||
return result; | ||
} | ||
function toMap(keySelector, selector) { | ||
const result = new Map(); | ||
for (const each of this) { | ||
result.set(keySelector(each), selector(each)); | ||
} | ||
return result; | ||
} | ||
function groupBy(keySelector, selector) { | ||
var _a; | ||
const result = new Map(); | ||
for (const each of this) { | ||
const key = keySelector(each); | ||
if (!result.has(key)) { | ||
result.set(key, new Array()); | ||
} | ||
(_a = result.get(key)) === null || _a === void 0 ? void 0 : _a.push(selector(each)); | ||
} | ||
return result; | ||
} | ||
function any(predicate) { | ||
@@ -148,0 +177,0 @@ for (const each of this) { |
{ | ||
"name": "@azure-tools/linq", | ||
"version": "3.1.201", | ||
"version": "3.1.203", | ||
"patchOffset": 100, | ||
@@ -46,8 +46,8 @@ "description": "LINQ-like functionality for Typescript.", | ||
"mocha": "5.2.0", | ||
"@typescript-eslint/eslint-plugin": "~2.0.0", | ||
"@typescript-eslint/parser": "~2.0.0", | ||
"eslint": "~6.2.2", | ||
"typescript": "~3.7.0-beta" | ||
"@typescript-eslint/eslint-plugin": "~2.6.0", | ||
"@typescript-eslint/parser": "~2.6.0", | ||
"eslint": "~6.6.0", | ||
"typescript": "~3.7.1-rc" | ||
}, | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66073
881