Skip to content
This repository was archived by the owner on Jul 4, 2019. It is now read-only.

Repository files navigation

Linqable.ts ✨

WARNING
potential security vulnerabilities in dependencies
project is not maintained, use ramdajs

Open documentation! ;3

MIT licenseMaintainabilitycodecovnpmimageDev Dependencies

Install

  • yarn add linqable.ts
    or
  • npm i linqable.ts

CDN

<scriptsrc="https://cdn.jsdelivr.net/npm/linqable.ts@1.7.18/lib/web/linq.min.js"></script>

Changelog

See Changelog

Usage 🌱

Browser:

<head><scriptsrc="https://cdn.jsdelivr.net/npm/linqable.ts@1.7.18/lib/web/linq.min.js"></script></head><!-- ... --><script>[2,4].Sum()// -> 6</script>

Node:

import"linqable.ts";console.log([3,5].Sum());

Use Advanced & Base Linqable:

import{AdvancedLinqable,BaseLinqable}from"linqable.ts";console.log(newBaseLinqable([3,5]).Sum());console.log(newAdvancedLinqable([3,5]).Acquire());

Build ☄️

  1. yarn build
  2. You are great! 💫

Dependences for build 🔥

  1. TypeScript 3.0 or above (in global)
  2. AVA 1.0.0-beta.8 or above (in global)

Test 🍒

  1. yarn test
  2. ava write test-report to screen

image

API:


Advanced API

Advanced API

Transpose

Transposes the rows of a sequence into columns.

letarray=[["Nola","Myse"],["Ruq"],["Dufna","Nygglatho","Kumesh"]];/* ... */array.Transpose();// result ->[['Nola','Ruq','Dufna',],['Myse','Nygglatho',],['Kumesh',],]

Evaluate

Returns a sequence containing the values resulting from invoking (in order) each function in the source sequence of functions.

letarray=[()=>"Chtholly",()=>"Ithea",()=>1+1,()=>!true]/* ... */array.Evaluate();// => ["Chtholly", "Ithea", 2, false]

Acquire

Ensures that a source sequence of objects are all acquired successfully. If the acquisition of any one fails then those successfully acquired till that point are delete

letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Acquire();// => success // => [{name: "Chtholly Nola", age: 17}, { name: "Ithea Myse", age: 18 }]array.Acquire();// => fail // => [] // => throw

Consume

Completely consumes the given sequence. This method uses immediate execution, and doesn't store any data during execution

letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Consume();

Batch

Batches the source sequence into sized buckets.

letarray=[{name: "Chtholly Nola"},{name: "Nephren Ruq"},{name: "Almaria Dufna"},{name: "Ithea Myse"}]/* ... */array.Batch(2);// => [[{name: "Chtholly Nola"}, {name: "Nephren Ruq"}],[{name: "Almaria Dufna"}, {name: "Ithea Myse"}]]// Returns an array with 2 arrays 😏

MaxBy

Returns the maxima (maximal elements) of the given sequence, based on the given projection.

letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.MaxBy(x=>x.age)// => { name: "Ithea Myse", age: 18 }

MinBy

Returns the minima (minimal elements) of the given sequence, based on the given projection.

letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.MinBy(x=>x.age)// => {name: "Chtholly Nola", age: 17}

Exclude

Excludes elements from a sequence starting at a given index

letarray=["CO2","Ir2O","C2O3","NH3","C2H6","H2C03"]/* ... */array.Exclude(1,2)// -> ["CO2", "NH3", "C2H6", "H2C03"]

Flatten

Flattens a sequence containing arbitrarily-nested sequences.

