{"id":10774,"library":"easy-stack","title":"easy-stack","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/RIAEvangelist/easy-stack","tags":["javascript","stack","node","js","auto","run","execute","browser","react"],"install":[{"cmd":"npm install easy-stack","lang":"bash","label":"npm"},{"cmd":"yarn add easy-stack","lang":"bash","label":"yarn"},{"cmd":"pnpm add easy-stack","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { Stack } from 'easy-stack';\nimport Stack from 'easy-stack';","symbol":"Stack","correct":"const Stack = require('easy-stack');"},{"note":"Use this specific path for environments requiring ES5 compatibility, such as older Node.js versions or direct browser usage without modern transpilation.","symbol":"Stack (ES5)","correct":"const Stack = require('easy-stack/es5.js');"},{"note":"For direct browser usage without a CommonJS bundler, include the `es5.js` file via a script tag, which exposes `Stack` globally.","wrong":"require('easy-stack'); // Fails in browser without a CommonJS bundler","symbol":"Global Stack (Browser)","correct":"<script src=\"./node_modules/easy-stack/es5.js\"></script>\n<script>\n  // Stack is now available globally\n  const stack = new Stack();\n</script>"}],"quickstart":{"code":"const Stack = require('easy-stack');\n\n// Create a new Stack instance\nconst stack = new Stack();\n\nlet requestCount = 0;\n\n// Add multiple functions to the stack\nfor (let i = 0; i < 3; i++) {\n    stack.add(function makeRequest() {\n        requestCount++;\n        // Simulate an asynchronous operation\n        console.log(`Processing request ${requestCount} from the stack...`);\n        setTimeout(() => {\n            console.log(`Request ${requestCount} completed.`);\n            // Crucially, call this.next() to advance the stack.\n            // This ensures the next item is processed, especially if autoRun is false or after an async step.\n            this.next();\n        }, 50);\n    });\n}\n\n// Dynamically add a high-priority task later. It will run automatically if `autoRun` is true and the stack is not stopped.\nstack.add(function dynamicTask() {\n    console.log('A new high-priority task dynamically added to the stack!');\n    this.next();\n});\n\nconsole.log('Stack initialized. Items will process in LIFO order (Last-In, First-Out).');","lang":"javascript","description":"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."},"warnings":[{"fix":"Review the new MIT license terms if your project's compliance depends on the previous DBAD license.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.1"},{"fix":"Assign a boolean value directly to `stack.stop` (e.g., `stack.stop = true;`) to control stack execution.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `const Stack = require('easy-stack');` for Node.js and bundler environments. For browser, use a script tag or a bundler.","message":"easy-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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Functions 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `require()` in a plain browser environment without a CommonJS bundler like Webpack or Browserify.","error":"ReferenceError: require is not defined"},{"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).","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'next')"},{"fix":"To stop or resume the stack, assign a boolean value directly: `stack.stop = true;` (to stop) or `stack.stop = false;` (to resume).","cause":"Incorrectly attempting to call the `stop` property as a method, when it is a boolean property.","error":"TypeError: stack.stop is not a function"}],"ecosystem":"npm"}