# requiresafe-npm-utils

> [![Build Status](https://magnum.travis-ci.com/requiresafe/npm-utils.svg?token=y6kXcG28kZTEjJL8fnHQ)](https://magnum.travis-ci.com/requiresafe/npm-utils)

Latest version **2.5.3** (published 2015-10-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install requiresafe-npm-utils
pnpm add requiresafe-npm-utils
yarn add requiresafe-npm-utils
bun add requiresafe-npm-utils
```

Provides the command `rnpm`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.3 |
| Published | 2015-10-19 |
| First published | 2015-10-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 11 |
| Author | ^lift security |
| Maintainers | nlf |
| Keywords | requireSafe, security, npm, package, shrinkwrap |

## Links

- npm: https://www.npmjs.com/package/requiresafe-npm-utils
- Repository: https://github.com/requiresafe/npm-utils
- Homepage: https://github.com/requiresafe/npm-utils#readme
- Issues: https://github.com/requiresafe/npm-utils/issues
- npm.io page: https://npm.io/package/requiresafe-npm-utils

## Dependencies (4)

- [async](https://npm.io/package/async.md) ^1.2.1
- [lodash](https://npm.io/package/lodash.md) ^3.7.0
- [semver](https://npm.io/package/semver.md) ^5.0.3
- [silent-npm-registry-client](https://npm.io/package/silent-npm-registry-client.md) 1.0.0

## Recent versions

- 2.5.3 (latest) — 2015-10-19

## README

# requireSafe (+) npm utilities

[![Build Status](https://magnum.travis-ci.com/requiresafe/npm-utils.svg?token=y6kXcG28kZTEjJL8fnHQ)](https://magnum.travis-ci.com/requiresafe/npm-utils)

## Methods:

### getModuleDependencies = function (module, callback)

Get a [depTree](#deptree-format) for the given module. `module` is an object that must contain a name and may optionally contain a version.

```js
getModuleDependencies({
    name: 'helmet',
    version: '0.2.0' //may also be a semver string, a la "^1.1.0"
}, function (err, depTree) {
    console.log(depTree);
});
```

### getPackageDependencies = function (packageJson, callback)

Get a [depTree](#deptree-format) for the module from a full package.json. `packageJson` should be an object from a parsed package.json file (or look like one): required keys: `name`, `version`, `dependencies`.

```js
var fs = require('fs');

getPackageDependencies(JSON.parse(fs.readFileSync('./package.json')), function (err, depTree) {
    console.log(depTree);
});
```

### getModuleMaintainers = function (module, callback)

Get an array of maintainers from a specifc module / version.

## depTree format

Many of the functions return a `depTree` representing the full dependency tree. This is in a format that's easier to traverse than a full tree. Each module in the full heirarchy has a key in the object of `module@version`. It's value is an object with `parents`, `children` and `source`.

Note that the root module has a key too.

e.g.:

```js
//depTree for some-module version 1.1.0
{
    //root module
    "some-module@1.1.0": {
        parents: [],
        children: ["depA@0.1.0", "depB@1.0.1", "depC@0.2.0"],
    },

    //root's dependencies
    "depA@0.1.0": {
        parents: ["some-module@1.1.0"],
        children: ["underscore@1.6.0"],
        source: "npm"
    },
    "depB@1.0.1": {
        parents: ["some-module@1.1.0"],
        children: ["underscore@1.6.0", "backbone@1.0.0"],
        source: "npm"
    },
    "depC@0.2.0": {
        parents: ["some-module@1.1.0"],
        children: [],
        source: "unknown" //not on npm, maybe it's private/local?
    }

    //deeper dependencies
    "underscore@1.6.0": {
        parents: ["depA@0.1.0", "depB@1.0.1", "backbone@1.6.0"], //modules can be required multiple places in the tree
        children: [],
        source: "npm"
    },
    "backbone@1.6.0": {
        parents: ["depB@1.0.1"], //modules can be required multiple places in the tree
        children: ["underscore@1.6.0"],
        source: "npm"
    }
}
```

---
_Source: https://npm.io/package/requiresafe-npm-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
