@guilherssousa/npm-graph-builder
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

NPM Graph Builder

A Typescript rewrite of npmgraphbuilder by anvaka. Builds graph of npm dependencies from npm registry. A graph is an instance of ngraph.graph.

Installing

With your favorite package manager:

npm install @guilherssousa/npm-graph-builder
pnpm install @guilherssousa/npm-graph-builder
yarn add @guilherssousa/npm-graph-builder

Demo

As the original package, it is not bound to any particular HTTP client. So it requires any HTTP client or library to be injected to the constructor:

import Graph from "ngraph.graph";
import graphBuilderConstructor from "npm-graph-builder";

const graphBuilder = graphBuilderConstructor({
  fetcher: httpClient /* any HTTP client */,
  url: "https://registry.npmjs.org/" /* npm registry URL */,
});

graphBuilder
  .createNpmDependenciesGraph({
    packageName: "browserify",
    graph: Graph(),
  })
  .then(function (graph) {
    console.log("Done.");
    console.log("Nodes count: ", graph.getNodesCount());
    console.log("Edges count: ", graph.getLinksCount());
  })
  .fail(function (err) {
    console.error("Failed to build graph: ", err);
  });

Here httpClient is a function(url) {} that returns a promise.

A demo of httpClient using Axios:

async function httpClient(url: string) {
  return await axios.get(url);
}

License

This repository and its code is licensed under the MIT license.

/@guilherssousa/npm-graph-builder/

    Package Sidebar

    Install

    npm i @guilherssousa/npm-graph-builder

    Weekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    333 kB

    Total Files

    13

    Last publish

    Collaborators

    • guilherssousa