require-one-of
Conditional require with fallback support. Minimal size (>700B), no dependencies.
Install
$ npm install require-one-of --save
Usage
const requireOneOf = require('require-one-of')
// throw an error if `puppeteer` not found
requireOneOf(['puppeteer'])
// throw an error if `puppeteer` or `puppeteer-core` not found
requireOneOf(['puppeteer', 'puppeteer-core'])
// pass fn as second argument for setup custom error
requireOneOf(['puppeteer', 'puppeteer-core'], modules => {
return new TypeError(
`Uh, oh. ${modules
.map(m => `'${m}'`)
.join(',')} not found on dependencies`
)
})
API
requireOneOf(modules, [fn])
modules
Required
Type: array
List of modules to be required. The first found will be resolved.
fn
Type: function
It exposes the function to call to create the error to be returned in case none of the modules are found.
License
require-one-of © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.
kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats