SkillAgentSearch skills...

Lib

LINQ 💥 implementation library for TypeScript ❄️

Install / Use

/learn @Linqable/Lib

README

<!-- Logo --> <p align="center"> <a href="#"> <img height="128" width="128" src="https://raw.githubusercontent.com/Linqable/lib/master/docs/4a9b94e9cbe73230ef552f6882216f95.png"> </a> </p> <!-- Name --> <h1 align="center"> Linqable.ts ✨ </h1> <h2 align="center"> WARNING <br/> potential security vulnerabilities in dependencies <br/> project is not maintained, use <a href="https://ramdajs.com">ramdajs</a> </h2>

Open documentation! ;3

MIT license Maintainability codecov npm image Dev Dependencies

Install

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

CDN

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

Changelog

See Changelog

Usage 🌱

Browser:

<head>
    <script src="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(new BaseLinqable([3,5]).Sum());
console.log(new AdvancedLinqable([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:

<hr/> <details> <summary>Advanced API</summary>

Advanced API

Transpose

Transposes the rows of a sequence into columns.

let array = [
    [
        "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.

let array = [() => "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

let array = [{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

let array = [{name: "Chtholly Nola", age: 17}, { name: "Ithea Myse", age: 18 }]

/* ... */

array.Consume();

Batch

Batches the source sequence into sized buckets.

let array = [{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.

let array = [{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.

let array = [{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

let array = ["CO2", "Ir2O", "C2O3", "NH3", "C2H6", "H2C03"]

/* ... */

array.Exclude(1, 2) // -> ["CO2", "NH3", "C2H6", "H2C03"]

Flatten

Flattens a sequence containing arbitrarily-nested sequences.

let array = ["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

let array = ["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

let array = [{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.

let array = [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}]
</details> <details> <summary>Standard API</summary>

Standard API

[First]OrDefault

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

let array = [{formula: "CeO2", MolarMass: 172.115 }, {formula: "O", MolarMass: 15.999 }];

/* ... */

array.First() // => {formula: "CeO2", MolarMass: 172.115 }

let defaultValue = {formula: "H", MollarMass: 14.1 }
[].FirstOrDefault(null, defaultValue) // => {formula: "H", MollarMass: 14.1 }

[Last]OrDefault

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

let array = [{formula: "CeO2", MolarMass: 172.115 }, {formula: "O", MolarMass: 15.999 }];

/* ... */

array.Last() // =>  {formula: "O", MolarMass: 15.999 }

let defaultValue = {formula: "H", MollarMass: 14.1 }
[].LastOrDefault(null, defaultValue) // => {formula: "H", MollarMass: 14.1 }

Select

Projects each element of a sequence into a new form.

let array = [{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.

let array = [{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.

let array = [{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) // => true
array.Where(x => !x.IsDead).Any(x => x.IsDead) // => false

All

Determines whether all elements of a sequence satisfy a condition.

let array = [{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) // => false
array.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.

let array1 = [1, 2, 3];
let array2 = [{num: 15}, {num: 10}];

/* ... */

array1.Sum() // => 6
array2.Sum(x => x.num) // => 25

IsEmpty

Gets a value indicating whether this array contains no elemets.

let array1 = [];
let array2 = ["Cobalt","Mithril"];

/* ... */

array1.IsEmpty() // => true
array2.IsEmpty() // => false

Min

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

let array = [{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.

let array = [{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.

let array = ["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.

View on GitHub
GitHub Stars7
CategoryData
Updated8mo ago
Forks3

Languages

TypeScript

Security Score

82/100

Audited on Jul 22, 2025

No findings