npm.io
2.2.2 • Published 2 years ago

list-dependents

Licence
MIT
Version
2.2.2
Deps
5
Size
32 kB
Vulns
0
Weekly
0
Stars
6

list-dependents

Lists all dependents of a project, using npm and ecosyste.ms

npm version npm downloads neostandard javascript style Module type: ESM Types in JS Follow @voxpelli@mastodon.social

Usage

Simple

import { fetchEcosystemDependents } from 'list-dependents';

const result = fetchEcosystemDependents(name);

for await (const { downloads, name, pkg } of fetchEcosystemDependents('npm-run-all2')) {
  console.log(downloads, name, pkg.description);
}
Advanced

See examples/cli.js

API

fetchEcosystemDependents()

Uses the ecosyste.ms API to resolve packages of dependents

Syntax
fetchEcosystemDependents(name, [options]) => AsyncGenerator<EcosystemDependentsItem>
Arguments
EcosystemDependentsOptions
  • filter(meta: EcosystemDependentsMeta) => boolean – function given EcosystemDependentsMeta and should return true for the package to be included
  • loggerBunyanLite – a logger instance
  • maxAgenumber – the maximum age of latest release to include
  • maxPagesnumber – the maximum number of source pages to fetch (there are perPage items per page)
  • minDownloadsLastMonth = 400number – the minimum amount of downloads needed to be returned
  • perPage = 36number – how many items per page to lookup
  • skipPkgboolean – when set skips resolving package.json
Returns

An AsyncGenerator that yields EcosystemDependentsItem objects

fetchEcosystemPackage()

Uses the ecosyste.ms API to resolve a package

Syntax
fetchEcosystemPackage(name, [options]) => Promise<EcosystemDependentsItem|false|undefined>
Arguments
  • namestring – The name of the package to do the lookup for
  • optionsPackageLookupOptions – optional options
PackageLookupOptions
  • clientgot – a client to use for HTTP requests
  • ecosystemsClientgot – a client to use for HTTP requests to ecosyste.ms
  • dependentOnstring – ensure the package depends on this module. Only works when package.json is fetched.
  • filter(meta: EcosystemDependentsMeta) => boolean – function given EcosystemDependentsMeta and should return true for the package to be included
  • loggerBunyanLite– a logger instance
  • skipPkgboolean | (meta: EcosystemDependentsMeta) => boolean – when true skips resolving package.json
  • userAgentstring – an additional more specific user agent to preceed the built in one in the User-Agent header of requests
Returns

A promise resolving to false if the package is actively excluded, undefined if it couldn't be resolved and else EcosystemDependentsItem

createPackageFetchQueue()

Returns a fetchEcosystemPackage equivalent that enforces a maximum concurrent fetches to npm + shares the back-off between all fetches, respecting the Retry-After response headers.

Syntax
const fetchPackage = createPackageFetchQueue([queueOptions]);
const package = await fetchPackage(name, [options]);
Arguments
PackageFetchQueueOptions
  • clientgot – a client to use for HTTP requests
  • loggerBunyanLite– a logger instance
  • userAgentstring – an additional more specific user agent to preceed the built in one in the User-Agent header of requests
Returns

A function equal to fetchEcosystemPackage except that the client, ecosystemClient, logger and userAgent is overriden by the values sent in when it was created

Types

DependentsMeta
export interface DependentsMeta {
  downloads: number;
  name: string;
}
DependentsItem
import type { NormalizedPackageJson } from 'read-pkg';

export interface DependentsItem extends DependentsMeta {
  pkg?: NormalizedPackageJson | undefined;
  targetVersion?: string | undefined,
}
EcosystemDependentsMeta
export interface EcosystemDependentsMeta extends DependentsMeta {
  dependentCount: number | undefined,
  firstRelease: string | undefined,
  latestRelease: string | undefined,
  latestVersion: string | undefined,
  repositoryUrl: string | undefined;
}
EcosystemDependentsItem
export interface EcosystemDependentsItem extends DependentsItem, EcosystemDependentsMeta {}

Similar modules