https://github.com/sdgluck/chain-call
:link: Build a chain of method calls
https://github.com/sdgluck/chain-call
Last synced: 9 months ago
JSON representation
:link: Build a chain of method calls
- Host: GitHub
- URL: https://github.com/sdgluck/chain-call
- Owner: sdgluck
- License: mit
- Created: 2016-10-21T10:25:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-10-26T14:52:17.000Z (over 9 years ago)
- Last Synced: 2025-08-19T20:35:15.748Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chain-call
> Build a chain of method calls
Made with ❤ at [@outlandish](http://www.twitter.com/outlandish)
[](http://standardjs.com/)
## Install
```sh
npm install --save chain-call
```
```sh
yarn add chain-call
```
## Import
```js
// ES6
import chainCall from 'chain-call'
// CommonJS
var chainCall = require('chain-call')
```
## Example
```js
const callApi = (entity, identifier) => chainCall(api, [
entity,
[typeof identifier === 'string' ? 'slug' : 'id', identifier],
'get',
['then', (response) => response]
])
callApi('users', 59) // calls api.users().id(59).get().then((response) => response)
```
## API
### `chainCall(subject, calls)`
Chain call methods on an object.
- __subject__ {Object} Object to chain method calls on
- __calls__ {Array} Array of calls to chain
Returns the result of invoking each method in `calls` one-by-one
on the return of the previous, beginning with a call on `subject`.
## Contributing
All pull requests and issues welcome!
If you're not sure how, check out Kent C. Dodds'
[great video tutorials on egghead.io](https://egghead.io/lessons/javascript-identifying-how-to-contribute-to-an-open-source-project-on-github)!
## Author & License
`chain-call` was created by [Sam Gluck](https://twitter.com/sdgluck) and is released under the MIT license.