1.2.1 • Published 8 months ago

npm-digger v1.2.1

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

npm-digger

API wrapper and data extractor on NPM packages without any requirements.

Table of content

Installation

npm i npm-digger

Features

  • No dependencies
  • built-in types system
  • Built-in management of caching data so it won't make unnecessary requests every time you ask for data in a same class.
  • Parsing data that not expose on the official npm API documentations

Usage

npm-digger expose all npm's API data and some more extras from npm's website and internal methods.

The main classes you can use are:

  • Registry - basic information on the npm registry and DB
  • Package - information on a specific package
  • Version - information on a specific version of a package
  • Downloads - statistics data on downloads of a specific package
  • User - information on npm's users
  • Search - results of searching on npm's website
  • Provenance - new feature introduced on Apr 23 and gives you a way to link package to its source repo and specific build instructions used to publish it.

Registry

By init the Registry class, you get access to all registry data npm's API is expose in its documentations.

import { Registry } from 'npm-digger'

const registry = new Registry()

const dbName = await registry.dbName()

console.log(dbName)

// console: "registry"

Functionality

FunctionDescriptionType
data()JSON response as returns from the npm APIRegistryModel
dbName()The DB name of the registrystring
engine()The engine name of the registry DBstring
docCount()The number of docs in the dbnumber
deletedDocCount()The number of deleted docs from the dbnumber
updateSeq()An opaque string that describes the state of the databasenumber
purgeSeq()An opaque string that describes the purge state of the databasenumber
compactRunning()'True' if the database compaction routine is operating on this databaseboolean
diskSize()The size of disk, in bytesnumber
dataSize()The size of data, in bytesnumber
sizes.active()The size of live data inside the database, in bytesnumber
sizes.external()The uncompressed size of database contents in bytesnumber
sizes.file()The size of the database file on disk in bytesnumber
diskFormatVersion()The version of the physical format used for the data when it is stored on disknumber
committedUpdateSeq()number
compactedSeq()number
uuid()string

Package

By init the Package class, you get access to all data npm's API is expose in its documentations in the package route https://registry.npmjs.org/:package. Also, there is some more information that comes from package page on npm website.

This class includes also the Downloads class (can be imported separately too)

import { Package } from 'npm-digger'

const package = new Package('express')

const description = await package.description()

console.log(description)

// console: "Fast, unopinionated, minimalist web framework"

Params

NameDescriptionTypeRequired
packageNameThe name of the package you want to get data on. If package is scoped, should be included toostringyes

Functionality

FunctionDescriptionType
name()Package name (with scope if exist)string
maintainers()npm username list of maintainersNpmPersonModel[]
distTags()object includes main tags of the package{key: name, value: tag}
lastPublish.maintainer()npm username of the maintainer who publish the last releasestring
lastPublish.time()date and time of last publishstring
types.isBundled()'True' if types are bundled in the packageboolean
types.isExternal()'true if types are in external packageboolean
types.entries()object of entries for locate types for the package{key: name, value: entry}
dependents.count()total number of dependents packagesnumber
dependents.listAll()list of all dependents packages with main detailsarray
githubApiRoute()main route for github API of the package repostring
npmUrl()URL for package page on npmstring
latestVersion.data()main data objects of the latest version of the packageJSON
latestVersion.author()author data of the latest version of the package
latestVersion.description()description of the latest version of the packagestring
latestVersion.homepage()homepage of the latest version of the packagestring
latestVersion.repository()link to the repo of the latest version of the packagestring
latestVersion.keywords()keywords of the latest version of the packagestring[]
latestVersion.maintainers()maintainers of the latest version of the package
latestVersion.license()license of the latest version of the packagestring
latestVersion.version()version of the latest version of the packagestring
latestVersion.dependencies()dependencies of the latest version of the package{key: package, value: version}
latestVersion.devDependencies()dev dependencies of the latest version of the package{key: package, value: version}
isPrivate()'true' if package is privateboolean
isSecurityPlaceholder()'true' if security placeholder was published for this packageboolean
readme()readme file contentstring
author()package author datastring
description()package descriptionstring
homepage()homepage of the packagestring
repository()package repository urlstring
keywords()package keywordsstring[]
license()license of the packagestring
currentVersion()current version of the packagestring
versions.data()JSON object with versions data{key: version, value: data about the version}
versions.deprecations()list of deprecated versionsstring[]
versions.releaseDates()JSON object with all releases times{key: release tag, value: date-time string}
id()package name, used as an ID in CouchDBstring
rev()revision number of this version of the document in CouchDBstring
createdTime()time string of package creationstring
lastModified()time string of package last modify timestring
stars.count()number of users who star this packagenumber
stars.usersList()list of users who star this packagestring[]
contributors()list of contributors of this packagearray
bugsReport()object with available URLs for bug report{key: name, value: link}
downloads()downloads classDownloads

