New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

proxy-method

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy-method

Straight-forward way of interception method(s) before and/or after its execution.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Proxy JavaScript Methods
npm npm

Simple way of adding custom logic to an instantiated object's method(s).

Installation

npm install proxy-method --save

Usage

const proxyMethod = require('proxy-method');

const instance = new class {

    print(message) {
        console.log(`This is your message: ${message}`);
    }

};

instance.print('This is a test.');

// prints: 'This is your message: This is a test.'

// proxy the method before it executes
var restore = proxyMethod.before(
    instance,
    'print',
    message => `${message.replace(/\.\s*$/, '')} - suffixed.`,
    true
);

instance.print('This is another test.');

// prints: 'This is your message: This is another test - suffixed.'

// removing previous proxied functionality
restore.restore();

proxyMethod.after(instance, 'print', () => console.log('Executing after proxied method.'));

instance.print('This is one more test.');

// prints:
// This is your message: This is one more test.
// Executing after proxied method.

Keywords

FAQs

Package last updated on 19 Oct 2019

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