@rowanmanning/require-first v5.1.0
@rowanmanning/require-first
Require and return the first available module.
Requirements
This library requires the following to run:
- Node.js 20+
Usage
Install with npm:
npm install @rowanmanning/require-firstLoad the library into your code with a require call:
const { requireFirst } = require('@rowanmanning/require-first');Require modules by passing in an array of paths. The first one that successfully resolves will be returned.
const thing = requireFirst(['thing1', './thing2', '~/../example/thing3']);By default, an error will be thrown if none of the modules are found. You can change this behaviour to return a default value specified by you:
const thing = requireFirst(['thing1', './thing2', '~/../example/thing3'], {
example: true
});Migration
A new major version of this project is released if breaking changes are introduced. We maintain a migration guide to help users migrate between these versions.
Contributing
The contributing guide is available here. All contributors must follow this library's code of conduct.
License
Licensed under the MIT license. Copyright © 2019, Rowan Manning
5 months ago
8 months ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
4 years ago
4 years ago
6 years ago
6 years ago
6 years ago
7 years ago