package-missing
Version:
This very simple but incredibly useful package contains a Constructor for the `PackageMissingError`.
42 lines (28 loc) • 1.55 kB
Markdown
[](https://travis-ci.org/martinheidegger/package-missing) [](https://coveralls.io/github/martinheidegger/package-missing)
[](http://standardjs.com/)
This, very simple but incredibly useful package contains a Constructor for the `PackageMissingError`.
```javascript
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'
```
ISC