npms-io-client

    1.0.8 • Public • Published

    npms-io-client

    npm typescript GitHub stars Twitter Follow

    A universal typed npms.io api client.

    Uses cross-fetch to support both node and browser environments.

    Installation

    yarn add npms-io-client
    npm install npms-io-client

    API

    Search

    import { getSearch } from "npms-io-client";
    
    getSearch({ terms: "chalk" }).then((result) => {
      console.log(result);
      // {
      //   total: 423,
      //   results: [{
      //     package: {
      //       name: 'chalk',
      //       scope: 'unscoped',
      //       version: '4.1.0',
      //       ...
      //     },
      //     ...
      //   ]
      // }
    });

    Types:

    getSearch(query: SearchQuery, from?: number, size?: number) => Promise<SearchResponse>;
    
    type SearchQuery = {
      terms?: string | string[];
    } & SearchQueryQualifiers;
    
    type SearchQueryQualifiers = {
      scope?: string;             // Filter by scope
      author?: string;            // Filter by author
      maintainer?: string;        // Filter by maintainer
      keywords?: string;          // Filter by keywords (Separate multiple keywords with commas. You may also exclude keywords e.g: -framework).
      deprecated?: boolean;       // Filter by deprecated / not deprecated
      unstable?: boolean;         // Filter by unstable (< 1.0.0) / stable (> 1.0.0)
      insecure?: boolean;         // Filter packages with vulnerabilities
      boostExact?: boolean;       // Boost exact matches. Defaults to true.
      scoreEffect?: number;       // Set the effect that package scores have for the final search score, defaults to 15.3
      qualityWeight?: number;     // Set the weight that quality has for the each package score, defaults to 1.95
      popularityWeight?: number;  // Set the weight that popularity has for the each package score, defaults to 3.3
      maintenanceWeight?: number; // Set the weight that the quality has for the each package score, defaults to 2.05
    }
    
    type SearchResponse = {
      total: number;
      results: SearchResult[];
    }
    
    type SearchResult = {
      package: Package;
      score: Score;
      searchScore: number;
    }


    Suggestions

    import { getSuggestions } from "npms-io-client";
    
    getSuggestions("chal").then((results) => {
      console.log(results);
      // [
      //   {
      //     package: {
      //       name: 'chalk',
      //       scope: 'unscoped',
      //       version: '4.1.0',
      //       ...
      //     }
      //   },
      //   ...
      // ]
    })

    Types:

    getSuggestions(query: string, size?: number) => Promise<SuggestionsResponse>;


    Package

    import { getPackage } from "npms-io-client";
    
    getPackage("chalk").then((result) => {
      console.log(result);
      // {
      //   "analyzedAt": "2020-08-03T09:35:15.248Z",
      //   "collected": { "metadata": { ... }, "npm": { ... }, ... },
      //   "evaluation": { "quality": { ... }, "popularity": { ... }, ... }
      //   "score": { "final": 0.966624747619474, "detail": { "quality": 0.9545507877497884, "popularity": 0.9437035852952291, ... } }
      // }
    });

    Types:

    getPackage(name: string) => Promise<PackageResult>;
    
    type PackageResult = {
      analyzedAt: string;
      collected: PackageCollected;
      evaluation: PackageEvaluation;
      score: Score;
    }


    Packages

    import { getPackages } from "npms-io-client";
    
    getPackages(["chalk", "react"]).then((results) => {
      console.log(results);
      // {
      //   chalk: {
      //     analyzedAt: '2020-08-03T09:35:15.248Z',
      //     collected: {
      //       metadata: { ... },
      //       npm: { ... },
      //       github: { ... },
      //       source: { ... }
      //     },
      //     evaluation: { quality: { ... }, popularity: { ... }, maintenance: { ... } },
      //     score: { final: 0.966624747619474, detail: { ... } }
      //   },
      //   react: {
      //     analyzedAt: '2020-08-28T11:38:05.049Z',
      //     collected: {
      //       metadata: { ... },
      //       npm: { ... },
      //       github: { ... },
      //       source: { ... }
      //     },
      //     evaluation: { quality: { ... }, popularity: { ... }, maintenance: { ... } },
      //     score: { final: 0.9387208252920034, detail: { ... } }
      //   }
      // }
    });

    Types:

    getPackages(packages: string[]): Promise<PackagesResponse>;
    
    type PackagesResponse = PackageResult[];


    Dependenciesdependencies


    Dev DependenciesDavid


    License license

    MIT

    Install

    npm i npms-io-client

    DownloadsWeekly Downloads

    2

    Version

    1.0.8

    License

    MIT

    Unpacked Size

    20.7 kB

    Total Files

    21

    Last publish

    Collaborators

    • bconnorwhite