From 30d01e5f4ec45ab17fda6856a303d36ff974fb3d Mon Sep 17 00:00:00 2001 From: Abbey Sparrow Date: Thu, 13 Nov 2014 13:05:21 -0800 Subject: [PATCH 1/2] added a UMD header to support AMD and browser globals, and commonjs --- index.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) mode change 100644 => 100755 index.js diff --git a/index.js b/index.js old mode 100644 new mode 100755 index 1a77c6f..51ac8b4 --- a/index.js +++ b/index.js @@ -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 = { @@ -471,4 +488,7 @@ function b64_enc (data) { return enc; } -module.exports = request; + return request; +//UMD FOOTER START +})); +//UMD FOOTER END From 15527be3351ff34e7d80144016ab13d7f81bff89 Mon Sep 17 00:00:00 2001 From: Abbey Sparrow Date: Thu, 13 Nov 2014 13:18:27 -0800 Subject: [PATCH 2/2] added readme notes for UMD, added myself as a contributor so Google gets credit --- AUTHORS | 1 + README.md | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/AUTHORS b/AUTHORS index b80f42a..0385a2e 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ Jason Smith Work Jason Smith maxogden +Abbey Sparrow via Google diff --git a/README.md b/README.md index 1213c28..ad962db 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,17 @@ Deploy `example-built.js` to your web site and use it from your page. ```html ``` + +## 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 + +``` + +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.