require-implementation
Package that helps you to be okay if some dependency is missing.
Last updated 4 years ago by leichtgewicht .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install require-implementation 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

2 Versions

  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |