ri

require-implementation

Package that helps you to be okay if some dependency is missing.

Showing:

Popularity

Downloads/wk

3

GitHub Stars

3

Maintenance

Last Commit

5yrs ago

Contributors

0

Package

Dependencies

1

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Build Status Coverage Status js-standard-style

require-implementation

Package that helps you to be okay if some dependency is missing.

Usage

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:

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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100