https://github.com/martinheidegger/require-implementation
Package that helps you to be okay if some dependency is missing.
https://github.com/martinheidegger/require-implementation
Last synced: 3 months ago
JSON representation
Package that helps you to be okay if some dependency is missing.
- Host: GitHub
- URL: https://github.com/martinheidegger/require-implementation
- Owner: martinheidegger
- Created: 2016-09-04T17:52:04.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-09-05T02:43:36.000Z (almost 9 years ago)
- Last Synced: 2024-12-31T18:35:47.035Z (6 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
[](https://travis-ci.org/martinheidegger/require-implementation) [](https://coveralls.io/github/martinheidegger/require-implementation)
[](http://standardjs.com/)# require-implementation
Package that helps you to be okay if some dependency is missing.
## Usage
```javascript
const impl = require('require-implementation')try {
// Let the user know what action you would like to take.
const math = impl('Trying to do some math.')
// ... then require what ever package could
// installed immediatly.
.require('math')
} catch (e) {
// You can filter other errors by checking for the code
e.code === 'EPACKAGEMISSING'// In recommended packages
e.recommendedPackages == ['math']e.message === 'EPACKAGEMISSING: Trying to do some math.\n'+
'This error can be easily fixed by running the following command:\n'+
'$ npm install --save math'
}```
In case there are multiple options:
```javascript
const impl = require('require-implementation')
try {
// requireFirst lets people know that each of the
const mathSet = impl('Trying to do some math.').requireFirst(['math', 'mathjs'])// You can find out which was ldaded by taking the name
mathSet.name === 'math' || mathSet.name === 'mathjs'// The required package can be found in .pkg
const math = mathSet.pkg
} catch (e) {
// Same error as above
}
```## License
ISC