package-missing

1.1.0 • Public • Published

Build Status Coverage Status js-standard-style

package-missing

This, very simple but incredibly useful package contains a Constructor for the PackageMissingError.

Usage

const PackageMissingError = require('package-missing')
 
// What would work if another package was installed?
const task = 'Can not parse the file test.yml'
 
// What packages can be installed to make this work?
const recommendedPackages = [ 'js-yaml', 'yaml' ]
 
const error = new PackageMissingError(task, recommendedPackages)
 
// You can test for this code
error.code === 'EPACKAGEMISSING'
 
// ... or for the package-missing-error
error instanceof PackageMissingError
 
// The input is available to be processed
error.task === task
error.recommendedPackages === recommendedPackages
 
// The message recommends to install the mentioned packages
error.message === error.code + '' + error.message + '\n'
    + 'This error can be easily fixed by running ONE of the following commands:\n'
    + recommendedPackages.map((pkg) => '- $ npm install ' + pkg + ' --save').join('\n')
 
// The error comes with a stack, but if you don't like it ...
typeof error.stack === 'string'

License

ISC

Package Sidebar

Install

npm i package-missing

Weekly Downloads

14

Version

1.1.0

License

ISC

Last publish

Collaborators

  • leichtgewicht