https://github.com/ngryman/traps
:wolf: Capture me if you can!
https://github.com/ngryman/traps
chainable-methods proxy
Last synced: 5 months ago
JSON representation
:wolf: Capture me if you can!
- Host: GitHub
- URL: https://github.com/ngryman/traps
- Owner: ngryman
- License: mit
- Created: 2016-09-07T19:30:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-15T00:27:00.000Z (over 8 years ago)
- Last Synced: 2025-08-13T17:51:51.294Z (11 months ago)
- Topics: chainable-methods, proxy
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# traps
> Trap me if you can!
[![travis][travis-image]][travis-url] [![codecov][codecov-image]][codecov-url]
[travis-image]: https://img.shields.io/travis/ngryman/traps.svg?style=flat
[travis-url]: https://travis-ci.org/ngryman/traps
[codecov-image]: https://img.shields.io/codecov/c/github/ngryman/traps.svg
[codecov-url]: https://codecov.io/github/ngryman/traps
`traps` leverages [proxies] and allows to easily create chainable `api`s.
You can register **traps** which will be invoked when a specific method is invoked or capture all method invocations in a **sink**.
[proxies]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
## Install
```bash
npm install --save traps
```
## Usage
```javascript
import traps from 'traps'
// capture all method invocations
const api = traps(console.log)
api.foo('bar').baz('qux')
// =>
// foo, ['bar']
// baz, ['qux']
// register a trap
api('woot', (name, params) => console.log('WOOT!', params))
api.woot('a wombat')
// => WOOT!, ['a wombat']
// invoke an lambda trap
api.trap(() => console.log('I do not have a name.'))
// => I do not have a name.
```
## License
MIT © [Nicolas Gryman](http://ngryman.sh)