NodeJS Client for the npms.io API
npm i npms-client
You may need to install axios as it is a peer dependency of npms-client.
All query parameters are optional unless otherwise specified. All API endpoints return a Promise.
Perform a search query
terms(required) - an array of strings that represent the terms to search acrossscope- a string that filters by a specific scope (@jaebradley, for example)author- a string that filters by a specific authormaintainer- a string that filters by a specific maintainerexclude- an object that represents certain exclusion rulespackageTypes- an array ofPACKAGE_TYPES. Defaults to[PACKAGE_TYPES.DEPRECATED, PACKAGE_TYPES.INSECURE, PACKAGE_TYPES.UNSTABLE].keywords- an array of strings that filter based on matching values inkeywordsfield inpackage.json
include- an object that represents certain inclusion rulespackageTypes- an array ofPACKAGE_TYPES. Defaults to an empty array.keywords- an array of strings that filter based on matching values inkeywordsfield inpackage.json
boostExactMatches- abooleanthat will boost exact matches. Istrueby default.packageScoreMultiplier- a number that represents the impact that package scores have on the final search scorepackageScoreWeights- an object that represents the impact that certain package attributes have on the package scorequality- a number that represents the impact that quality has on package scorepopularity- a number that represents the impact that popularity has on package scoremaintenance- a number that represents the impact that maintenance has on package score
from- a number that represents the offset to start searching from. Is0, by defaultsize- a number that represents the total number of results to return. Is25, by default.
import { search, PACKAGE_TYPES } from 'npms-client';
// Search for packages that match jae or jaebradley that are not deprecated, insecure, or unstable
await search({ terms: ['jae', 'jaebradley'] });
// Search for packages that match jae that only exclude deprecated packages
await search({
terms: ['jae'],
exclude: {
packageTypes: [PACKAGE_TYPES.DEPRECATED],
keywords: [],
},
});
// Other search examples
const termsSearch = await search({ terms: ['foo', 'bar']});
const scopeSearch = await search({ terms: ['foo', 'bar'], scope: '@jaebradley' });
const authorSearch = await search({ terms: ['foo', 'bar'], author: 'jaebradley' });
const maintainerSearch = await search({ terms: ['foo', 'bar'], maintainer: 'jaebradley' });
const excludeDeprecatedPackages = await search({ terms: ['foo', 'bar'], exclude: { packageTypes: [PACKAGE_TYPES.DEPRECATED] }});
const excludeKeywords = await search({ terms: ['foo', 'bar'], exclude: { keywords: ['jae', 'baebae'] }});
const includeDeprecatedPackages = await search({ terms: ['foo', 'bar'], include: { packageTypes: [PACKAGE_TYPES.DEPRECATED] }});
const includeKeywords = await search({ terms: ['foo', 'bar'], include: { keywords: ['jae', 'baebae'] }});
const sizeSearch = await search({ terms: ['foo', 'bar'], size: 10 });
const offsetSearch = await search({ terms: ['foo', 'bar'], from: 10 });Get suggestions for an array of search terms
terms(required) - an array of strings that represent the terms to search acrosssize- a number that represents the total number of results to return. Is25by default.
import { getSuggestions } from 'npms-client';
await getSuggestions({ terms: ['jae'] });Get information about a specific package
packageName(required) - a string that represents the package name
import { getPackageInformation } from 'npms-client';
await getPackageInformation('npms-client');Get information about a set of packages
packageNames(required) - an array of strings that represent all the package names to get information for
import { getPackagesInformation } from 'npms-client';
await getPackagesInformation(['npms-client']);An enum that is exported by npms-client.
There are three values - PACKAGE_TYPES.DEPRECATED, PACKAGE_TYPES.UNSTABLE, PACKAGE_TYPES.INSECURE.
These values are primarily used to exclude or include certain packages when executing search queries.