https://github.com/robloach/require-one
:fishing_pole_and_fish: Require the first found module from an array.
https://github.com/robloach/require-one
Last synced: over 1 year ago
JSON representation
:fishing_pole_and_fish: Require the first found module from an array.
- Host: GitHub
- URL: https://github.com/robloach/require-one
- Owner: RobLoach
- License: mit
- Created: 2015-05-30T06:54:09.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2023-01-11T06:48:04.000Z (over 3 years ago)
- Last Synced: 2024-04-28T14:04:42.522Z (about 2 years ago)
- Language: JavaScript
- Homepage: http://npm.im/require-one
- Size: 19.5 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Require One [](https://npmjs.org/package/require-one "View this project on NPM")
[](http://travis-ci.org/RobLoach/require-one "Check this project's build status on TravisCI")
[](https://npmjs.org/package/require-one "View this project on NPM")
[](https://david-dm.org/RobLoach/require-one)
> Load the first package found from the given array.
## Install
Method | Installation
------ | ------------
[npm](http://npmjs.com/package/jquery-once) | `npm install require-one --save`
[component](https://github.com/componentjs/component) | `component install robloach/require-one`
[Composer](https://packagist.org/packages/robloach/require-one) | `composer require require-one`
[Bower](http://bower.io/search/?q=require-one) | `bower install require-one`
## Usage
This works across [CommonJS](https://webpack.github.io/docs/commonjs.html)/[node](http://nodejs.org), [AMD](http://requirejs.org/docs/whyamd.html#amd) and with global variables for the browser.
### CommonJS
This is an example of loading either [jQuery](http://jquery.com), [Zepto](http://zeptojs.com), or [Cheerio](http://cheeriojs.github.io/cheerio) with a CommonJS module loader, like [Node.js](http://nodejs.org).
``` javascript
var $ = requireOne('jquery', 'zepto', 'cheerio');
// => jQuery, Zepto or Cheerio, depending on which one is available.
```
### AMD
This is an example of loading either [jQuery](http://jquery.com), [Zepto](http://zeptojs.com), or [Cheerio](http://cheeriojs.github.io/cheerio) with an AMD module loader, like [Require.js](http://requirejs.org).
``` javascript
require(['require-one'], function(requireOne) {
// Retrieve the first package that is available.
var $ = requireOne('jquery', 'zepto', 'cheerio');
// => jQuery, Zepto or Cheerio, depending on which one is available.
// ...
});
```
### Globals
This is an example of loading either [jQuery](http://jquery.com), [Zepto](http://zeptojs.com), or [Cheerio](http://cheeriojs.github.io/cheerio) without a module loader, i.e. with the browser's global variables.
``` html
var $ = requireOne('jquery', 'jQuery', 'zepto', 'Zepto', 'cheerio');
// => jQuery, Zepto or Cheerio, depending on which one is available.
My Sample Project
```
## License
[MIT](LICENSE.md)