{"id":14738,"library":"node-range","title":"Node Range - Lazy Sequence Generator","description":"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.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/miketheprogrammer/node-range","tags":["javascript","range","node","lazy","map","foreach"],"install":[{"cmd":"npm install node-range","lang":"bash","label":"npm"},{"cmd":"yarn add node-range","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-range","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail in pure ESM environments.","wrong":"import range from 'node-range';","symbol":"range","correct":"const range = require('node-range');"},{"note":"The `range` function is not exposed globally. It must be explicitly imported via `require`.","wrong":"range(1, 11);","symbol":"range","correct":"const range = require('node-range');\n// Then use range(start, end)"},{"note":"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`.","wrong":"const rangeInstance = new (require('node-range'))(1, 11);","symbol":"Range function result","correct":"const rangeInstance = require('node-range')(1, 11);"}],"quickstart":{"code":"const range = require('node-range');\n\nconsole.log('--- Lazy Map Example ---');\n// Generate a lazy range from 1 to 10 (exclusive of 11), and map each element\n// The array is only materialized when needed (e.g., by console.log or when iteration completes)\nconst mappedArr = range(1, 11).map(function(i) {\n    return i * 5;\n});\nconsole.log('Result of lazy map:', mappedArr);\n\nconsole.log('\\n--- To Array and Map Example ---');\n// Convert to an array first, then use standard Array.prototype.map\nconst toArrayAndMap = range(1, 11).toArray().map(function(i) {\n    return i * 2;\n});\nconsole.log('Result of toArray().map:', toArrayAndMap);\n\nconsole.log('\\n--- Synchronous ForEach Example ---');\n// Execute a function for each item in the range without returning an array\nrange(1, 5).forEach(function(i) {\n    console.log('forEach sync:', Math.pow(i, 2));\n});\n\nconsole.log('\\n--- Asynchronous ForEach (Callback-based) Example ---');\n// Execute a function asynchronously for each item (callback-based)\n// Note: This is non-blocking but uses older callback patterns\nrange(1, 3).forEachAsync(function(i) {\n    console.log('forEachAsync num:', i);\n});\nconsole.log('This should come first (demonstrating async nature)');","lang":"javascript","description":"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."},"warnings":[{"fix":"Migrate to a actively maintained lazy sequence or range generation library that supports modern JavaScript and Node.js versions, such as a utility from a functional programming library (e.g., Lodash, Ramda) or a dedicated iterator library.","message":"The `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.","severity":"breaking","affected_versions":"All versions (0.1.0)"},{"fix":"In CommonJS modules, use `const range = require('node-range');`. In ES modules, you might need dynamic import (`import('node-range').then(...)`) or a transpilation step, though switching to a modern library is recommended.","message":"This 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.","severity":"gotcha","affected_versions":"All versions (0.1.0)"},{"fix":"Benchmark performance critically for your specific use case against modern JavaScript alternatives and native array methods before relying on this package's performance claims.","message":"The 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.","severity":"gotcha","affected_versions":"All versions (0.1.0)"},{"fix":"Consider writing custom type declarations or, preferably, migrating to a modern, type-safe alternative. Alternatively, disable type checking for this specific import if the project accepts the risk.","message":"There 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.","severity":"gotcha","affected_versions":"All versions (0.1.0)"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Add `const range = require('node-range');` at the top of your CommonJS module.","cause":"The `range` function is not globally available and must be imported.","error":"ReferenceError: range is not defined"},{"fix":"Ensure you are calling the result of `require('node-range')` as a function: `const range = require('node-range'); const myRange = range(1, 10);`","cause":"This error can occur if `node-range` does not export a function directly, or if the `require` call is incorrectly structured.","error":"TypeError: require(...) is not a function"},{"fix":"Verify that `require('node-range')` successfully resolves to the intended package and that you are using it in a compatible CommonJS Node.js environment. Consider using `console.log(typeof require('node-range'));` to inspect the export.","cause":"This suggests that the object returned by `range(start, end)` is not the expected range instance with the `.map` method, likely due to an incorrect import or module resolution issue in an incompatible environment.","error":"TypeError: range(...).map is not a function"},{"fix":"This package is CommonJS-only. If you are in an ES module environment, you must dynamically import it using `import('node-range').then(module => { const range = module; ... });` or configure your build system for CJS-ESM interop. However, migration to a modern library is strongly advised.","cause":"Attempting to `require()` an ES module from a CommonJS module, or trying to `import` a CommonJS module in a pure ESM context without proper interoperability settings.","error":"ERR_REQUIRE_ESM"}],"ecosystem":"npm"}