3.2.5 • Published 2 years ago
linq-arrays v3.2.5
linq-arrays
The name LINQ is already used ::sad::
Based on System.Linq in C#, but in TS for browser and Node.js (server side);
Features
- The same methods (not all) of
Array.prototype - Typescript out of box
- Make the massive and repetitive operations for you,
like
sort by key,order by key,sorter for strings/numbers/date - A set of tools in Fluent Interface to work with arrays
Install
Simple, just choose your package manage and drop the command
yarn add linq-arrays
npm i linq-arrays
pnpm add linq-arraysUsing
const array = new Linq([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
// you can create a instance with Linq.From(array)
array.Sum() // 55
/*
with .Where, you can use some symbols to make your filter more simple
- != : compare use !=
- !== : compare use !==
- < : compare use <
- <= : compare use <=
- == : compare use ==
- === : compare use ===
- > : compare use >
- >= : compare use >=
eq: compare use Equals in `src/utils.ts`
is: compare use Object.is (JS method)
*/
array.Where({symbol: "!==", value: 2}).Sum() // 53
// or you can pass you function
array.Where((number, index, allItems) => number !== 2) // the same of Array.prototype.filter
/*
args accept a method, the same of Array.prototype.map.
If empty, just return the array like .ToArray
*/
const result = array.Select((x) => x ** 2) // the same of Array.prototype.mapAPI
const array = new Linq([1, 2, 3, 4, 5, 6, 7, 8, 9])Reverse(): use theArray.prototype.reverseto reverse arrayAdd(el: Type | Type[]): Add an item/items to last position of array with push/concatPrepend(el: Type | Type[]): Add an item/items to first position of array with push/concatConcat(list: Type[]): Concat an array to your arraySelect(transform?: ArrayCallback<Type>): Get array from Linq instance. The argument is a optional function, and works equalsArray.prototype.mapTake(init: number, end?: number): Takenitems of array. If end is null, usen:array.lengthHead(): Get first item of arrayTail(): Return all items, except firstSkip(jumps: number | ArrayCallbackAssertion<Type>): Skip thenitems or skip while the callback is falseDistinct(): like Linq.UniqueToArray(): Get array from instanceFirst(predicate?: ArrayCallbackAssertion<Type>): Return the first item of array or applyArray.prototype.findLast(predicate?: ArrayCallbackAssertion<Type>): Return the last item of array or applyArray.prototype.findin reverse array (usingArray.prototype.reverse)Sum(key?: keyof Type): Sum all items of array. You can specify the property or sum all primitive values in arrayAverage(key?: keyof Type): Get Average ofLinq.SumGroupBy(key: keyof Type): The same of static methodLinq.GroupByExcept(exceptions: Type[]): Get all items not in argument arrayIntersect(commons: Type[]): Get all items in argument arrayOrderBy(key?: keyof Type, sort?: OrderKeys): Order array from keyIncludes(object: Type): Check if array includes the objectIn(array: Type[]): Check if instance array has items in argument arrayEmpty(): nothing to commentToMap<KEY>(key: keyof Type): Map<KEY, Type>: convert the array to Map, using the value of objectkey to Map keysZip<T>(array: T[], fn: (first: Type, second?: T) => any)Count(predicate?: ArrayCallbackAssertion<Type>): Count items based on predicate or just array.lengthGet(n: number): Get item innpositionClone(): deepClone instance arrayToObject(key: keyof Type): ArrayAsObj<Type>All(predicate: ArrayCallbackAssertion<Type>): The same ofArray.prototype.every
3.2.5
2 years ago
3.2.4
2 years ago
3.2.2
2 years ago
3.2.3
2 years ago
3.2.1
2 years ago
3.2.0
2 years ago
3.0.2-5
2 years ago
3.0.2-4
2 years ago
3.0.2-7
2 years ago
3.0.2-6
2 years ago
3.0.2-9
2 years ago
3.0.2-8
2 years ago
3.1.3
2 years ago
3.0.4
2 years ago
3.1.2
2 years ago
3.0.3
2 years ago
3.1.1
2 years ago
3.0.2
2 years ago
3.1.0
2 years ago
3.0.1
2 years ago
3.0.6
2 years ago
3.1.4
2 years ago
3.0.5
2 years ago
3.0.2-1
2 years ago
3.0.2-0
2 years ago
3.0.2-3
2 years ago
3.0.2-2
2 years ago
3.0.0
3 years ago
2.0.2
3 years ago
2.0.0-rc
3 years ago
2.0.2-rc
3 years ago
2.0.1-rc
3 years ago
1.5.1
5 years ago
1.5.0
5 years ago
1.4.0
5 years ago
1.3.1
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.0
6 years ago
1.0.0
6 years ago