Registry / data / node-range

node-range

JSON →
library0.1.0jsnpmunverified

Node-range is a JavaScript utility package designed to generate lazy sequences (ranges) of numbers, offering methods like `map`, `forEach`, and `forEachAsync` that operate without fully materializing the entire sequence into memory upfront. This can be beneficial for performance and memory usage when dealing with very large ranges. The package's current and only stable version is 0.1.0, last published over a decade ago in January 2015. Due to its age, it relies on older CommonJS module patterns and lacks support for modern JavaScript features like native Promises (it uses callbacks for async operations) or TypeScript definitions. Its claim of being "faster than Array.map" might be outdated due to significant V8 engine optimizations in modern Node.js. Given its lack of updates, it is no longer maintained and should be used with caution, if at all.

data
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

This package is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail in pure ESM environments.

const range = require('node-range');

The `range` function is not exposed globally. It must be explicitly imported via `require`.

const range = require('node-range'); // Then use range(start, end)

The package exports a function directly, which you call with arguments to get a range instance. It is not a class to be instantiated with `new`.

const rangeInstance = require('node-range')(1, 11);

This quickstart demonstrates creating lazy numerical ranges, applying transformations with `map` (lazy and eager), iterating with `forEach` for synchronous operations, and `forEachAsync` for non-blocking iteration using callbacks.

const range = require('node-range'); console.log('--- Lazy Map Example ---'); // Generate a lazy range from 1 to 10 (exclusive of 11), and map each element // The array is only materialized when needed (e.g., by console.log or when iteration completes) const mappedArr = range(1, 11).map(function(i) { return i * 5; }); console.log('Result of lazy map:', mappedArr); console.log('\n--- To Array and Map Example ---'); // Convert to an array first, then use standard Array.prototype.map const toArrayAndMap = range(1, 11).toArray().map(function(i) { return i * 2; }); console.log('Result of toArray().map:', toArrayAndMap); console.log('\n--- Synchronous ForEach Example ---'); // Execute a function for each item in the range without returning an array range(1, 5).forEach(function(i) { console.log('forEach sync:', Math.pow(i, 2)); }); console.log('\n--- Asynchronous ForEach (Callback-based) Example ---'); // Execute a function asynchronously for each item (callback-based) // Note: This is non-blocking but uses older callback patterns range(1, 3).forEachAsync(function(i) { console.log('forEachAsync num:', i); }); console.log('This should come first (demonstrating async nature)');
Debug
Known footguns
breakingThe `node-range` package is abandoned and has not been updated since January 2015. It is highly likely to be incompatible with modern Node.js versions (e.g., Node.js v14+), especially regarding ES Modules, and may contain unpatched security vulnerabilities.
gotchaThis package is CommonJS-only and cannot be directly imported using ES module syntax (`import ... from 'node-range';`) in pure ESM Node.js projects without specific loaders or build tool configurations.
gotchaThe README's claim that `node-range` is "Faster than Array.map" might no longer be true in many scenarios. Modern V8 engine optimizations in Node.js have significantly improved the performance of native array methods, potentially making them competitive or even faster than this older, unmaintained lazy implementation.
gotchaThere are no TypeScript type definitions (`.d.ts` files) available for `node-range`. Using this package in a TypeScript project will result in type errors and a lack of intelligent code completion and type checking.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
14 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
script
1
bytedance
1
Resources