require-one
Advanced tools
Comparing version 0.2.0 to 1.0.0
@@ -18,3 +18,10 @@ { | ||
} | ||
}, | ||
"archive": { | ||
"exclude": [ | ||
"example", | ||
"test", | ||
".*" | ||
] | ||
} | ||
} |
{ | ||
"name": "require-one", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Require the first found package from an array.", | ||
@@ -25,3 +25,9 @@ "main": "require-one.js", | ||
"testit": "^2.0.2" | ||
}, | ||
"browser": "./require-one.js", | ||
"browserPackage": { | ||
"files": [ | ||
"require-one.js" | ||
] | ||
} | ||
} |
@@ -9,3 +9,2 @@ # Require One [![NPM version](https://img.shields.io/npm/v/require-one.svg)](https://npmjs.org/package/require-one "View this project on NPM") | ||
## Install | ||
@@ -19,3 +18,2 @@ | ||
## Usage | ||
@@ -25,7 +23,9 @@ | ||
### CommonJS/Node | ||
### 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 or Cheerio, depending on which one is loaded first. | ||
// => jQuery, Zepto or Cheerio, depending on which one is available. | ||
``` | ||
@@ -35,2 +35,4 @@ | ||
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 | ||
@@ -40,4 +42,4 @@ require(['require-one'], function(requireOne) { | ||
// Retrieve the first package that is available. | ||
var $ = requireOne('jquery', 'cheerio'); | ||
// => jQuery or Cheerio, depending on which one is loaded first. | ||
var $ = requireOne('jquery', 'zepto', 'cheerio'); | ||
// => jQuery, Zepto or Cheerio, depending on which one is available. | ||
@@ -50,2 +52,4 @@ // ... | ||
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, like with browser globals. | ||
``` html | ||
@@ -56,3 +60,3 @@ <!DOCTYPE html> | ||
<title>My Sample Project</title> | ||
<script type="text/javascript" src="../require-one.js"></script> | ||
<script type="text/javascript" src="path/to/require-one.js"></script> | ||
<script> | ||
@@ -67,1 +71,5 @@ var con = requireOne('nope', 'nopers', 'nopes', 'console'); | ||
</html> | ||
## License | ||
[MIT](LICENSE.md) |
@@ -15,3 +15,5 @@ /*! | ||
if (typeof define === 'function' && define.amd) { | ||
// AMD | ||
/** | ||
* AMD | ||
*/ | ||
define(function (require) { | ||
@@ -23,9 +25,11 @@ // Use AMD's require() wrapper. | ||
} else if (typeof exports === 'object') { | ||
// CommonJS | ||
/** | ||
* CommonJS | ||
*/ | ||
module.exports = factory(require) | ||
} else { | ||
/** | ||
* Our own require function for the global scope. | ||
* Global scope | ||
*/ | ||
function globalRequire (packageName) { | ||
root.requireOne = factory(function (packageName) { | ||
if (root[packageName]) { | ||
@@ -35,4 +39,3 @@ return root[packageName] | ||
throw new Error('Package ' + packageName + 'not found') | ||
} | ||
root.requireOne = factory(globalRequire) | ||
}) | ||
} | ||
@@ -43,6 +46,10 @@ }(this, function (requireFunction) { | ||
* | ||
* @arg {(...string|string[])} packages - An array of strings representing | ||
* which packages to load, or an argument list of strings to load. | ||
* @param {(...string|string[])} packages - An array or argument list of | ||
* strings representing which packages to load. | ||
* | ||
* @returns The first loaded package from the packages parameter. | ||
* @returns The first available package. Throws an error otherwise. | ||
* | ||
* @throws Throws an Error when none of the packages could be loaded. | ||
* | ||
* @global | ||
*/ | ||
@@ -49,0 +56,0 @@ return function requireFromArray (packages) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
8649
15
126
0
68
1
80