npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

blinq

v2.2.4

Published

With the advent of javascript iterators and generators, its possible to pipe sequences through a bunch of transformations without materializing collections (arrays) for the intermediate steps. This library attempts to recreate the dotnet linq-to-objects a

Downloads

123

Readme

A strongly-typed TypeScript implementation of Microsoft dotnet's LINQ to Objects using ES6 iterables.

With the advent of javascript iterators and generators, its possible to pipe sequences through a bunch of transformations without materializing collections (arrays) for the intermediate steps. This library attempts to recreate the dotnet linq-to-objects api to provide a number of standard operations on iterable sequences.

The following operations are available, and the user can optionally supply their own EqualityComparer (implementing equals and getHashCode) when using the set-based operations.

aggregate, all, any, append, average, concat, count, defaultIfEmpty, distinctBy, distinct, elementAt, except, firstOrDefault, first, flatten, forEach, fullOuterGroupJoin, fullOuterJoin, groupAdjacent, groupBy, groupJoin, intersect, isSubsetOf, isSupersetOf, join, lastOrDefault, last, leftOuterJoin, maxBy, max, minBy, min, orderBy / orderByDescending / thenBy / thenByDescending, preprend, reverse, selectMany, select, sequenceEqual, singleOrDefault, single, skip, skipWhile, sum, take, takeWhile, toArray, toLookup, toMap, toSet, union, where, zipAll, zip

Build Status Coverage Status

NPM package can be downloaded here.

documentation

Generated documentation can be found at https://biggyspender.github.io/blinq/

How?

Import blinq ES6 style:

import {
  blinq,
  range,
  empty,
  fromGenerator,
  fromSingleValue,
  repeatGenerate,
  repeat,
  EqualityComparer,
  hashString
} from "blinq";

or nodejs style:

const {
  blinq,
  range,
  empty,
  fromGenerator,
  fromSingleValue,
  repeatGenerate,
  repeat,
  EqualityComparer,
  hashString
} = require("blinq")

Now, just wrap your iterable with a call to blinq(myIterable), and start transforming your data:

const someNumbers = [1, 2, 3, 4];
const squares = blinq(someNumbers).select(n => n * n);
for(let v of squares){
    console.log(v);
}

...or if you'd like an array of your results, you can materialize a blinq query with the .toArray() method:

const someNumbers = range(1, 4);
const squaresBelowTen = someNumbers.select(n => n * n).where(n => n < 10);
const arr = squaresBelowTen.toArray();
console.log(arr);

or even spread your results into an array:

const arr2 = [...squaresBelowTen]

A case-insensitive set, using EqualityComparer

const names = ["zebra", "antelope", "ardvaark", "tortoise", "turtle", "dog", "frog"]
const comparer: EqualityComparer<string> = {
    equals: (a, b) => a.toLowerCase() === b.toLowerCase(),
    getHashCode: (x) => hashString(x.toLowerCase())
}
const set = blinq(names).toSet(comparer)
expect(set.has("DOg")).toBeTruthy()

More examples:

Let's make a collection of cars:

const cars = [{
    manufacturer:"Ford",
    model:"Escort"
  },{
    manufacturer:"Ford",
    model:"Cortina"
  },{
    manufacturer:"Renault",
    model:"Clio"
  },{
    manufacturer:"Vauxhall",
    model:"Corsa"
  },{
    manufacturer:"Ford",
    model:"Fiesta"
  },{
    manufacturer:"Fiat",
    model:"500"
  }
];

...and sort them by manufacturer, and then by model:

const orderedCars = blinq(cars).orderBy(c => c.manufacturer).thenBy(c => c.model);
console.log(orderedCars.toArray());

Or we could count the number of cars for each manufacturer:

const carsPerManufacturer = blinq(cars)
  .groupBy(c => c.manufacturer)
  .select(g => ({
    manufacturer:g.key, 
    count:g.count()
  }))
  .orderBy(c => c.manufacturer);
for(var c of carsPerManufacturer){
  console.log(`${c.manufacturer} : ${c.count}`);
}

What next?

The tests for this project are kept up to date and are the best place to look for other examples.

acknowledgements

Created using the wonderful https://github.com/alexjoverm/typescript-library-starter.