Flexible api to fetch npm package info
npm install @ma.vu/pkginfo
yarn add @ma.vu/pkginfo
Accepts name of package, returns name, version & description (default)
const pkginfo = require('@ma.vu/pkginfo')
pkginfo('got').then(data => console.log(data))
/*
{
name: 'got',
version: '9.6.0',
'description: 'Simplified HTTP request
}
*/
You are able to specify what you get in output.
NOTE: It will completely override defaults
homepage => str(url)
repository => str
latest => semver
name => str
description => str
version => semver
author => str || arr
license => str
devDependencies => Int
dependencies => Int
const pkginfo = require('@ma.vu/pkginfo')
info('got', [
'name',
'description',
'author',
'dependencies',
'devDependencies',
]).then(data => console.log(data))
/*
{
name: 'got',
description: 'Simplified HTTP request
author: 'sindresorhus',
dependencies: 11,
devDependencies: 16
}
*/
It accepts object, and exact version of package you fetching, and now version
is your version you fetching, and latest
is latest available version
const pkginfo = require('@ma.vu/pkginfo')
info({ name: 'got', version: '3.0.0' }, [
'name',
'version',
'latest',
'dependencies',
'devDependencies',
]).then(data => console.log(data))
/*
{
name: 'got',
version: '3.0.0',
latest: 9.6.0,
dependencies: 10,
devDependencies: 5
}
*/
Rationale for this is, if you query db and query can't yield the result, you will get null, error will not be thrown. The same is for version
info('not-existing-package-name').then(data => console.log(data))
/*
null
*/
info({name: 'react', version: '100.0.0'}).then(data => console.log(data))
/*
null
*/