Socket
Socket
Sign inDemoInstall

superagent

Package Overview
Dependencies
1
Maintainers
1
Versions
169
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 0.1.3

6

History.md
0.1.3 / 2011-10-25
==================
* Added error to callback
* Bumped node dep for 0.5.x
0.1.2 / 2011-09-24

@@ -3,0 +9,0 @@ ==================

5

lib/node/index.js

@@ -1,2 +0,1 @@

/*!

@@ -29,3 +28,3 @@ * superagent

exports.version = '0.1.2';
exports.version = '0.1.3';

@@ -574,3 +573,3 @@ /**

req.on('drain', function(){ self.emit('drain'); });
req.on('error', function(){ self.emit('error'); });
req.on('error', function(err){ self.emit('error', err); });

@@ -577,0 +576,0 @@ return req;

4

package.json
{
"name": "superagent"
, "version": "0.1.2"
, "version": "0.1.3"
, "description": "elegant progressive ajax client"

@@ -14,3 +14,3 @@ , "keywords": ["http", "ajax", "request", "agent"]

, "main": "index"
, "engines": { "node": "0.4.x" }
, "engines": { "node": ">= 0.4.0 < 0.7.0" }
}

@@ -59,3 +59,3 @@

* superagent
* Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca>
* Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca>
* MIT Licensed

@@ -93,14 +93,6 @@ */

} else {
try {
return new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {}
try {
return new ActiveXObject('Msxml2.XMLHTTP.6.0');
} catch(e) {}
try {
return new ActiveXObject('Msxml2.XMLHTTP.3.0');
} catch(e) {}
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {}
try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
}

@@ -131,3 +123,3 @@ return false;

function isFunction(obj) {
return obj && obj.call && obj.apply;
return 'function' == typeof obj;
}

@@ -213,2 +205,3 @@

, urlencoded: 'application/x-www-form-urlencoded'
, 'form-data': 'application/x-www-form-urlencoded'
};

@@ -421,2 +414,3 @@

// sugar
this.accepted = 202 == status;
this.noContent = 204 == status || 1223 == status;

@@ -551,3 +545,3 @@ this.badRequest = 400 == status;

* request.post('/user')
* .type('urlencoded')
* .type('form-data')
* .data('name=tj')

@@ -558,3 +552,3 @@ * .end(callback)

* request.post('/user')
* .type('urlencoded')
* .type('form-data')
* .data({ name: 'tj' })

@@ -657,7 +651,2 @@ * .end(callback)

if (serialize) data = serialize(data);
// content-length
if (null != data && !this.header['content-length']) {
this.set('Content-Length', data.length);
}
}

@@ -682,6 +671,12 @@

