Registry / data / easy-stack

easy-stack

JSON →
library1.0.1jsnpmunverified

easy-stack is a JavaScript library providing a simple Last-In, First-Out (LIFO) stack data structure, designed for both Node.js and browser environments. Its distinguishing feature is `autoRun`, which allows the stack to automatically execute newly added functions if it's not currently running or has not been forcibly stopped. This makes it suitable for managing prioritized operations, such as handling socket messages, processing async/sync tasks in a specific order, or creating extendable base classes for custom stack behaviors. The current stable version is 1.0.1, released primarily to update its licensing from the DBAD Public License to MIT. The package maintains a stable, albeit infrequent, release cadence, focusing on broad compatibility across various CommonJS loaders and vanilla browser usage, targeting Node.js environments from version 6.0.0 and above.

npm install easy-stack
INSTALL
IMPORT
SIG · EASY-STACK
E
easy-stack
datajavascriptv1.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

Stack
✓ const Stack = require('easy-stack');
✗ import { Stack } from 'easy-stack'; import Stack from 'easy-stack';
The primary module export for `easy-stack` is the Stack constructor directly, designed for CommonJS. ESM `import` syntax is not natively supported without a bundler configured for CJS interop.
Stack (ES5)
✓ const Stack = require('easy-stack/es5.js');
Use this specific path for environments requiring ES5 compatibility, such as older Node.js versions or direct browser usage without modern transpilation.
Global Stack (Browser)
✓ <script src="./node_modules/easy-stack/es5.js"></script> <script> // Stack is now available globally const stack = new Stack(); </script>
✗ require('easy-stack'); // Fails in browser without a CommonJS bundler
For direct browser usage without a CommonJS bundler, include the `es5.js` file via a script tag, which exposes `Stack` globally.

Demonstrates initializing a new easy-stack instance, adding functions to it, and the LIFO execution flow with `this.next()` for sequence control, including dynamic additions.

const Stack = require('easy-stack'); // Create a new Stack instance const stack = new Stack(); let requestCount = 0; // Add multiple functions to the stack for (let i = 0; i < 3; i++) { stack.add(function makeRequest() { requestCount++; // Simulate an asynchronous operation console.log(`Processing request ${requestCount} from the stack...`); setTimeout(() => { console.log(`Request ${requestCount} completed.`); // Crucially, call this.next() to advance the stack. // This ensures the next item is processed, especially if autoRun is false or after an async step. this.next(); }, 50); }); } // Dynamically add a high-priority task later. It will run automatically if `autoRun` is true and the stack is not stopped. stack.add(function dynamicTask() { console.log('A new high-priority task dynamically added to the stack!'); this.next(); }); console.log('Stack initialized. Items will process in LIFO order (Last-In, First-Out).');
Debug
Known issues
breakingThe license for easy-stack changed from the DBAD Public License to the MIT License. While not a code-breaking change, this alters the legal terms of use and distribution.
fix
Review the new MIT license terms if your project's compliance depends on the previous DBAD license.
affects: >=1.0.1
gotchaThe `stop` property is a boolean flag (`stack.stop = true;`) to halt execution, not a method (`stack.stop();`). Attempting to call it as a function will result in a TypeError.
fix
Assign a boolean value directly to `stack.stop` (e.g., `stack.stop = true;`) to control stack execution.
affects: >=1.0.0
gotchaeasy-stack is fundamentally a CommonJS module. Direct use of ES Modules `import` syntax (`import Stack from 'easy-stack';`) will fail in Node.js environments without a build step or explicit configuration for CJS-ESM interop.
fix
Always use `const Stack = require('easy-stack');` for Node.js and bundler environments. For browser, use a script tag or a bundler.
affects: >=1.0.0
gotchaThe package targets Node.js version 6.0.0 and above. This is an older Node.js version, which means the package may not fully leverage or be tested against modern JavaScript features or security practices available in newer Node.js releases.
fix
Consider potential compatibility or security implications when using in highly modern Node.js environments. While functional, it might not integrate seamlessly with very recent ecosystem changes.
affects: >=1.0.0
gotchaFunctions added to the stack (`stack.add(myFunction)`) must call `this.next()` internally to proceed to the next item in the stack. Failure to do so will halt stack execution prematurely, especially for asynchronous operations.
fix
Ensure that every function passed to `stack.add` explicitly calls `this.next()` after its work is done, particularly after any asynchronous tasks, to maintain the execution flow.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in a plain browser environment without a CommonJS bundler like Webpack or Browserify.
fix
For browser usage, include `es5.js` via a `<script>` tag (e.g., `<script src='./node_modules/easy-stack/es5.js'></script>`) to make `Stack` globally available.
TypeError: Cannot read properties of undefined (reading 'next')
This typically occurs when a function added to the stack (`stack.add(myFunction)`) loses its `this` context, preventing access to `this.next()`. This can happen with arrow functions or improperly bound functions.
fix
Ensure functions passed to `stack.add` are regular functions or are explicitly bound to the stack instance if `this` context is critical (though `easy-stack` usually handles this correctly internally for regular functions).
TypeError: stack.stop is not a function
Incorrectly attempting to call the `stop` property as a method, when it is a boolean property.
fix
To stop or resume the stack, assign a boolean value directly: `stack.stop = true;` (to stop) or `stack.stop = false;` (to resume).
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
easy-stack — npm install easy-stack · libregistry