Volver al ranking

mihaifm/linq

JavaScript

linq.js - LINQ for JavaScript

linqjavascript
Crecimiento de estrellas
Estrellas
1.7k
Forks
231
Crecimiento semanal
Issues
19
5001k1.5k
nov 2012may 2017dic 2021jul 2026
Artefactosnpmnpm install linq
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/linq@4.0.0/linq.d.ts"
import Enumerable from 'https://deno.land/x/linq@4.0.0/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

Repositorios relacionados
neuecc/UniRx

Reactive Extensions for Unity

C#MIT Licenseunirxunity
7.3k885
ldqk/Masuit.Tools

全龄段友好的C#万能工具库,码数吐司库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展、Excel导出等常用封装。诸多功能集一身,代码量不到2MB!

C#MIT Licenselambdareflection
masuit.tools
6.2k1.3k
AngleSharp/AngleSharp

:angel: The ultimate angle brackets parser library parsing HTML5, MathML, SVG and CSS to construct a DOM based on the official W3C specifications.

C#MIT Licenseanglesharpdom
anglesharp.github.io
5.5k593
Cysharp/ZLinq

Zero allocation LINQ with LINQ to Span, LINQ to SIMD, and LINQ to Tree (FileSystem, JSON, GameObject, etc.) for all .NET platforms and Unity, Godot.

C#MIT Licenselinqc-sharp
5.2k210
morelinq/MoreLINQ

Extensions to LINQ to Objects

C#Apache License 2.0linqdotnet
morelinq.github.io
3.8k418
ahmetb/go-linq

.NET LINQ capabilities in Go

GoGo ModulesApache License 2.0golinq
godoc.org/github.com/ahmetb/go-linq
3.7k225
stevencohn/OneMore

A OneNote add-in with simple, yet powerful and useful features

C#Mozilla Public License 2.0onenoteaddin
3.4k255
linq2db/linq2db

Linq to database provider.

C#MIT Licenselinqdatabase
3.3k478
nhibernate/nhibernate-core

NHibernate Object Relational Mapper

C#GNU Lesser General Public License v2.1nhibernatec-sharp
nhibernate.info
2.2k933
zio/zio-quill

Compile-time Language Integrated Queries for Scala

ScalaApache License 2.0databasescala
zio.dev/zio-quill
2.2k352
zzzprojects/System.Linq.Dynamic.Core

The .NET Standard / .NET Core version from the System Linq Dynamic functionality.

C#Apache License 2.0linqdynamic
dynamic-linq.net
1.7k245
nhibernate/fluent-nhibernate

Fluent NHibernate!

C#BSD 3-Clause "New" or "Revised" Licensenhibernatefluent-api
1.7k677