Skip to content

anvaka/npmrank

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npmrank

This repository computes various graph metrics for npm dependencies.

setup

git clone https://github.com/anvaka/npmrank.git
cd npmrank
npm install

Download the npm graph from npm. To do this, follow the instructions from https://github.com/anvaka/allnpm#downloading-npm-data

Once you get the byField file convert it to graph:

node --max-old-space-size=4096 convertToGraph.js

You are ready to analyze the graph.

Graph metrics: PageRank, HITS, and Node Degree

node --max-old-space-size=4096 computeStats.js ./data/dependenciesGraph.out.graph 100 > sample/dependencies.md
node --max-old-space-size=4096 computeStats.js ./data/devDependencies.out.graph 100 > sample/devdependencies.md
node --max-old-space-size=4096 computeStats.js ./data/allDependencies.out.graph 100 > sample/alldependencies.md

These commands analyze and print top 100 entries for the following metrics:

  • Indegree - most dependent upon packages. Demo
  • Outdegree - packages with highest number of dependencies. Demo
  • Pagerank - rough estimate of package importance, based on number of dependents/dependencies. Demo
  • Hubs and Authorities - alternative importance classification, also based on number of edges. Demo

Command line usage

The following line will compute number of unique packages, that depend on packages created and maintained by a given user (in this case it's @thlorenz):

node --max-old-space-size=4096 ./countAuthorDeps.js thlorenz

You can also count total dependents for a given search query. E.g. this will count number of packages that depend on either underscore or lodash:

node --max-old-space-size=4096 countTotalDeps.js "^(lodash|underscore)$"

NOTE: Total dependents means all transitive dependents as well (i.e. dependents of dependents, and so on).

To count which versions depend on your package you can use countVersions.js utility:

node --max-old-space-size=4096 countVersions.js jquery

To get list of packages grouped by version pass --print-names argument:

node --max-old-space-size=4096 countVersions.js ngraph.graph --print-names

To further narrow down this list and print only those deps that could receive a certain semver range, pass --semver argument. E.g.:

node --max-old-space-size=4096 countVersions.js lodash --semver='3.9.x'

Searching for packages that sounds like a given name

node --max-old-space-size=4096 soundsLike.js packageName [maxDistance=3]

Where

packageName [required] - name that you are investigating
maxDistance [optional, defaults to 2] - Levenshtein distance threshold. Smaller
 values yield better matches.

Examples:

# will find `digraph, mongraph, graph, egraph, ...`
node soundsLike.js ngraph

# this will narrow down results to edit distance 1
# `graph, egraph, ...`:
node soundsLike.js ngraph 1

Online

Discover relevant and popular packages quickly: https://anvaka.github.io/npmrank/online/ Select a keyword and get packages sorted by their pagerank value.

Metrics dump with all graphs is available here.

license

MIT