Obliterator is a JavaScript/TypeScript library designed to provide higher-order functions for working with iterators and iterable-like values. It offers a suite of utilities for common iterable operations such as chaining multiple iterators, generating combinations and permutations, filtering, mapping, and consuming iterators. A key differentiator is its pragmatic approach to iterables, treating standard sequences like arrays and strings as valid inputs for convenience, even if they aren't strict ES6 iterables. The current stable version is 2.0.5, and it ships with full TypeScript declarations. The library is actively maintained, with the latest update noted in January 2025 on npm, focusing on utility functions for managing data streams and collections.
npm install obliteratorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates creating an iterator, applying filter and map transformations, chaining with other iterables, and highlights a key `combinations` gotcha.
When consuming results from `combinations` or `permutations` that need to be stored, clone the yielded array: `const combo = Array.from(iterator.next().value);` or `const allCombos = [...combinations(array, k)].map(c => [...c]);`
Be aware of this distinction when integrating with other libraries that strictly adhere to the ES6 iterable protocol. Use `Iterator.is(value)` for Obliterator's own definition of an iterable.
If you need to iterate over the same sequence multiple times, ensure you create a new iterator instance each time, or convert the iterator to a collection (e.g., an array) after the first pass if memory allows.
Use a named import for `Iterator` from the main package: `import { Iterator } from 'obliterator';` or ensure the default import is from the specific submodule: `import Iterator from 'obliterator/iterator';`Always import utility functions as named exports: `import { chain } from 'obliterator';`. For CommonJS, use `const { chain } = require('obliterator');`.Ensure the 'k' value for `combinations` or `permutations` is reasonable and does not lead to an combinatorial explosion that exceeds system memory or JavaScript engine limits. Re-evaluate your algorithm if very large 'k' values are truly needed.
No dependency data recorded yet.