Version

By init the Version class, you get access to all version data npm's API is expose in its documentations. If no version number provided, the latest version will be used.

This class includes also the Provenance class (can be imported separately too)

import { Version } from 'npm-digger'

const version = new Version('express', '4.18.2')

const name = await version.name()

console.log(name)

// console: "express@4.18.2"

Params | Name | Description | Type | Required | | ------ | ------ | ------ | ------ | | packageName | package name | string | yes | | packageVersion | requested version number | string | no |

Functionality

FunctionDescriptionType
data()JSON object consist all data of specified version or latest version of a packageJSON
name()The name of packagestring
version()The version of the packagestring
description()The description of the packagestring
author()author informationPersonModel
contributors()List of contributors of the packagearray
keywords()List of keywords of the packagestring[]
engines()the node engines required for this version to run, if specified{key: engine, value: version}
scripts()all scripts defined on the package jason file of the package{key: name, value: script}
id()Id of the package on npm (A.K.A packageName@PackageVersion)string
nodeVersion()the version of node used to publish this versionstring
npmVersion()the version of the npm client used to publish thisstring
dist()Dist object with information about this version distributionDistModel
tarball()url of tarball filestring
directories()directories included by this version
main()the package's entry point (e.g., index.js or main.js)string
license()the SPDX identifier of the package's licensestring
repository()url for repository as given in package.json
bugs()url for bugs reportingstring
homepage()url of the homepage of the packagestring
bin()a mapping of bin commands to set up for this version
dependencies()a mapping of other packages this version depends on to the required semver ranges
peerDependencies()a mapping of package names to the required semver ranges of peer dependencies
devDependencies()a mapping of package names to the required semver ranges of development dependencies
optionalDependencies()an object mapping package names to the required semver ranges of optional dependencies
resolutions()
gitHead()git head signature of the versionstring
maintainers()list of the npm usernames of the people with permission to write to that package
npmUser()the account that did the publishing for that version
hasShrinkwrap()true if this version is known to have a shrinkwrap that must be used to install it; false if this version is known notboolean

Downloads

By init the Downloads class, you get access to analytics data about the package downloads.

import { Downloads } from 'npm-digger'

const downloads = new Downloads('express')

const pointDownload = await downloads.pointDownload('last-week')

console.log(pointDownload)

// console: 
//      {
//          "downloads": 26951829,
//          "start": "2023-08-10",
//          "end": "2023-08-16",
//          "package": "express"
//      }

Params | Name | Description | Type | Required | | ------ | ------ | ------ | ------ | | packageName | package name | string | yes |

Functionality

FunctionDescriptionTypeparams
weeklyDownloads()List of the last 52 weeks from today with their download countJSON
pointDownload()JSON object consist the total downloads count to a specific date or periodJSONperiod - one of Period type options or date string of yyy-mm-dd:yyy-mm-dd format
rangeDownload()JSON object consist list of downloads count for each day in a range of timeJSONperiod - one of Period type options or date string of yyy-mm-dd:yyy-mm-dd format
perVersion()JSON object consist all downloads count of the last week for each version{key: version, value: downloads count}

User

By init the User class, you get access to all available data exist on npm user page

