Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

middle.js

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

middle.js

micro-library for quick implementation of "middleware" support into any project, it helps you implement open/closed principe

  • 4.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

middle.js

a micro-library for quick implementation of "middleware" support into any project. By "middleware" I mean something between Express.js middleware pattern and event handling in javascript.

This tool will help you implement open/closed principle from SOLID

By micro-library I mean really micro, it has only 1.6kB minified non-gzipped.

Install

You have several options to install middle.js

  1. Download built files from github:
https://github.com/luckylooke/middle/tree/master/dist
  1. Clone via git:
git clone https://github.com/luckylooke/middle.git
  1. Install via npm:
npm install middle.js

Usage

Let say you want users of your library/system/... to be able to use middleware on your public methods. For example imagine you have super cool message library with method send(consignee, message).

mySuperMsgLib.send('Superman', 'I love you, Lois Lane');

Superman get message 'I love you, Lois Lane'. Lib user enhance this by adding footer like this

mySuperMsgLib.send.use(function addFooter(next, consignee, message){
    message += '<br>send by Daily Planet message system.'; // enahancing message
    next(consignee, message); // passing data to next middleware or at last to ending method
});

Now when you send again the message

mySuperMsgLib.send('Superman', 'I really love you, Lois Lane');

Superman get message 'I really love you, Lois Lane
send by Daily Planet message system.'. To add this functionality to your method for one instace of class, you need to do this:

var mySuperMsgLib = new MySuperMsgLib();
mySuperMsgLib.send = new Middle(MySuperMsgLib.prototype.send, mySuperMsgLib);

For all instances, apply on prototype:

MySuperMsgLib.prototype.send = new Middle(function(){
    // send implementation
});

TODO:

  • Docs for all usecases

Keywords

FAQs

Package last updated on 02 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc