Coder Social home page Coder Social logo

archived-npm-download-db's Introduction

npm-download-db

A local store containing npm download counts for all packages, able to provide rankings

NPM

API

NpmDownloadDb(db[, options]) (constructor)

Returns a new instance of NpmDownloadDb operating on the database provided. The database must be a LevelUp style object (can be backed by LevelDB or whatever backing store you can find implementing the API).

options is optional but if options.rankPeriod is provided it will override the default of 30 to set the period, in days, within which to calculate the ranking of packages.

db.update([options])

Run an update operation on the database, using npm-download-count-collector to collect downloads for all current packages in the registry. By default, a full year's worth of downloads will be collected at a parallelism of 2. See npm-download-count-collector for details on the options you can pass through.

Note this can take a while and will result in a large database.

When the update operation is complete, the db object will emit an 'updated' event.

db.rank()

Run a rank operation on the database. Packages are summed for the current period (rankPeriod (default 30) days up to the previous day) and ranked according to totals. Identical download counts will receive the same rank number.

When the rank operation is complete, the db object will emit an 'ranked' event.

db.packageCount(package, start[, end], callback)

Retrieve the download count for a given package over a given period where start and end are standard Date objects. If no end date is provided, receive just the downloads for the start day. The callback will be provided either with an Error (including in the case that the package can't be found) or an integer with the count.

db.packageCounts(package, start, end, callback)

Like db.packageCount() but provides an array of entries where each entry is a day in the given range. Each element of the array contains an object which has the properties day which is a string in the format YYYY-MM-DD and count which is the total downloads on that day.

db.packageRank(package, callback)

Retrieve the latest rank for a given package. The callback will be provided either with an Error (including in the case that the package can't be found) or an object containing a number of properties related to the rank:

  • package: the name of the package in question
  • rank: the ranking of the package over the latest period for which a ranking was calculated for this package
  • day: the day on which the ranking was taken (recorded as the day prior to the rank() operation)
  • count: the download count for the package during the period for which the ranking was considered
  • total: the total number of packages considered for the ranking this data was produced from

db.topPackages([ count, ]callback)

Generate a list of top ranked packages. By default count is 100 if not provided. If provided, count will be capped to a maximum of 1000. The callback will receive either an Error or an Array containing a rank-sorted list of rank objects as returned by db.packageRank() (above).

db.allPackages

Contains an Array with the names of all of the packages for which download data could be fetched during the last update operation (will be undefined until an update is performed). This value may be cached across instances.

db.periodAllTotal

Contains an integer representing the total number of downloads during the ranking period last used for ranking. This value may be cached across instances.

License

npm-download-db is Copyright (c) 2016 Rod Vagg (rvagg) and licensed under the Apache 2.0 licence. All rights not explicitly granted in the Apache 2.0 license are reserved. See the included LICENSE file for more details.

archived-npm-download-db's People

Contributors

rvagg avatar

Stargazers

 avatar Jake Burden avatar Behzad Abbasi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.