letarray=["CO2",["C2O3",["NH3",127.4],241,"H2C03"]/* ... */array.Flatten()// -> ["CO2", "C2O3", "NH3", 127.4, 241, "H2C03"]

Pairwise

Returns a sequence resulting from applying a function to each element in the source sequence and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element

letarray=["atom","core","neutron"];/* ... */array.Pairwise((x,y)=>`${x} contains ${y}`)// -> ["atom contains core", "core contains neutron"]

Pipe

Executes the given action on each element in the source sequence and yields it

letarray=[{name: 'neutron',lifetime: 880},{name: "proton",lifetime: Infinity}]/* ... */array.Pipe(x=>x.lifetime++);array.Where(x=>x.name=="neutron").lifetime// -> 881

Lag

Produces a projection of a sequence by evaluating pairs of elements separated by a negative offset.

letarray=[0,1,2,3,4];/* ... */array.Lag(/*step*/2,/*defaultValue*/0,(a,b)=>{return{A: a,B: b};})//returned -> [{"A":0,"B":0},{"A":1,"B":0},{"A":2,"B":0},{"A":3,"B":1},{"A":4,"B":2}]
Standard API

Standard API

[First]OrDefault

Returns the first element of a sequence. (Predicate Support)

letarray=[{formula: "CeO2",MolarMass: 172.115},{formula: "O",MolarMass: 15.999}];/* ... */array.First()// => {formula: "CeO2", MolarMass: 172.115 }letdefaultValue={formula: "H",MollarMass: 14.1}[].FirstOrDefault(null,defaultValue)// => {formula: "H", MollarMass: 14.1 }

[Last]OrDefault

Returns the last element of a sequence. (Predicate Support)

letarray=[{formula: "CeO2",MolarMass: 172.115},{formula: "O",MolarMass: 15.999}];/* ... */array.Last()// => {formula: "O", MolarMass: 15.999 }letdefaultValue={formula: "H",MollarMass: 14.1}[].LastOrDefault(null,defaultValue)// => {formula: "H", MollarMass: 14.1 }

Select

Projects each element of a sequence into a new form.

letarray=[{name: "Chtholly Nola",age: 17},{name: "Nephren Ruq",age: 17}]/* ... */array.Select(x=>x.name.split(' ').First())// => [{name: "Chtholly"}, {"Nephren"}]

Where

Filters a sequence of values based on a predicate.

letarray=[{name: "Chtholly Nola",age: 17},{name: "Nephren Ruq",age: 17},{name: "Almaria Dufna",age: 19},{name: "Ithea Myse",age: 18}]/* ... */// where adult only 🙈array.Where(x=>x.age>=18)// => [ {name: "Almaria Dufna", age: 19}, {name: "Ithea Myse", age: 18}]

Any

Determines whether any element of a sequence exists or satisfies a condition.

letarray=[{name: "Chtholly Nola",IsDead: true},{name: "Nephren Ruq",IsDead: false},{name: "Almaria Dufna",IsDead: true},{name: "Ithea Myse",IsDead: true}]/* ... */array.Any(x=>x.IsDead)// => truearray.Where(x=>!x.IsDead).Any(x=>x.IsDead)// => false

All

Determines whether all elements of a sequence satisfy a condition.

letarray=[{name: "Chtholly Nola",IsDead: true},{name: "Nephren Ruq",IsDead: false},{name: "Almaria Dufna",IsDead: true},{name: "Ithea Myse",IsDead: true}]/* ... */array.All(x=>x.IsDead)// => falsearray.Where(x=>x.IsDead).All(x=>x.IsDead)// => true

Sum

Computes the sum of the sequence of Decimal values that are obtained by invoking a transform function on each element of the input sequence.

letarray1=[1,2,3];letarray2=[{num: 15},{num: 10}];/* ... */array1.Sum()// => 6array2.Sum(x=>x.num)// => 25

IsEmpty

Gets a value indicating whether this array contains no elemets.

letarray1=[];letarray2=["Cobalt","Mithril"];/* ... */array1.IsEmpty()// => truearray2.IsEmpty()// => false

Min

Invokes a transform function on each element of a sequence and returns the minimum number value.

letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Min(x=>x.age)// => 17

Max

Invokes a transform function on each element of a sequence and returns the maximum number value.

letarray=[{name: "Chtholly Nola",age: 17},{name: "Ithea Myse",age: 18}]/* ... */array.Max(x=>x.age)// => 18

Take

Returns a specified number of contiguous elements from the start of a sequence.

letarray=["Cobalt","Mithril","Adamantium"];/* ... */array.Take(2)// => ["Cobalt","Mithril"]

OrderBy

Sorts the elements of a sequence in a particular direction (ascending, descending) according to a key.

letarray=[4,2,7,3,0,6];/* ... */array.OrderBy();// => [0, 2, 3, 4, 6, 7];

Supports primitives, including Date.
To compare other objects, you need to implement interface IComparer (TypeScript)
or implement function [Compare(y) : number]

As well support Descending.

Reverse

Inverts the order of the elements in a sequence.

letarray=[{name: "Chtholly Nola"},{name: "Nephren Ruq"},{name: "Almaria Dufna"},{name: "Ithea Myse"}]/* ... */array.Reverse()// => [{name: "Ithea Myse"},{name: "Almaria Dufna"},{name: "Nephren Ruq"},{name: "Chtholly Nola"}]

Distinct

Returns distinct elements from a sequence by using the default equality comparer to compare values.

letarray1=["Alkaloid","Protein","Chlorophyll","Alkaloid"];/* ... */array1.Distinct()// => ["Alkaloid", "Protein", "Chlorophyll"]

Union

Produces the set union of two sequences.

letarray1=["Alkaloid","Protein","Chlorophyll","Alkaloid"];letarray2=["Uranium","Iridium","Iridium","Plutonium"];/* ... */array1.Union(array2)// => ["Alkaloid", "Protein", "Chlorophyll", "Uranium", "Iridium", "Plutonium"]

Zip

Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

letwoman=["Chtholly","Nephren"];letman=["Willem","Willem"];woman.Zip(man,(w,m)=>`${w} love ${m}`)// => ["Chtholly love Willem", "Nephren love Willem"]

Single[OrDefault]

Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

letarray=[{synthesis: "Nuclear"},{synthesis: "Thermonuclear"}]array.Single()// => Throw Error/* ... */array.SingleOrDefault({synthesis: "none"})// => return default value // => {synthesis: "none"}/* ... */array=[{synthesis: "Nuclear"}];/* ... */array.Single()// => {synthesis: "Nuclear"}
Road Map

RoadMap

Standard:

  • First
  • FirstOrDefault
  • Last
  • LastOrDefault
  • Select
  • SelectMany
  • Where
  • Any
  • All
  • Sum
  • Take
  • TakeWhile
  • Min & Max
  • MinBy & MaxBy
  • IsDefault
  • OrderBy
  • Range
  • Reverse
  • Single
  • SingleOrDefault
  • SkipWhile
  • ThenBy
  • ThenByDescending
  • ToArray
  • Union
  • Zip
  • Aggregate
  • Count
  • Average
  • Append
  • Contains
  • DefaultIfEmpty
  • Distinct
  • Except
  • GroupBy
  • GroupJoin
  • Join

Advanced:

  • Acquire
  • AggregateRight
  • Assert
  • AssertCount
  • AtLeast
  • AtMost
  • Backsert
  • Batch
  • Cartesian
  • Choose (Deferred typescript 3)
  • Concat
  • Consume
  • CountBetween & CountBy & CountDown & CompareCount
  • EndsWith
  • EquiZip
  • DistinctBy
  • Exactly
  • ExceptBy
  • Exclude
  • Evaluate
  • FallbackIfEmpty
  • FillBackward & FillForward
  • Flatten
  • Fold
  • FullGroupJoin
  • FullJoin
  • Generate & GenerateByIndex
  • GroupAdjacent
  • Index
  • Insert
  • Interleave
  • Lag
  • Lead
  • LeftJoin
  • Move
  • OrderedMerge
  • Pad & PadStart
  • Pairwise
  • PartialSort & PartialSortBy
  • Partition
  • Permutations
  • Pipe
  • Prepend
  • PreScan
  • Random & RandomDouble & RandomSubset
  • Rank & RankBy
  • Repeat
  • RightJoin
  • RunLengthEncode
  • Scan & ScanRight
  • Segment
  • Sequence
  • Shuffle
  • SkipLast & SkipUntil
  • Slice
  • SortedMerge
  • Split
  • StartsWith
  • Subsets
  • TagFirstLast
  • Transpose
  • TakeEvery & TakeLast & TakeUntil
  • ZipLongest & ZipShortest

License

FOSSA Status

Releases

Packages

Used by

Contributors

Languages