Permalink
Browse files

Added component support

  • Loading branch information...
1 parent 35f5ada commit 6955d61c4cdd2927df95894af682a020f11df57d @tj tj committed May 21, 2012
Showing with 29 additions and 34 deletions.
  1. +24 −30 lib/superagent.js
  2. +5 −0 package.json
  3. +0 −4 test/test.request.js
View
@@ -1,29 +1,17 @@
/*!
* superagent
- * Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
+ * Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed
*/
-var superagent = function(exports){
+;(function(){
/**
- * Expose the request function.
- */
-
- exports = request;
-
- /**
- * Library version.
- */
-
- exports.version = '0.3.0';
-
- /**
* Noop.
*/
- var noop = function(){};
+ function noop(){};
/**
* Determine XHR.
@@ -100,7 +88,7 @@ var superagent = function(exports){
* Expose serialization method.
*/
- exports.serializeObject = serialize;
+ request.serializeObject = serialize;
/**
* Parse the given x-www-form-urlencoded `str`.
@@ -129,7 +117,7 @@ var superagent = function(exports){
* Expose parser.
*/
- exports.parseString = parseString;
+ request.parseString = parseString;
/**
* Default MIME type map.
@@ -138,7 +126,7 @@ var superagent = function(exports){
*
*/
- exports.types = {
+ request.types = {
html: 'text/html'
, json: 'application/json'
, urlencoded: 'application/x-www-form-urlencoded'
@@ -154,7 +142,7 @@ var superagent = function(exports){
*
*/
- exports.serialize = {
+ request.serialize = {
'application/x-www-form-urlencoded': serialize
, 'application/json': JSON.stringify
};
@@ -168,7 +156,7 @@ var superagent = function(exports){
*
*/
- exports.parse = {
+ request.parse = {
'application/x-www-form-urlencoded': parseString
, 'application/json': JSON.parse
};
@@ -324,7 +312,7 @@ var superagent = function(exports){
*/
Response.prototype.parseBody = function(str){
- var parse = exports.parse[this.type];
+ var parse = request.parse[this.type];
return parse
? parse(str)
: null;
@@ -378,7 +366,7 @@ var superagent = function(exports){
* Expose `Response`.
*/
- exports.Response = Response;
+ request.Response = Response;
/**
* Initialize a new `Request` with the given `method` and `url`.
@@ -439,7 +427,7 @@ var superagent = function(exports){
};
/**
- * Set Content-Type to `type`, mapping values from `exports.types`.
+ * Set Content-Type to `type`, mapping values from `request.types`.
*
* Examples:
*
@@ -461,7 +449,7 @@ var superagent = function(exports){
*/
Request.prototype.type = function(type){
- this.set('Content-Type', exports.types[type] || type);
+ this.set('Content-Type', request.types[type] || type);
return this;
};
@@ -572,7 +560,7 @@ var superagent = function(exports){
// querystring
if (query) {
- query = exports.serializeObject(query);
+ query = request.serializeObject(query);
this.url += ~this.url.indexOf('?')
? '&' + query
: '?' + query;
@@ -584,7 +572,7 @@ var superagent = function(exports){
// body
if ('GET' != this.method && 'HEAD' != this.method) {
// serialize stuff
- var serialize = exports.serialize[this.header['content-type']];
+ var serialize = request.serialize[this.header['content-type']];
if (serialize) data = serialize(data);
}
@@ -602,7 +590,7 @@ var superagent = function(exports){
* Expose `Request`.
*/
- exports.Request = Request;
+ request.Request = Request;
/**
* Issue a request:
@@ -735,6 +723,12 @@ var superagent = function(exports){
return req;
};
- return exports;
-
-}({});
+ // expose
+
+ if ('undefined' == typeof exports) {
+ window.request = window.superagent = request;
+ } else {
+ module.exports = request;
+ }
+
+})();
View
@@ -14,6 +14,11 @@
, "should": "*"
, "mocha": "*"
}
+ , "component": {
+ "scripts": {
+ "superagent": "lib/superagent.js"
+ }
+ }
, "main": "index"
, "engines": { "node": "*" }
}
View
@@ -1,10 +1,6 @@
request = superagent;
-test('.version', function(){
- assert(request.version);
-});
-
test('Request inheritance', function(){
assert(request.get('/') instanceof request.Request);
assert(request.get('/') instanceof EventEmitter);

0 comments on commit 6955d61

Please sign in to comment.