linqx
v0.2.1
Published
Modern fork of linq with more APIs
Downloads
7
Readme
linqx
Modern fork of the original linq for JavaScript.
linqx keeps the familiar LINQ-style API while adding modern exports, new utility methods, improved TypeScript support, and active maintenance.
Written in pure JavaScript with no runtime dependencies.
Key Differences from linq
1. Named Export Added
The original package only exposed a default export.
linqx also provides:
export { Enumerable };This makes extensions, wrappers, and custom integrations cleaner and more flexible for typescript.
Example:
// enumerable.extensions.ts
import { Enumerable } from "linqx";
declare module "linqx" {
namespace Enumerable {
export function crossJoin<T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }>;
}
}
Enumerable.prototype.crossJoin = function <T>(this: Enumerable.IEnumerable<T>): Enumerable.IEnumerable<{ left: T; right: T; }> {
return Enumerable.from(crossJoinIterator(this));
function* crossJoinIterator(enumerable: Enumerable.IEnumerable<T>): Iterable<{ left: T; right: T; }> {
for (const item of enumerable) {
for (const otherItem of enumerable) {
yield { left: item, right: otherItem };
}
}
}
};Useful when augmenting prototypes or writing reusable helpers.
2. Additional APIs
linqx adds practical methods not available in the original package.
whereIf(flag, predicate)
page(pageNumber, pageSize)
page({ pageNumber, pageSize })
joinWith(separator)
toMap(keySelector, valueSelector)
chunk(size)
index()
position()
withNeighbors()Installation
npm install linqxUsage
ES Modules
import Enumerable from "linqx";
const result = Enumerable
.range(1, 10)
.where(x => x % 3 === 0)
.select(x => x * 10)
.toArray();Named Export
import { Enumerable } from "linqx";
const values = Enumerable.from([1, 2, 3]);TypeScript
import Enumerable from "linqx";
const items: Enumerable.IEnumerable<number> = Enumerable.from([1, 2, 3]);New API Examples
// whereIf
Enumerable
.from([1, 2, 3, 4])
.whereIf(true, x => x > 2)
.toArray();
// chunk
Enumerable
.from([1, 2, 3, 4, 5])
.chunk(2)
.toArray();
// result: [[1, 2], [3, 4], [5]]
// withNeighbors
for (const { prev, item, next } of Enumerable.from([10, 20, 30]).withNeighbors()) {
}
// position
for (const { index, item, isFirst, isLast } of Enumerable.from(["a", "b", "c"]).position()) {
}Migration from linq
Most projects can switch directly:
-import Enumerable from "linq";
+import Enumerable from "linqx";Repository
https://github.com/huoshan12345/linqx
Credits
Based on the original work by Yoshifumi Kawai and later linq maintainers.
Independent community fork.
License
MIT
