JSPM

calling-chain

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q11664F
  • License MIT

a module help you make calling chain

Package Exports

  • calling-chain
  • calling-chain/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (calling-chain) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

chainProxy

A module help you make calling chain.

I like bluebird but I hate some method like .get and .call, it's ugly!

And some time I want safely get some property in an object.

So I write this module make sync calling to be easy like spark language.

Note

This module only can run in Node 6.x because it use Proxy

Usage

You can use it like:

var _ = require('chainproxy')();

Promise.resolve({a: 12333})
  .then(_.a.toString().split('')[0].toString().replace('1', 'replaceStr').length)
  .then(console.log.bind(null, 'result:'), console.error.bind(null, 'catch error:'));

You can set a default value to require('chainproxy')(); param.

If sync calling have throw some error like TypeError, the expression will return the default value; if not set default value, expression will throw the error.

This expression actually create function like that:

function (args, _, defaultValue){
  try{
    _.a.toString().split(args[0])[args[1]].toString().replace(args[2], args[3]).length
  }catch(err){
    if(defaultValue) return defaultValue;
    else throw err;
  }
}

So you can see it's vary quick and easy to use.