Package detail

require-one

RobLoach24.5kMIT1.0.3

Require the first found package from an array.

require

readme

Require One NPM version

Build Status NPM downloads Dependency Status

Load the first package found from the given array.

Install

Method Installation
npm npm install require-one --save
component component install robloach/require-one
Composer composer require require-one
Bower bower install require-one

Usage

This works across CommonJS/node, AMD and with global variables for the browser.

CommonJS

This is an example of loading either jQuery, Zepto, or Cheerio with a CommonJS module loader, like Node.js.

var $ = requireOne('jquery', 'zepto', 'cheerio');
// => jQuery, Zepto or Cheerio, depending on which one is available.

AMD

This is an example of loading either jQuery, Zepto, or Cheerio with an AMD module loader, like Require.js.

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, Zepto, or Cheerio without a module loader, i.e. with the browser's global variables.

<!DOCTYPE html>
<html>
  <head>
    <script type="text/javascript" src="path/to/require-one.js"></script>
    <script>
      var $ = requireOne('jquery', 'jQuery', 'zepto', 'Zepto', 'cheerio');
      // => jQuery, Zepto or Cheerio, depending on which one is available.
    </script>
  </head>
  <body>
    <h1>My Sample Project</h1>
  </body>
</html>

License

MIT

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

[1.0.3] - 2016-12-24

Changed

  • Updated xo coding style

[1.0.2] - 2015-03-29

Changed

1.0.1 - 2015-09-26

Changed

[1.0.0] - 2015-07-09

Added

  • First stable release