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

chaingun

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chaingun

make an object's functions chainable

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

chaingun

make an object's functions chainable.

var chaingun = require('chaingun');

var chain = chaingun({
  add: function(a, b) { return a + b; },
  multiply: function(a, b) { return a * b; }
});

chain(2)
  .add(3)
  .multiply(5)
  .add(5)
  .multiply(2)
  ();  // 60

install

node:

$ npm install chaingun

browser:

$ bower install chaingun
<script src="/bower_components/chaingun/chaingun.js"></script>

api

chaingun(obj)

Returns a chainable version of the given object.

When the chainable is invoked, a chain is started. A chain consists of 'curried' versions of the original object's enumerable function properties. Each function invoked in the chain will be curried with the chain's current value, and its result used as the chain's new value. The given value will be used as the starting value for the chain. When the chain is invoked directly, its value is returned:

var chain = chaingun({add: function(a, b) { return a + b; }});

chain(2)
  .add(3)
  .add(5);
  () // 10

If obj is a function, it will be invoked at the start of the chain. Its return value will be used as the starting value of the chain:

function thing(a, b) { return a + b; }
thing.multiply = function(a, b) { return a * b; };

var chain = chaingun(thing);

chain(2, 3)
  .multiply(4)
  ();  // 20

obj's properties can be accessed directly from the chainable:

var obj = {
  foo: 2,
  bar: 3,
  baz: {},
  quux: function() {}
};

var chain = chaingun(obj);
chain.foo === obj.foo;  // true
chain.bar === obj.bar;  // true
chain.baz === obj.baz;  // true
chain.quux === obj.quux;  // true

Keywords

FAQs

Package last updated on 26 Jul 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