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

interceptor-js

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

interceptor-js

Small library to generate interception proxies

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Simple interceptor library for JavaScript

I have no idea why you'd ever need interception in JavaScript but it was a nice exercise.

Some possible use cases: Testing frameworks, logging frameworks, binding frameworks or frameworks that expose objects over an API that need to be tracked / intercepted in some sort.

Do things like this:

var I = Interceptor();

var obj = I.proxy({
  name: 'Interceptor',
  sum: function(a, b) {
    return a + b;
  },
  getProperty(object, property) {
    return object[property];
  }
});

I.when('name').of(obj).isAccessed().then(function() {
  return 'Intercepted!';
});

I.when('sum').of(obj).isInvoked().then(function() {
  return 'The whole is more than the sum of its parts';
});

I.when('getProperty').of(obj).isInvokedWith({name: 'Interceptor'}, 'name').then(function() {
  return 'Intercepted!';
});

Open issues

  • The practical usage of this library is not yet 100% clear
  • Modifications to the original object or to the proxy don't get tracked. It currently only works with properties present when the proxy was created (maybe usage of Object.observe would help)
  • invokedWith could use some wildcard arguments or something like that

FAQs

Package last updated on 26 Aug 2014

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