import { User } from 'npm-digger'

const user = new User('username')

const accountType = await user.accountType()

console.log(accountType)

// console: "user"

Params | Name | Description | Type | Required | | ------ | ------ | ------ | ------ | | username | name of required user data | string | yes |

Functionality

FunctionDescriptionType
rawData()JSON object consist all data from npm user pageJSON
accountType()The user type definition by npmstring
name()The user name on npmstring
description()The user description paragraph on npmstring
avatars()An object with links all the existing avatar images sizesobject
avatar.small()Link to small avatar imagestring
avatar.medium()Link to medium avatar imagestring
avatar.large()Link to large avatar imagestring
createdDate()Account creation datestring
updatedDate()Last date of updating the accountstring
id()User id on npmnumber
info.isGithubAccountConnected()'true' if the user associate github account to his npm profileboolean
info.isTwitterAccountConnected()'true' if the user associate twitter account to his npm profileboolean
info.githubAccount()associated github usernamestring
info.twitterAccount()associated twitter usernamestring
info.fullName()The full name provided by the userstring
info.email()The email provided by the userstring
packages.totalNumber()Number of all packages owned by the usernumber
packages.listAll()Array of all the packages owned by the user with their main infoarray
orgs.totalNumber()Number of all organizations the user is associated withnumber
orgs.listAll()Array of all the organizations the user is associated with, with their main infoarray

Search

By init the Search class, you get access npm search engine for package searching as define in the npm documentations.

import { Search } from 'npm-digger'

const search = new Search()

const res = await search.searchPackage('express', 5)

Functionality

FunctionDescriptionType
searchPackage()JSON object consist search results on npm website search engineJSON

Params | Name | Description | Type | Required | | ------ | ------ | ------ | ------ | | query | full text search to apply | string | yes | | size | how many results should be returned | number | no | | from | offset to return results from | number | no | | quality | how much of an effect should quality have on search results | number | no | | popularity | how much of an effect should popularity have on search results | number | no | | maintenance | how much of an effect should maintenance have on search results | number | no |

Provenance

Provenance

By init the Provenance class, you get access npm & github provenance data.

import { Provenance } from 'npm-digger'

const provenance = new Provenance()

const res = await provenance.searchPackage('express', 5)

Params | Name | Description | Type | Required | | ------ | ------ | ------ | ------ | | packageName | package name | string | yes | | packageVersion | requested version number | string | yes |

Functionality

FunctionDescriptionType
data()JSON object consist all provenance data of the specified package versionJSON
subjectAlternativeName()string
certificateIssuer()string
issuer()string
issuerDisplayName()string
buildTrigger()string
buildConfigUri()string
sourceRepositoryUri()string
sourceRepositoryDigest()string
sourceRepositoryRef()string
runInvocationUri()string
expiresAt()string
includedAt()string
resolvedSourceRepositoryCommitUri()string
transparencyLogUri()string
buildConfigDisplayName()string
resolvedBuildConfigUri()string
sourceCommitResponseCode()number
sourceCommitUnreachable()boolean
sourceCommitNotFound()boolean

Vulnerabilities

By init the Vulnerabilities class, you get access osv data about the package and can search for vulnerabilities. this class uses the osv API to fetch the data.

import { Vulnerabilities } from 'npm-digger'

const vulnerabilities = new Vulnerabilities()

const res = await vulnerabilities.number('express', '3.0.0')

console.log(res)
// 1

Params | Name | Description | Type | Required | | ------ | ------ | ------ | ------ | | packageName | package name | string | yes | | packageVersion | requested version number | string | yes |

Functionality

FunctionDescriptionType
data()JSON object consist all provenance data of the specified package versionJSON
number()the number of vulnerabilities for the packagenumber
ids()all vulnerabilities ids for the specified packagestring[]
keyInfo()an object with key info about the vulnerabilities: id, summary, publish date, modified date, affected versions and severityobject
1.2.1

8 months ago

1.2.0

8 months ago

1.1.0

8 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago