Giter Site home page Giter Site logo

jinq.js's Introduction

jinq.js

JavaScript Integrated Query for generators and arrays. Inspired by LINQ

For vanillajs and nodejs

๐Ÿ“„ Wiki

Installation

For nowโ„ข use:

$ npm i github:A1rPun/jinq.js

And then import it like:

import { jinq } from 'jinq';

Usage examples

Use jinq.from to construct an Enumerable from an iterator or an array.

function* generator() {
  yield 1;
  yield 2;
  yield 3;
}

const numberText = jinq
  .from(generator())
  .skip(2)
  .take(1)
  .select((n) => `The number: ${n}`)
  .single();

numberText === 'The number: 3'; // true

Use jinq.range to construct a generated sequence of numbers.

const bigRange = jinq.range(0, Number.MAX_SAFE_INTEGER);

bigRange.any(); // true
bigRange.take(2).toList(); // [0, 1]

How jinq deviates from LINQ

  • EqualityComparer is not implemented

Enumerable methods

JavaScript has numerous built in methods to do operations on arrays, not so much for generators. This library focuses primarely on generators because of the lazy loading with yields.

Method Returns value Description JS alternative
aggregate() โœ… Array.reduce()
all() โœ… Array.every()
any() โœ… Array.some()
append() Array.push()
asEnumerable() yield* Iterator
average() โœ… Array.reduce()
cast() accepts a type as parameter e.g. String, Number or Boolean Array.map()
chunk() -
concat() Array.concat()
contains() โœ… Array.includes()
count() โœ… Array.length
defaultIfEmpty() -
distinct() -
distinctBy() -
elementAt() โœ… can throw an error Array.at() ?? throw new Error()
elementAtOrDefault() โœ… Array.at() ?? defaultValue
except() Array.filter()
exceptBy() Array.filter()
first() โœ… can throw an error Array.at(0) ?? throw new Error()
firstOrDefault() โœ… Array.at(0) ?? defaultValue
groupBy() -
groupJoin() -
intersect() -
intersectBy() -
join() -
last() โœ… can throw an error Array.at(-1) ?? throw new Error()
lastOrDefault() โœ… Array.at(-1) ?? defaultValue
longCount() โœ… Array.length
max() โœ… Array.reduce()
maxBy() โœ… Array.reduce()
min() โœ… Array.reduce()
minBy() โœ… Array.reduce()
ofType() Array.filter()
order() doesn't return an IOrderedEnumerable Array.sort()
orderBy() doesn't return an IOrderedEnumerable Array.sort()
orderByDescending() doesn't return an IOrderedEnumerable Array.sort()
prepend() Array.unshift()
reverse() Array.reverse()
select() Array.map()
selectMany() Array.flatMap()
sequenceEqual() โœ… Array.all()
single() โœ… can throw an error -
singleOrDefault() Array.at(index) ?? defaultValue
skip() Array.slice()
skipLast() Array.slice()
skipWhile() Array.slice()
sum() โœ… Array.reduce()
take() Array.slice()
takeLast() Array.slice()
takeWhile() Array.slice()
toArray() โœ… [...Iterator]
toDictionary() โœ… new Map(Array)
toHashSet() โœ… new Set(Array)
toList() โœ… same as toArray() [...Iterator]
toLookup() โœ… new Map(Array)
tryGetNonEnumeratedCount() โœ… returns the count if enumerated, otherwise undefined Array.length
union() -
unionBy() -
where() Array.filter()
zip() -

Static methods

  • jinq.empty()
  • jinq.from()
  • jinq.range()
  • jinq.repeat()

jinq.js's People

Contributors

a1rpun avatar

Stargazers

 avatar Jeroen Nederlof avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.