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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lqjs

v1.0.1

Published

Adds some LINQ functionality for JavaScript Array

Readme

linqjs

Some LINQ functionality for JavaScript Array

Installation

npm install lqjs

Supplies the following functions for arrays:

  • all
  • any
  • copy
  • distinct
  • first
  • orderBy
  • orderByDescending
  • select
  • skip
  • take
  • where

Say you have the following array:

let people = [
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' },
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' },

  // Yes I know she is added twice, it's for the distinct() call!
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' }
];

all

Determines whether all elements of a sequence satisfy a condition.

Param: Function predicate

Returns: boolean


Example:

let allIsAlive = people.all(x => x.isAlive);

Will produce:

false

any

Determines whether any element of a sequence satisfies a condition.

Param: Function predicate

Returns: boolean


Example:

let females = people.any(x => x.gender === 'F');

Will produce:

true

copy

Make an exact copy of the array, not a reference.

Param none

Returns: Array


Example:

let copiedList = people.copy();

Will produce:

[
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' },
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' }
]

distinct

Returns distinct elements from a sequence.

Param: none

Returns: Array


Example:

let distinctList = people.distinct();

Will produce:

[
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' },
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' }
]

first

Returns the first element of a sequence based on a predicate, or a null if the sequence contains no elements. I've combined First(), FirstOrDefault(), Single(), and SingleOrDefault() into first(), and all "fails" just return a null.

Param: Function predicate

Returns: Object


Examples:

let khan = people.first(x => x.name.endsWith('Khan'));

Will produce:

{ name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' }

let obama = people.first();

Will produce:

{ name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' }

let nonExisting = people.first(x => x.age === 100);

Will produce:

null

orderBy

Sorts the elements of a sequence in ascending order according to a key.

Param: string key

Returns: Array


Example:

let alphabetically = people.orderBy('name');

Will produce:

[
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' },
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' },
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' }
]

orderByDescending

Sorts the elements of a sequence in descending order.

Param: string key

Returns: Array


Example:

let unalphabetically = people.orderByDescending('name');

Will produce:

[
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' },
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' },
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' }
]

select

Projects each element of a sequence into a new form.

Param: Object map

Returns: Array


Example:

let firstNamesAndGender = people.select({
  firstName: x => x.name.substr(0, x.name.indexOf(' ')),
  gender: x => x.gender === 'M' ? 'Male' : 'Female'
});

Will produce:

[
  { firstName: 'Barack', gender: 'Male' },
  { firstName: 'Genghis', gender: 'Male' },
  { firstName: 'Britney', gender: 'Female' },
  { firstName: 'Ada', gender: 'Female' },
  { firstName: 'Ada', gender: 'Female' }
]

skip

Bypasses a specified number of elements in a sequence and then returns the remaining elements.

Param: int number

Returns: Array


Example:

let skipped = people.skip(2);

Will produce:

[
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' },
  { name: 'Ada Lovelace', age: 36, isAlive: false, gender: 'F' }
]

take

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

Param: int number

Returns: Array


Example:

let taken = people.take(2);

Will produce:

[
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' }
]

where

Filters a sequence of values based on a predicate.

Param: Function predicate

Returns: Array


Example:

let wheres = people.where(x => x.age > 50);

Will produce:

[
  { name: 'Barack Obama', age: 55, isAlive: true, gender: 'M' },
  { name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' }
]

chains

You can chain multiple functions as they're prototypes of the Array object.


Examples:

let names = people
  .orderBy('name')
  .skip(2)
  .take(2)
  .where(x => x.age < 40);

Will produce:

[
  { name: 'Britney Spears', age: 35, isAlive: true, gender: 'F' }
]

let otherPerson = people
  .where(x => !x.isAlive &&
              x.gender === 'M')
  .first();

Will produce:

{ name: 'Genghis Khan', age: 65, isAlive: false, gender: 'M' }