@nuform/helium

A framework for creating and executing middleware

Usage no npm install needed!

<script type="module">
  import nuformHelium from 'https://cdn.skypack.dev/@nuform/helium';
</script>

README

Helium

Helium is a package that allows you to create your own middleware layer. It also allows you to enable or disable middleware on the fly.

// Import Helium
const Helium = require('@nuform/helium');

// Create a new middleware instance
const middleware = new Helium();

// Sample data that we can pass on between middleware
var dataPoint = {cheese: ["Cheddar"]};

// Add a function to the middleware 
// (Pass in an object containing the name of the middleware (see below) if you want to disable or enable it later)
middleware.use({name: "AddSwissCheese"}, function(data, next) {

    // Add Swiss Cheese (Modify the sample data if we want to)
    data.cheese.push('Swiss');

    // Continue
    next();

});

// Enable the Add Swiss Cheese Middleware
middleware.enable("AddSwissCheese");

// Runt the middleware with the prexisting data as an argument
middleware.run(dataPoint, function(data) {

    // Log
    console.log(data.cheese);
    
    // ['Cheddar', 'Swiss']
    

});