/**
* Shortcut for `new Request(method, url)`.
* Issue a request:
*
* Examples:
*
* request('GET', '/users').end(callback)
* request('/users').end(callback)
* request('/users', callback)
*
* @param {String} method
* @param {String} url
* @param {String|Function} url or callback
* @return {Request}

@@ -692,2 +687,12 @@ * @api public

function request(method, url) {
// callback
if ('function' == typeof url) {
return new Request('GET', method).end(url);
}
// url first
if (1 == arguments.length) {
return new Request('GET', method);
}
return new Request(method, url);

@@ -694,0 +699,0 @@ }

@@ -8,2 +8,2 @@ /*!

* Slice reference.
*/var slice=[].slice;function EventEmitter(){this.callbacks={}}EventEmitter.prototype.on=function(event,fn){(this.callbacks[event]=this.callbacks[event]||[]).push(fn);return this},EventEmitter.prototype.emit=function(event){var args=slice.call(arguments,1),callbacks=this.callbacks[event];if(callbacks)for(var i=0,len=callbacks.length;i<len;++i)callbacks[i](args);return this};var superagent=function(exports){exports=request,exports.version="0.1.1";var noop=function(){};function getXHR(){if(window.XMLHttpRequest&&("file:"!=window.location.protocol||!window.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}return!1}var trim="".trim?function(s){return s.trim()}:function(s){return s.replace(/(^\s*|\s*$)/g,"")};function isFunction(obj){return obj&&obj.call&&obj.apply}function isObject(obj){if(null==obj)return!1;var cons=obj.constructor;return cons&&Object==cons}function serialize(obj){if(!isObject(obj))return obj;var pairs=[];for(var key in obj)pairs.push(encodeURIComponent(key)+"="+encodeURIComponent(obj[key]));return pairs.join("&")}exports.serializeObject=serialize;function parseString(str){var obj={},pairs=str.split("&"),parts,pair;for(var i=0,len=pairs.length;i<len;++i)pair=pairs[i],parts=pair.split("="),obj[decodeURIComponent(parts[0])]=decodeURIComponent(parts[1]);return obj}exports.parseString=parseString,exports.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded"},exports.serialize={"application/x-www-form-urlencoded":serialize,"application/json":JSON.stringify},exports.parse={"application/x-www-form-urlencoded":parseString,"application/json":JSON.parse};function parseHeader(str){var lines=str.split(/\r?\n/),fields={},index,line,field,val;lines.pop();for(var i=0,len=lines.length;i<len;++i)line=lines[i],index=line.indexOf(":"),field=line.slice(0,index).toLowerCase(),val=trim(line.slice(index+1)),fields[field]=val;return fields}function Response(xhr,options){options=options||{},this.xhr=xhr,this.text=xhr.responseText,this.setStatusProperties(xhr.status),this.header=parseHeader(xhr.getAllResponseHeaders()),this.setHeaderProperties(this.header),this.body=this.parseBody(this.text)}Response.prototype.setHeaderProperties=function(header){var params=(this.header["content-type"]||"").split(/ *; */);this.contentType=params.shift(),this.setParams(params)},Response.prototype.setParams=function(params){var param;for(var i=0,len=params.length;i<len;++i)param=params[i].split(/ *= */),this[param[0]]=param[1]},Response.prototype.parseBody=function(str){var parse=exports.parse[this.contentType];return parse?parse(str):null},Response.prototype.setStatusProperties=function(status){var type=status/100|0;this.status=status,this.statusType=type,this.info=1==type,this.ok=2==type,this.clientError=4==type,this.serverError=5==type,this.error=4==type||5==type,this.noContent=204==status||1223==status,this.badRequest=400==status,this.unauthorized=401==status,this.notAcceptable=406==status,this.notFound=404==status},exports.Response=Response;function Request(method,url){var self=this;EventEmitter.call(this),this.method=method,this.url=url,this.header={},this.set("X-Requested-With","XMLHttpRequest"),this.on("end",function(){self.callback(new Response(self.xhr))})}Request.prototype=new EventEmitter,Request.prototype.constructor=Request,Request.prototype.set=function(field,val){if(isObject(field)){for(var key in field)this.set(key,field[key]);return this}this.header[field.toLowerCase()]=val;return this},Request.prototype.type=function(type){this.set("Content-Type",exports.types[type]||type);return this},Request.prototype.data=function(data){var obj=isObject(data);if(obj&&isObject(this._data))for(var key in data)this._data[key]=data[key];else this._data=data;if("GET"==this.method)return this;if(!obj)return this;if(this.header["content-type"])return this;this.type("json");return this},Request.prototype.send=function(data,fn){isFunction(data)?this.end(data):data?this.data(data).end(fn):this.end();return this},Request.prototype.end=function(fn){var self=this,xhr=this.xhr=getXHR(),data=this._data||null;this.callback=fn||noop,xhr.onreadystatechange=function(){4==xhr.readyState&&self.emit("end")},"GET"==this.method&&null!=data&&(this.url+="?"+exports.serializeObject(data),data=null),xhr.open(this.method,this.url,!0);if("GET"!=this.method&&"HEAD"!=this.method){var serialize=exports.serialize[this.header["content-type"]];serialize&&(data=serialize(data)),null!=data&&!this.header["content-length"]&&this.set("Content-Length",data.length)}for(var field in this.header)xhr.setRequestHeader(field,this.header[field]);xhr.send(data);return this},exports.Request=Request;function request(method,url){return new Request(method,url)}request.get=function(url,data,fn){var req=request("GET",url);isFunction(data)&&(fn=data,data=null),data&&req.data(data),fn&&req.end(fn);return req},request.del=function(url,fn){var req=request("DELETE",url);fn&&req.end(fn);return req},request.post=function(url,data,fn){var req=request("POST",url);data&&req.data(data),fn&&req.end(fn);return req},request.put=function(url,data,fn){var req=request("PUT",url);data&&req.data(data),fn&&req.end(fn);return req};return exports}({})
*/var slice=[].slice;function EventEmitter(){this.callbacks={}}EventEmitter.prototype.on=function(event,fn){(this.callbacks[event]=this.callbacks[event]||[]).push(fn);return this},EventEmitter.prototype.emit=function(event){var args=slice.call(arguments,1),callbacks=this.callbacks[event];if(callbacks)for(var i=0,len=callbacks.length;i<len;++i)callbacks[i](args);return this};var superagent=function(exports){exports=request,exports.version="0.1.1";var noop=function(){};function getXHR(){if(window.XMLHttpRequest&&("file:"!=window.location.protocol||!window.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}return!1}var trim="".trim?function(s){return s.trim()}:function(s){return s.replace(/(^\s*|\s*$)/g,"")};function isFunction(obj){return"function"==typeof obj}function isObject(obj){if(null==obj)return!1;var cons=obj.constructor;return cons&&Object==cons}function serialize(obj){if(!isObject(obj))return obj;var pairs=[];for(var key in obj)pairs.push(encodeURIComponent(key)+"="+encodeURIComponent(obj[key]));return pairs.join("&")}exports.serializeObject=serialize;function parseString(str){var obj={},pairs=str.split("&"),parts,pair;for(var i=0,len=pairs.length;i<len;++i)pair=pairs[i],parts=pair.split("="),obj[decodeURIComponent(parts[0])]=decodeURIComponent(parts[1]);return obj}exports.parseString=parseString,exports.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},exports.serialize={"application/x-www-form-urlencoded":serialize,"application/json":JSON.stringify},exports.parse={"application/x-www-form-urlencoded":parseString,"application/json":JSON.parse};function parseHeader(str){var lines=str.split(/\r?\n/),fields={},index,line,field,val;lines.pop();for(var i=0,len=lines.length;i<len;++i)line=lines[i],index=line.indexOf(":"),field=line.slice(0,index).toLowerCase(),val=trim(line.slice(index+1)),fields[field]=val;return fields}function Response(xhr,options){options=options||{},this.xhr=xhr,this.text=xhr.responseText,this.setStatusProperties(xhr.status),this.header=parseHeader(xhr.getAllResponseHeaders()),this.setHeaderProperties(this.header),this.body=this.parseBody(this.text)}Response.prototype.setHeaderProperties=function(header){var params=(this.header["content-type"]||"").split(/ *; */);this.contentType=params.shift(),this.setParams(params)},Response.prototype.setParams=function(params){var param;for(var i=0,len=params.length;i<len;++i)param=params[i].split(/ *= */),this[param[0]]=param[1]},Response.prototype.parseBody=function(str){var parse=exports.parse[this.contentType];return parse?parse(str):null},Response.prototype.setStatusProperties=function(status){var type=status/100|0;this.status=status,this.statusType=type,this.info=1==type,this.ok=2==type,this.clientError=4==type,this.serverError=5==type,this.error=4==type||5==type,this.accepted=202==status,this.noContent=204==status||1223==status,this.badRequest=400==status,this.unauthorized=401==status,this.notAcceptable=406==status,this.notFound=404==status},exports.Response=Response;function Request(method,url){var self=this;EventEmitter.call(this),this.method=method,this.url=url,this.header={},this.set("X-Requested-With","XMLHttpRequest"),this.on("end",function(){self.callback(new Response(self.xhr))})}Request.prototype=new EventEmitter,Request.prototype.constructor=Request,Request.prototype.set=function(field,val){if(isObject(field)){for(var key in field)this.set(key,field[key]);return this}this.header[field.toLowerCase()]=val;return this},Request.prototype.type=function(type){this.set("Content-Type",exports.types[type]||type);return this},Request.prototype.data=function(data){var obj=isObject(data);if(obj&&isObject(this._data))for(var key in data)this._data[key]=data[key];else this._data=data;if("GET"==this.method)return this;if(!obj)return this;if(this.header["content-type"])return this;this.type("json");return this},Request.prototype.send=function(data,fn){isFunction(data)?this.end(data):data?this.data(data).end(fn):this.end();return this},Request.prototype.end=function(fn){var self=this,xhr=this.xhr=getXHR(),data=this._data||null;this.callback=fn||noop,xhr.onreadystatechange=function(){4==xhr.readyState&&self.emit("end")},"GET"==this.method&&null!=data&&(this.url+="?"+exports.serializeObject(data),data=null),xhr.open(this.method,this.url,!0);if("GET"!=this.method&&"HEAD"!=this.method){var serialize=exports.serialize[this.header["content-type"]];serialize&&(data=serialize(data))}for(var field in this.header)xhr.setRequestHeader(field,this.header[field]);xhr.send(data);return this},exports.Request=Request;function request(method,url){if("function"==typeof url)return(new Request("GET",method)).end(url);if(1==arguments.length)return new Request("GET",method);return new Request(method,url)}request.get=function(url,data,fn){var req=request("GET",url);isFunction(data)&&(fn=data,data=null),data&&req.data(data),fn&&req.end(fn);return req},request.del=function(url,fn){var req=request("DELETE",url);fn&&req.end(fn);return req},request.post=function(url,data,fn){var req=request("POST",url);data&&req.data(data),fn&&req.end(fn);return req},request.put=function(url,data,fn){var req=request("PUT",url);data&&req.data(data),fn&&req.end(fn);return req};return exports}({})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc