Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a UMD wrapper for direct delivery #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Jason Smith Work <[email protected]>
Jason Smith <[email protected]>
maxogden <[email protected]>
Abbey Sparrow via Google <[email protected]>
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ Deploy `example-built.js` to your web site and use it from your page.
```html
<script src="example-built.js"></script> <!-- Runs the request, outputs the result to the console -->
```

## UMD

`browser-request` is [UMD](https://github.com/umdjs/umd) wrapped, allowing you to serve it directly to the browser from wherever you store the module.

```html
<script src="/node_modules/browser-request/index.js"></script> <!-- Assigns the module to window.request -->
```

You may also use an [AMD loader](http://requirejs.org/docs/whyamd.html) by referencing the same file in your loader [config](http://requirejs.org/docs/api.html#config).

## License

Browser Request is licensed under the Apache 2.0 license.
Expand Down
22 changes: 21 additions & 1 deletion index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// UMD HEADER START
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.returnExports = factory();
}
}(this, function () {
// UMD HEADER END

var XHR = XMLHttpRequest
if (!XHR) throw new Error('missing XMLHttpRequest')
request.log = {
Expand Down Expand Up @@ -471,4 +488,7 @@ function b64_enc (data) {

return enc;
}
module.exports = request;
return request;
//UMD FOOTER START
}));
//UMD FOOTER END