Skip to content

Require and return the first available module.

License

Notifications You must be signed in to change notification settings

rowanmanning/require-first

Repository files navigation

@rowanmanning/require-first

Require and return the first available module.

Table of Contents

Requirements

This library requires the following to run:

Usage

Install with npm:

npm install @rowanmanning/require-first

Load 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
});

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

About

Require and return the first available module.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •