iterable-query - Query API for JavaScript Iterables and Async Iterables
// TypeScript; // JavaScript (CommonJS); .frombooks .filterbook.author === "Alice" .groupBybook.releaseYear; // TypeScript (functional style); // JavaScript (functional style, CommonJS) ;
iterable-query is a library that provides a query API for ES6 iterables, adding numerous operations found in other languages like Haskell, Scala, and C# (.NET).
Installing
For the latest version:
npm install iterable-query
Documentation
Examples
Filtering
; .fromgen .filteri % 2 === 0; .fromgen .wherei % 2 === 1; // alias for `filter`
Sorting
.frombooks .orderBybook.title .thenBybook.author; ;
Grouping
;; .fromgroups .groupJoinusers, group.id, user.id; for of usersByGroup
Hierarchies
.hierarchydocument.body, ; // disable all buttonsdoc .descendants .wherenode.type === "BUTTON" .forEach; // get all thumbnails .descendants .filternode.type === "IMG" .mapnode .filterimg.height < 32 && img.width < 32 .toArray;
Supported ECMAScript Editions
ES2017 Support (default)
The iterable-query library can be used in an ES2017-compatible runtime by importing "iterable-query"
:
// TypeScript; // JavaScript; // TypeScript (functional style); // JavaScript (functional style);
The default implementation requires a host that supports ES2017 at a minimum. This means support for:
Symbol
andSymbol.iterator
Promise
Map
Set
WeakMap
WeakSet
for..of
- Generator Functions
- Async Functions
The following ES2018 features are polyfilled:
Symbol.asyncIterator
(viaSymbol.for("Symbol.asyncIterator")
).
The following ES2018 features are not required to use the default (ES2017) version:
- Async Generator Functions (internal use is transpiled)
In addition, we also provide downlevel support for ES2015 and ES5.
ES2015 Support
The iterable-query library can be used in an ES2015-compatible runtime by importing "iterable-query/es2015"
:
// TypeScript; // JavaScript; // TypeScript (functional style); // JavaScript (functional style);
The ES2015 implementation requires a host that supports ES2015 at a minimum. This means support for:
Symbol
andSymbol.iterator
Promise
Map
Set
WeakMap
WeakSet
for..of
- Generator Functions
The following ES2018 features are polyfilled:
Symbol.asyncIterator
(viaSymbol.for("Symbol.asyncIterator")
).
The following ES2017 features are not required to use the ES2015 version:
- Async Functions (internal use is transpiled)
The ES2015 version of the library has all of the same features as the normal version.
ES5 Support
The iterable-query library can be used in an ES5-compatible runtime by importing "iterable-query/es5"
:
// TypeScript; // JavaScript Query = iq.Query; // TypeScript (functional style); // JavaScript (functional style) filter = fn.filter, groupBy = fn.groupBy;
The ES5 version of the library has all of the same features as the normal version.
The ES5 implementation requires a host that supports ES5 at a minimum. This means support for:
Object.create
andObject.defineProperty
The following ES2015 features are not polyfilled and require you to supply a runtime polyfill:
Promise
The following ES2015 features are polyfilled:
Symbol
andSymbol.iterator
(which produce strings)Map
Set
WeakMap
WeakSet
The following ES2017 features are polyfilled:
Symbol.asyncIterator
(viaSymbol.for("Symbol.asyncIterator")
).
The following ES2015 and ES2017 features are not required to use the ES5 version:
for..of
- Generator Functions (internal use is transpiled)
- Async Functions (internal use is transpiled)