https://github.com/nodesource/ah-prune
Prune specific types of async hook resources from a collected map.
https://github.com/nodesource/ah-prune
Last synced: 4 months ago
JSON representation
Prune specific types of async hook resources from a collected map.
- Host: GitHub
- URL: https://github.com/nodesource/ah-prune
- Owner: nodesource
- License: mit
- Created: 2017-01-20T19:38:02.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-09T11:20:13.000Z (almost 9 years ago)
- Last Synced: 2024-04-25T04:01:26.339Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://nodesource.github.io/ah-prune
- Size: 1.13 MB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ah-prune [](http://travis-ci.org/nodesource/ah-prune)
Prune specific types of async hook resources from a collected map.
```js
const prune = require('ah-prune')
// Removing all TickObject
const noticks = prune({ activities, prune: new Set([ 'TickObject' ]) })
// Removing everything but TCPWRAP
const onlytcpwrap = prune({ activities, keep: new Set([ 'TCPWRAP' ]) })
// Removing everything but a specific id via a custom keep function
const onlytcp1 = prune({
activities
, keepFn(type, activity) { return activity.id === 'tcp:1' }
})
```
## Installation
npm install ah-prune
## [API](https://nodesource.github.io/ah-prune/)
### prune
Prunes the supplied async hook activities according to `prune` or
`keep` option.
It repoints the triggerIds in the process so that the graph is
preserved.
Only either `prune` or `keep` maybe supplied at once.
The `activities` passed are not modified, instead a clone is made before
the pruning step, unless `copy` is set to `false`
**Parameters**
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options to configure the pruning step
- `$0.activities` **[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** the activities to be pruned
- `$0.prune` **[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** if supplied all activities of types supplied
in the Set are removed
- `$0.keep` **[Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** if supplied all activities of types NOT
supplied in the Set are removed
- `$0.keepFn` **[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** `function (type, activity)` if supplied will be
used as the predicate function to determine if an activity is removed.
Return `true` to keep the activity, `false` to remove it
- `$0.copy` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** if set, the activities are cloned before
modification, otherwise they are modified in place, default: `true`
Returns **[Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** the pruned activities
## License
MIT