Conditional require with fallback support. Minimal size (>700B), no dependencies.
$ npm install require-one-of --save
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`
)
})
Required
Type: array
List of modules to be required. The first found will be resolved.
Type: function
It exposes the function to call to create the error to be returned in case none of the modules are found.
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