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

daisy-chain

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

daisy-chain

Create a pipeline of proxy objects that will wrap over a target object.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

daisychain

Create a pipeline of proxy objects that will wrap over a target object.

Install

npm install --save daisy-chain

const { daisyChain } = require('daisy-chain');

API

daisyChain(proxies, target, prop?)

  • proxies (Object[]): an array of proxy objects.
  • target (Object): a target object.
  • prop (String): an optional property on the target the proxies will wrap over. (If not provided, the proxies will wrap over target).

A proxy can provide a wrapper over any property/ function on the target object (or property on the target object).

The order of the proxies in the proxy array determines their execution order.

Each proxy object can wrap a target property/ function with the signature:

foobar(next, ...args)
  • next is the next foobar proxy call in the pipeline (or the original foobar call) on the target object/ specified target object property.
  • args are the provided arguments to foobar.

Example (javascript)

const { daisyChain } = require('daisy-chain');

class Greeting {
  constructor() {
    this.message = 'hello';
  }

  greet() {
    return this.message;
  }
}

class GreetingWorld {
  constructor() {
    this.message = ' world';
  }

  greet(next, ...args) {
    return next(...args) + this.message;
  }
}

class GreetingLogger {
  greet(next, ...args) {
    const result = next(...args);
    console.log(result);
    return result;
  }
}

const target = new Greeting();
const proxyPipeline = [new GreetingLogger(), new GreetingWorld()];
const wrappedTarget = daisyChain(proxyPipeline, target);

wrappedTarget.greet(); // hello world

see examples

FAQs

Package last updated on 28 Jun 2017

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