Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Latest commit

 

History

History
145 lines (112 loc) · 3.29 KB

README.md

File metadata and controls

145 lines (112 loc) · 3.29 KB

pkginfo

Build Status version MIT License semantic-release Renovate - Always up to date Code Coverage

Flexible api to fetch npm package info

Install

NPM

npm install @ma.vu/pkginfo

YARN

yarn add @ma.vu/pkginfo

Usage

pkginfo <object|str>,[ options ] => Promise

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
   }
*/

Override Defaults

You are able to specify what you get in output.

NOTE: It will completely override defaults

Supported Properties

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
   }
*/

Require Exact version

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
   }
*/

Null for not finding package or/and version

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
*/

Version does not exists

info({name: 'react', version: '100.0.0'}).then(data => console.log(data))
/* 
   null
*/