@azure-tools/linq
Advanced tools
Comparing version 3.1.251 to 4.0.253
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.when = exports.ToDictionary = exports.Dictionary = void 0; | ||
class Dictionary { | ||
@@ -4,0 +5,0 @@ } |
@@ -1,7 +0,63 @@ | ||
export * from './new-linq'; | ||
export * from './freeze'; | ||
export * from './visitor'; | ||
export * from './common'; | ||
export * from './factory'; | ||
export * from './freeze'; | ||
export * from './new-linq'; | ||
export * from './sort'; | ||
export * from './visitor'; | ||
declare global { | ||
interface Array<T> { | ||
/** | ||
* Returns the elements of an array that meet the condition specified in a callback function. | ||
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. | ||
*/ | ||
where<S extends T>(callbackfn: (value: T, index: number, array: Array<T>) => value is S): Array<S>; | ||
/** | ||
* Returns the elements of an array that meet the condition specified in a callback function. | ||
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. | ||
*/ | ||
where(callbackfn: (value: T, index: number, array: Array<T>) => unknown): Array<T>; | ||
/** | ||
* Calls a defined callback function on each element of an array, and returns an array that contains the results. | ||
*/ | ||
select<U>(callbackfn: (value: T, index: number, array: Array<T>) => U): Array<U>; | ||
/** | ||
* Determines whether the specified callback function returns true for any element of an array. | ||
* @param callbackfn A function that accepts up to three arguments. The some method calls | ||
* the callbackfn function for each element in the array until the callbackfn returns a value | ||
* which is coercible to the Boolean value true, or until the end of the array. | ||
* @param thisArg An object to which the this keyword can refer in the callbackfn function. | ||
* If thisArg is omitted, undefined is used as the this value. | ||
*/ | ||
any(callbackfn: (value: T, index: number, array: Array<T>) => unknown, thisArg?: any): boolean; | ||
/** | ||
* Determines whether all the members of an array satisfy the specified test. | ||
* @param callbackfn A function that accepts up to three arguments. The every method calls | ||
* the callbackfn function for each element in the array until the callbackfn returns a value | ||
* which is coercible to the Boolean value false, or until the end of the array. | ||
* @param thisArg An object to which the this keyword can refer in the callbackfn function. | ||
* If thisArg is omitted, undefined is used as the this value. | ||
*/ | ||
all(callbackfn: (value: T, index: number, array: Array<T>) => unknown, thisArg?: any): boolean; | ||
/** | ||
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. | ||
* @param start The zero-based location in the array from which to start removing elements. | ||
* @param deleteCount The number of elements to remove. | ||
* @param items Elements to insert into the array in place of the deleted elements. | ||
*/ | ||
insert(start: number, ...items: Array<T>): Array<T>; | ||
/** | ||
* Removes elements from an array returning the deleted elements. | ||
* @param start The zero-based location in the array from which to start removing elements. | ||
* @param deleteCount The number of elements to remove. | ||
*/ | ||
remove(start: number, deleteCount?: number): Array<T>; | ||
selectMany<U>(callbackfn: (value: T, index: number, array: Array<T>) => U): Array<U extends ReadonlyArray<infer InnerArr> ? InnerArr : U>; | ||
groupByMap<TKey, TValue>(keySelector: (each: T) => TKey, selector: (each: T) => TValue): Map<TKey, Array<TValue>>; | ||
groupBy<TValue>(keySelector: (each: T) => string, selector: (each: T) => TValue): { | ||
[s: string]: Array<TValue>; | ||
}; | ||
readonly last: T | undefined; | ||
readonly first: T | undefined; | ||
} | ||
} | ||
//# sourceMappingURL=exports.d.ts.map |
@@ -6,12 +6,60 @@ "use strict"; | ||
*--------------------------------------------------------------------------------------------*/ | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./new-linq")); | ||
__export(require("./freeze")); | ||
__export(require("./visitor")); | ||
__export(require("./common")); | ||
__export(require("./factory")); | ||
__export(require("./sort")); | ||
__exportStar(require("./common"), exports); | ||
__exportStar(require("./factory"), exports); | ||
__exportStar(require("./freeze"), exports); | ||
__exportStar(require("./new-linq"), exports); | ||
__exportStar(require("./sort"), exports); | ||
__exportStar(require("./visitor"), exports); | ||
Object.defineProperties(Array.prototype, { | ||
where: { value: Array.prototype.filter }, | ||
select: { value: Array.prototype.map }, | ||
any: { value: Array.prototype.some }, | ||
all: { value: Array.prototype.every }, | ||
insert: { value: function (position, items) { return this.splice(position, 0, ...items); } }, | ||
selectMany: { value: Array.prototype.flatMap }, | ||
groupByMap: { | ||
value: function (keySelector, selector) { | ||
const result = new Map(); | ||
for (const each of this) { | ||
const key = keySelector(each); | ||
if (!result.has(key)) { | ||
result.set(key, new Array()); | ||
} | ||
result.get(key).push(selector(each)); | ||
} | ||
return result; | ||
} | ||
}, | ||
groupBy: { | ||
value: function (keySelector, selector) { | ||
const result = {}; | ||
for (const each of this) { | ||
const key = keySelector(each); | ||
(result[key] = result[key] || new Array()).push(selector(each)); | ||
} | ||
return result; | ||
} | ||
}, | ||
last: { | ||
get() { | ||
return this[this.length - 1]; | ||
} | ||
}, | ||
first: { | ||
get() { | ||
return this[0]; | ||
} | ||
} | ||
}); | ||
//# sourceMappingURL=exports.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.realize = exports.isValue = exports.isFunction = void 0; | ||
function isFunction(f) { | ||
@@ -4,0 +5,0 @@ return typeof f === 'function'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.clone = exports.deepFreeze = void 0; | ||
function deepFreeze(instance) { | ||
@@ -4,0 +5,0 @@ const obj = instance; |
@@ -1,2 +0,2 @@ | ||
import { IndexOf, Dictionary } from './common'; | ||
import { Dictionary, IndexOf } from './common'; | ||
export interface IterableWithLinq<T> extends Iterable<T> { | ||
@@ -32,7 +32,17 @@ linq: IterableWithLinq<T>; | ||
} | ||
export declare function keys<K, T>(source: Map<K, T> | null | undefined): Iterable<K>; | ||
export declare function keys<T, TSrc extends Dictionary<T>>(source: Dictionary<T> | null | undefined): Iterable<string>; | ||
export declare function keys<T, TSrc extends Array<T>>(source: Array<T> | null | undefined): Iterable<number>; | ||
export declare function keys<K, T, TSrc>(source: any | undefined | null): Iterable<any>; | ||
/** returns an IterableWithLinq<> for keys in the collection */ | ||
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>; | ||
declare function _keys<K, T>(source: Map<K, T> | null | undefined): IterableWithLinq<K>; | ||
declare function _keys<T, TSrc extends Dictionary<T>>(source: Dictionary<T> | null | undefined): IterableWithLinq<string>; | ||
declare function _keys<T, TSrc extends Array<T>>(source: Array<T> | null | undefined): IterableWithLinq<number>; | ||
declare function _keys<K, T, TSrc>(source: any | undefined | null): IterableWithLinq<any>; | ||
export declare function values<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T>)>(source: (Iterable<T> | Array<T> | Dictionary<T> | Map<K, T> | Set<T>) | null | undefined): Iterable<T>; | ||
export declare const linq: { | ||
values: typeof _values; | ||
items: typeof _items; | ||
keys: typeof _keys; | ||
}; | ||
/** returns an IterableWithLinq<> for values in the collection | ||
@@ -42,9 +52,8 @@ * | ||
*/ | ||
export declare function values<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T>)>(...sources: Array<(Iterable<T> | Array<T> | Dictionary<T> | Map<K, T> | Set<T>) | null | undefined>): IterableWithLinq<T>; | ||
declare function _values<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T>)>(source: (Iterable<T> | Array<T> | Dictionary<T> | Map<K, T> | Set<T>) | null | undefined): IterableWithLinq<T>; | ||
export declare function items<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T> | undefined | null)>(source: (TSrc & (Array<T> | Dictionary<T> | Map<K, T>)) | null | undefined): Iterable<[IndexOf<TSrc>, T]>; | ||
/** returns an IterableWithLinq<{key,value}> for the source */ | ||
export declare function items<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T> | undefined | null)>(source: (TSrc & (Array<T> | Dictionary<T> | Map<K, T>)) | null | undefined): IterableWithLinq<{ | ||
key: IndexOf<TSrc>; | ||
value: T; | ||
}>; | ||
declare function _items<K, T, TSrc extends (Array<T> | Dictionary<T> | Map<K, T> | undefined | null)>(source: (TSrc & (Array<T> | Dictionary<T> | Map<K, T>)) | null | undefined): IterableWithLinq<[IndexOf<TSrc>, T]>; | ||
export declare function length<T, K>(source?: string | Iterable<T> | Dictionary<T> | Array<T> | Map<K, T> | Set<T>): number; | ||
export {}; | ||
//# sourceMappingURL=new-linq.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.length = exports.items = exports.linq = exports.values = exports.keys = void 0; | ||
/*--------------------------------------------------------------------------------------------- | ||
@@ -43,2 +44,19 @@ * Copyright (c) Microsoft Corporation. All rights reserved. | ||
function keys(source) { | ||
if (source) { | ||
if (Array.isArray(source)) { | ||
return source.keys(); | ||
} | ||
if (source instanceof Map) { | ||
return source.keys(); | ||
} | ||
if (source instanceof Set) { | ||
throw new Error('Unable to iterate keys on a Set'); | ||
} | ||
return Object.keys(source); | ||
} | ||
// undefined/null | ||
return []; | ||
} | ||
exports.keys = keys; | ||
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>> { | ||
@@ -55,3 +73,3 @@ if (source) { | ||
} | ||
return linqify((Object.getOwnPropertyNames(source))); | ||
return linqify((Object.keys(source))); | ||
} | ||
@@ -61,56 +79,41 @@ // undefined/null | ||
} | ||
exports.keys = keys; | ||
function isIterable(source) { | ||
return !!source && !!source[Symbol.iterator]; | ||
} | ||
/** returns an IterableWithLinq<> for values in the collection | ||
* | ||
* @note - null/undefined/empty values are considered 'empty' | ||
*/ | ||
function values(...sources) { | ||
return linqify({ | ||
[Symbol.iterator]: function* () { | ||
for (const each of sources) { | ||
yield* _values(each); | ||
} | ||
} | ||
}); | ||
} | ||
exports.values = values; | ||
/** returns an IterableWithLinq<> for values in the collection */ | ||
function _values(source) { | ||
function values(source) { | ||
if (source) { | ||
// map | ||
if (source instanceof Map || source instanceof Set) { | ||
return linqify(source.values()); | ||
return source.values(); | ||
} | ||
// any iterable source | ||
if (isIterable(source)) { | ||
return linqify(source); | ||
return source; | ||
} | ||
// dictionary (object keys) | ||
return linqify(function* () { | ||
for (const key of keys(source)) { | ||
const value = source[key]; | ||
if (typeof value !== 'function') { | ||
yield value; | ||
} | ||
} | ||
}()); | ||
return Object.values(source); | ||
} | ||
// null/undefined | ||
return linqify([]); | ||
return []; | ||
} | ||
/** returns an IterableWithLinq<{key,value}> for the source */ | ||
exports.values = values; | ||
exports.linq = { | ||
values: _values, | ||
items: _items, | ||
keys: _keys | ||
}; | ||
/** returns an IterableWithLinq<> for values in the collection | ||
* | ||
* @note - null/undefined/empty values are considered 'empty' | ||
*/ | ||
function _values(source) { | ||
return (source) ? linqify(values(source)) : linqify([]); | ||
} | ||
function items(source) { | ||
if (source) { | ||
if (Array.isArray(source)) { | ||
return linqify(function* () { for (let i = 0; i < source.length; i++) { | ||
yield { key: i, value: source[i] }; | ||
} }()); | ||
return source.entries(); | ||
} | ||
if (source instanceof Map) { | ||
return linqify(function* () { for (const [key, value] of source.entries()) { | ||
yield { key, value }; | ||
} }()); | ||
return source.entries(); | ||
} | ||
@@ -120,17 +123,12 @@ if (source instanceof Set) { | ||
} | ||
return linqify(function* () { | ||
for (const key of keys(source)) { | ||
const value = source[key]; | ||
if (typeof value !== 'function') { | ||
yield { | ||
key, value: source[key] | ||
}; | ||
} | ||
} | ||
}()); | ||
return Object.entries(source); | ||
} | ||
// undefined/null | ||
return linqify([]); | ||
return []; | ||
} | ||
exports.items = items; | ||
/** returns an IterableWithLinq<{key,value}> for the source */ | ||
function _items(source) { | ||
return linqify(source ? items(source) : []); | ||
} | ||
function length(source) { | ||
@@ -147,3 +145,3 @@ if (source) { | ||
} | ||
return source ? Object.getOwnPropertyNames(source).length : 0; | ||
return source ? Object.values(source).length : 0; | ||
} | ||
@@ -215,5 +213,3 @@ return 0; | ||
for (const each of this) { | ||
for (const item of selector(each)) { | ||
yield item; | ||
} | ||
yield* selector(each); | ||
} | ||
@@ -220,0 +216,0 @@ }.bind(this)()); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.sort = void 0; | ||
const first = -1; | ||
@@ -9,4 +10,4 @@ const second = 1; | ||
var _a, _b; | ||
const pA = (_a = accessor(a), (_a !== null && _a !== void 0 ? _a : Number.MAX_VALUE)); | ||
const pB = (_b = accessor(b), (_b !== null && _b !== void 0 ? _b : Number.MAX_VALUE)); | ||
const pA = (_a = accessor(a)) !== null && _a !== void 0 ? _a : Number.MAX_VALUE; | ||
const pB = (_b = accessor(b)) !== null && _b !== void 0 ? _b : Number.MAX_VALUE; | ||
return pA === pB ? neither : pA < pB ? first : second; | ||
@@ -18,4 +19,4 @@ }); | ||
var _a, _b; | ||
const pA = (_a = accessor(a), (_a !== null && _a !== void 0 ? _a : -Number.MAX_VALUE)); | ||
const pB = (_b = accessor(b), (_b !== null && _b !== void 0 ? _b : -Number.MAX_VALUE)); | ||
const pA = (_a = accessor(a)) !== null && _a !== void 0 ? _a : -Number.MAX_VALUE; | ||
const pB = (_b = accessor(b)) !== null && _b !== void 0 ? _b : -Number.MAX_VALUE; | ||
return pA === pB ? neither : pA > pB ? first : second; | ||
@@ -27,4 +28,4 @@ }); | ||
var _a, _b; | ||
const pA = (_a = accessor(a), (_a !== null && _a !== void 0 ? _a : -Number.MAX_VALUE)); | ||
const pB = (_b = accessor(b), (_b !== null && _b !== void 0 ? _b : -Number.MAX_VALUE)); | ||
const pA = (_a = accessor(a)) !== null && _a !== void 0 ? _a : -Number.MAX_VALUE; | ||
const pB = (_b = accessor(b)) !== null && _b !== void 0 ? _b : -Number.MAX_VALUE; | ||
return pA === pB ? neither : pA < pB ? first : second; | ||
@@ -36,4 +37,4 @@ }); | ||
var _a, _b; | ||
const pA = (_a = accessor(a), (_a !== null && _a !== void 0 ? _a : Number.MAX_VALUE)); | ||
const pB = (_b = accessor(b), (_b !== null && _b !== void 0 ? _b : Number.MAX_VALUE)); | ||
const pA = (_a = accessor(a)) !== null && _a !== void 0 ? _a : Number.MAX_VALUE; | ||
const pB = (_b = accessor(b)) !== null && _b !== void 0 ? _b : Number.MAX_VALUE; | ||
return pA === pB ? neither : pA > pB ? first : second; | ||
@@ -40,0 +41,0 @@ }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.references = exports.refCount = exports.visitor = void 0; | ||
function* _visitor(instance, visited) { | ||
@@ -4,0 +5,0 @@ if (instance === null || instance === undefined || visited.has(instance)) { |
{ | ||
"name": "@azure-tools/linq", | ||
"version": "3.1.251", | ||
"version": "4.0.253", | ||
"patchOffset": 100, | ||
@@ -9,3 +9,3 @@ "description": "LINQ-like functionality for Typescript.", | ||
"engines": { | ||
"node": ">=10.12.0" | ||
"node": ">=12.13.0" | ||
}, | ||
@@ -43,12 +43,12 @@ "repository": { | ||
"devDependencies": { | ||
"mocha-typescript": "1.1.17", | ||
"@types/mocha": "5.2.5", | ||
"@testdeck/mocha": "~0.1.0", | ||
"@types/mocha": "~7.0.2", | ||
"@types/node": "12.7.2", | ||
"mocha": "5.2.0", | ||
"@typescript-eslint/eslint-plugin": "~2.6.0", | ||
"@typescript-eslint/parser": "~2.6.0", | ||
"eslint": "~6.6.0", | ||
"typescript": "~3.7.2" | ||
"mocha": "7.1.2", | ||
"@typescript-eslint/eslint-plugin": "2.28.0", | ||
"@typescript-eslint/parser": "2.28.0", | ||
"eslint": "6.8.0", | ||
"typescript": "~3.9.5" | ||
}, | ||
"dependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
90871
33