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

linq

v4.0.2

Published

linq.js - LINQ for JavaScript

Downloads

150,751

Readme

linq

This is a JavaScript implementation of the .NET LINQ library.

It contains all the original .NET methods plus a few additions.

Written in pure JavaScript with no dependencies.

Examples

// C# LINQ - delegate
Enumerable.Range(1, 10)
    .Where(delegate(int i) { return i % 3 == 0; })
    .Select(delegate(int i) { return i * 10; });

// linq.js - anonymous function
Enumerable.range(1, 10)
    .where(function(i) { return i % 3 == 0; })
    .select(function(i) { return i * 10; });
// C# LINQ - lambda
Enumerable.Range(1, 10).Where((i) => i % 3 == 0).Select((i) => i * 10);

// linq.js - arrow function
Enumerable.range(1, 10).where((i) => i % 3 == 0).select((i) => i * 10);
// C# LINQ - anonymous type
array.Select((val, i) => new { Value: val, Index: i }());

// linq.js - object literal
Enumerable.from(array).select((val, i) => ({ value: val, index: i }));

See sample/tutorial.js and the test folder for more examples.

Usage

Node.js (ES modules)

Install the latest version of the library with npm:

npm install linq

Load it in your code with the import syntax:

import Enumerable from 'linq'

let result = Enumerable.range(1, 10).where(i => i % 3 == 0).select(i => i * 10)
console.log(result.toArray()) // [ 30, 60, 90 ]

Because the library is an ES module, this code will only work if your project is also configured as an ES module. Add the following line in your package.json to make it an ES module:

"type": "module"

If you're not planning to use ES modules, check the CommonJS section below.

Node.js (CommonJS modules)

Install version 3 of this library:

npm install linq@3

Load it with the require syntax:

const Enumerable = require('linq')

let count = Enumerable.range(1, 10).count(i => i < 5)
console.log(count) // 4

The cjs branch contains the source code for the CommonJS version of the library.

TypeScript

Install the latest version of the library with npm.

Configure your compiler options in tsconfig.json

"compilerOptions": {
    "target": "ES2020",
    "moduleResolution": "node"
}

The library comes with a d.ts file containing type definitions for all the objects and methods, feel free to use them in your code:

import Enumerable from 'linq';

type tnum = Enumerable.IEnumerable<number>;
let x: tnum = Enumerable.from([1, 2, 3]);

Deno

Import the library from deno.land. Use the @deno-types annotation to load type definitions:

// @deno-types="https://deno.land/x/[email protected]/linq.d.ts"
import Enumerable from 'https://deno.land/x/[email protected]/linq.js'

let radius = Enumerable.toInfinity(1).where(r => r * r * Math.PI > 10000).first()

You can also install locally with npm. Use the full file path when importing the library:

// @deno-types="./node_modules/linq/linq.d.ts"
import Enumerable from './node_modules/linq/linq.js'

Browser

The minified version of the library is available in the release archive.

Load it via <script type="module">:

<script type="module" src="./linq.min.js"></script>
<script type="module">
    import Enumerable from './linq.min.js'
    Enumerable.from([1, 2, 3]).forEach(x => console.log(x))
</script>

You can also load the library via a CDN:

| CDN | URL | | ---------: | :----------------------------------------- | | unpkg | https://unpkg.com/linq/ | | jsDelivr | https://jsdelivr.com/package/npm/linq | | packd | https://bundle.run/linq@latest?name=linq |

Credits

Yoshifumi Kawai developed the original version of this library.

License

MIT License