{"library":"mware","title":"mware Middleware Stack Creator","description":"mware is a lightweight utility designed to create and manage sequential middleware stacks, inspired by patterns found in frameworks like Connect. It provides a simple API (`use` and `run`) to define a series of functions that process a shared context and can either proceed to the next middleware, halt the stack with a success signal, or terminate it by reporting an error. The current stable version is 1.0.1. However, the project's copyright date of 2016 and the nature of its last fix suggest it is largely unmaintained. Its key differentiator is its minimalism, offering a core middleware pattern without the overhead or specific request/response abstractions typical of larger web frameworks, making it suitable for generic processing pipelines in both Node.js and browser environments.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install mware"],"cli":null},"imports":["import mware from 'mware';","const { use, run } = mware();","const mware = require('mware');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import mware from 'mware';\n\nconst { use, run } = mware();\n\n// Add middleware functions\nuse((ctx, next) => {\n    console.log('Middleware 1: Processing context', ctx);\n    // Modify context or perform async operations\n    setTimeout(() => next(), 100);\n});\n\nuse((ctx, next) => {\n    console.log('Middleware 2: Further processing', ctx);\n    if (ctx.shouldStop) {\n        console.log('Middleware 2: Stopping stack early.');\n        return next(null, 'Stopped Early'); // Stop the stack with a result\n    }\n    return next(); // Proceed to the next middleware\n});\n\nuse((ctx, next) => {\n    console.log('Middleware 3: This might not run if stopped early.');\n    // Simulate an error condition\n    if (ctx.fail) {\n        return next(new Error('Simulated error in middleware 3')); // Stop and report error\n    }\n    next();\n});\n\n// Run the stack with an initial context\nconst context = { value: 42, shouldStop: false, fail: false };\nrun([context], (err, result) => {\n    if (err) {\n        console.error('Stack completed with error:', err.message);\n    } else {\n        console.log('Stack completed successfully. Result:', result || 'No explicit result');\n    }\n    console.log('Final context state:', context);\n});","lang":"javascript","description":"This example demonstrates how to initialize `mware`, add multiple asynchronous middleware functions, and run the stack with a context. It shows how middleware can modify the context, stop the stack early with a result, or terminate with an error.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}