Socket
Socket
Sign inDemoInstall

middleman

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    middleman

A small library that lets you inject some code between a third party library and the execution context. With **Middleman.js** you can easily:


Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Install size
17.8 kB
Created
Weekly downloads
 

Readme

Source

Middleman.js

A small library that lets you inject some code between a third party library and the execution context. With Middleman.js you can easily:

  • filter arguments passed to an original method,
  • pass one function's arguments to another function, or
  • overload a third party method to change how it works
  • Development version 0.1.0 2.27kb Uncompressed
  • Production version 0.1.0 0.6kb Minified
  • Unit tests

Example

Let's say you add a third party library to your application that has a method called doSomethingCool.

    var ThirdPartyLibrary = {
        doSomethingCool : function(firstParam, isAwesome) {
            // do something cool with firstParam, then:
            if (isAwesome){
                console.log('All up in your app, doing awesome things.');
            }
        };
    };

You decide that you want to force the second parameter isAwesome to be true every time doSomethingCool is called because your application is totally awesome. You could just write a wrapper method like this:

    var AwesomeApplication = {
        doSomethingCool : function(firstParam) {
            return ThirdPartyLibrary.doSomethingCool(firstParam, true);
        }
    };

    AwesomeApplication.doSomethingCool('blah blah blah');
    /**
     * console: All up in your app, doing awesome things.
     */

However, now you have to remember to call your method instead of the original method. What if ThirdPartyLibrary is very popular (e.g. jQuery)? Your colleague Tony has been using ThirdPartyLibrary for years. He doesn't remember to use your wrapper function when writing new code for your application.

Middlman.js gets between Tony and ThirdPartyLibrary, so your application stays awesome. :expressionless:

    var MM = new Middleman();

    MM.map({
        lib : ThirdPartyLibrary,
        method : 'doSomethingCool',
        filter : function(args) {
            // make the second parameter true
            args[1] = true;
            return args;
        }
    });

    ThirdPartyLibrary.doSomethingCool("I'm Tony, and the second param is undefined.");
    /**
     * console: All up in your app, doing awesome things.
     */

Piece of cake.

Keywords

FAQs

Last updated on 11 Feb 2013

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc