# ah-prune [![build status](https://secure.travis-ci.org/nodesource/ah-prune.png)](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/)

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### 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)&lt;[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)&lt;[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)&lt;[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)&lt;[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)>** the pruned activities

## License

MIT
