1. nodesecurity-npm-utils
## Methods:
nodesecurity-npm-utils
Package: nodesecurity-npm-utils
Created by: nodesecurity
Last modified: Wed, 22 Jun 2022 03:34:44 GMT
Version: 6.0.0
License: MIT
Downloads: 89,485
Repository: https://github.com/nodesecurity/npm-utils

Install

npm install nodesecurity-npm-utils
yarn add nodesecurity-npm-utils

node security project npm utilities

Methods:

getPackageJson = function (module, callback)

Return the full package document for the given module.

getShrinkwrapDependencies = function (shrinkwrapJson, callback)

Get a depTree for the module from a full npm-shrinkwrap.json. shrinkwrapJson should be an object from a parsed npm-shrinkwrap.json file (or look like one): required keys: name, version, dependencies.

 var fs = require('fs');

getShrinkwrapDependencies(JSON.parse(fs.readFileSync('./npm-shrinkwrap.json')), function (err, depTree) {
    console.log(depTree);
});

depTree format

The returned depTree representing the full dependency tree object 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.:

 //depTree for some-module version 1.1.0
{
    //root module
    "[email protected]": {
        parents: [],
        children: ["[email protected]", "[email protected]", "[email protected]"],
    },

    //root's dependencies
    "[email protected]": {
        parents: ["[email protected]"],
        children: ["[email protected]"],
        source: "npm"
    },
    "[email protected]": {
        parents: ["[email protected]"],
        children: ["[email protected]", "[email protected]"],
        source: "npm"
    },
    "[email protected]": {
        parents: ["[email protected]"],
        children: [],
        source: "unknown" //not on npm, maybe it's private/local?
    }

    //deeper dependencies
    "[email protected]": {
        parents: ["[email protected]", "[email protected]", "[email protected]"], //modules can be required multiple places in the tree
        children: [],
        source: "npm"
    },
    "[email protected]": {
        parents: ["[email protected]"], //modules can be required multiple places in the tree
        children: ["[email protected]"],
        source: "npm"
    }
}

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code