Socket
Socket
Sign inDemoInstall

superagent

Package Overview
Dependencies
Maintainers
1
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superagent - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

2

component.json

@@ -5,3 +5,3 @@ {

"description": "awesome http requests",
"version": "0.9.4",
"version": "0.9.6",
"keywords": ["http", "ajax", "request", "agent"],

@@ -8,0 +8,0 @@ "scripts": ["index.js", "lib/superagent.js"],

0.9.7 / 2012-10-19
==================
* fix `.buffer()` `res.text` when no parser matches
0.9.6 / 2012-10-17

@@ -3,0 +8,0 @@ ==================

@@ -388,3 +388,3 @@

*
* @return {Boolean} val
* @return {Boolean} [val]
* @return {Request} for chaining

@@ -395,3 +395,5 @@ * @api public

Request.prototype.buffer = function(val){
this._buffer = val;
this._buffer = false === val
? false
: true;
return this;

@@ -664,8 +666,9 @@ };

if (parse) {
parse(res, function(err, obj){
// TODO: handle error
res.body = obj;
});
}
// default for buffering
parse = parse || exports.parse.text;
parse(res, function(err, obj){
// TODO: handle error
res.body = obj;
});
}

@@ -672,0 +675,0 @@

{
"name": "superagent",
"version": "0.9.6",
"version": "0.9.7",
"description": "elegant & feature rich browser / node HTTP with a fluent API",

@@ -5,0 +5,0 @@ "keywords": [

@@ -176,4 +176,3 @@

return true;
};
/*!
};/*!
* superagent

@@ -184,2 +183,4 @@ * Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>

var root = typeof window == 'undefined' ? this : window;
;(function(){

@@ -202,4 +203,4 @@

function getXHR() {
if (window.XMLHttpRequest
&& ('file:' != window.location.protocol || !window.ActiveXObject)) {
if (root.XMLHttpRequest
&& ('file:' != root.location.protocol || !root.ActiveXObject)) {
return new XMLHttpRequest;

@@ -227,14 +228,2 @@ } else {

/**
* Check if `obj` is a function.
*
* @param {Mixed} obj
* @return {Boolean}
* @api private
*/
function isFunction(obj) {
return 'function' == typeof obj;
}
/**

@@ -249,3 +238,3 @@ * Check if `obj` is an object.

function isObject(obj) {
return null != obj && 'object' == typeof obj;
return obj === Object(obj);
}

@@ -286,6 +275,6 @@

function parseString(str) {
var obj = {}
, pairs = str.split('&')
, parts
, pair;
var obj = {};
var pairs = str.split('&');
var parts;
var pair;

@@ -315,7 +304,7 @@ for (var i = 0, len = pairs.length; i < len; ++i) {

request.types = {
html: 'text/html'
, json: 'application/json'
, urlencoded: 'application/x-www-form-urlencoded'
, 'form': 'application/x-www-form-urlencoded'
, 'form-data': 'application/x-www-form-urlencoded'
html: 'text/html',
json: 'application/json',
urlencoded: 'application/x-www-form-urlencoded',
'form': 'application/x-www-form-urlencoded',
'form-data': 'application/x-www-form-urlencoded'
};

@@ -333,4 +322,4 @@

request.serialize = {
'application/x-www-form-urlencoded': serialize
, 'application/json': JSON.stringify
'application/x-www-form-urlencoded': serialize,
'application/json': JSON.stringify
};

@@ -348,4 +337,4 @@

request.parse = {
'application/x-www-form-urlencoded': parseString
, 'application/json': JSON.parse
'application/x-www-form-urlencoded': parseString,
'application/json': JSON.parse
};

@@ -363,8 +352,8 @@

function parseHeader(str) {
var lines = str.split(/\r?\n/)
, fields = {}
, index
, line
, field
, val;
var lines = str.split(/\r?\n/);
var fields = {};
var index;
var line;
var field;
var val;

@@ -553,2 +542,3 @@ lines.pop(); // trailing CRLF

this.notFound = 404 == status;
this.forbidden = 403 == status;
};

@@ -590,2 +580,17 @@

/**
* Abort the request.
*
* @return {Request}
* @api public
*/
Request.prototype.abort = function(){
if (this.aborted) return;
this.xhr.abort();
this.emit('abort');
this.aborted = true;
return this;
};
/**
* Set header `field` to `val`, or multiple fields with one object.

@@ -673,3 +678,2 @@ *

* request.get('/search')
* .send({ search: 'query' })
* .end(callback)

@@ -719,3 +723,2 @@ *

Request.prototype.send = function(data){
if ('GET' == this.method) return this.query(data);
var obj = isObject(data);

@@ -758,6 +761,6 @@ var type = this.header['content-type'];

Request.prototype.end = function(fn){
var self = this
, xhr = this.xhr = getXHR()
, query = this._query
, data = this._data;
var self = this;
var xhr = this.xhr = getXHR();
var query = this._query;
var data = this._data;

@@ -847,4 +850,4 @@ // store callback

var req = request('GET', url);
if (isFunction(data)) fn = data, data = null;
if (data) req.send(data);
if ('function' == typeof data) fn = data, data = null;
if (data) req.query(data);
if (fn) req.end(fn);

@@ -866,3 +869,3 @@ return req;

var req = request('HEAD', url);
if (isFunction(data)) fn = data, data = null;
if ('function' == typeof data) fn = data, data = null;
if (data) req.send(data);

@@ -942,3 +945,3 @@ if (fn) req.end(fn);

if ('undefined' == typeof exports) {
window.request = window.superagent = request;
root.request = root.superagent = request;
} else {

@@ -945,0 +948,0 @@ module.exports = request;

@@ -5,2 +5,2 @@ /**

* Check if `obj` is an array.
*/function isArray(obj){return"[object Array]"=={}.toString.call(obj)}function EventEmitter(){}EventEmitter.prototype.on=function(name,fn){return this.$events||(this.$events={}),this.$events[name]?isArray(this.$events[name])?this.$events[name].push(fn):this.$events[name]=[this.$events[name],fn]:this.$events[name]=fn,this},EventEmitter.prototype.addListener=EventEmitter.prototype.on,EventEmitter.prototype.once=function(name,fn){var self=this;function on(){self.removeListener(name,on),fn.apply(this,arguments)}return on.listener=fn,this.on(name,on),this},EventEmitter.prototype.removeListener=function(name,fn){if(this.$events&&this.$events[name]){var list=this.$events[name];if(isArray(list)){var pos=-1;for(var i=0,l=list.length;i<l;i++)if(list[i]===fn||list[i].listener&&list[i].listener===fn){pos=i;break}if(pos<0)return this;list.splice(pos,1),list.length||delete this.$events[name]}else(list===fn||list.listener&&list.listener===fn)&&delete this.$events[name]}return this},EventEmitter.prototype.removeAllListeners=function(name){return name===undefined?(this.$events={},this):(this.$events&&this.$events[name]&&(this.$events[name]=null),this)},EventEmitter.prototype.listeners=function(name){return this.$events||(this.$events={}),this.$events[name]||(this.$events[name]=[]),isArray(this.$events[name])||(this.$events[name]=[this.$events[name]]),this.$events[name]},EventEmitter.prototype.emit=function(name){if(!this.$events)return!1;var handler=this.$events[name];if(!handler)return!1;var args=[].slice.call(arguments,1);if("function"==typeof handler)handler.apply(this,args);else{if(!isArray(handler))return!1;var listeners=handler.slice();for(var i=0,l=listeners.length;i<l;i++)listeners[i].apply(this,args)}return!0},function(){var Emitter="undefined"==typeof exports?EventEmitter:require("emitter");function noop(){}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){return null!=obj&&"object"==typeof obj}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("&")}request.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}request.parseString=parseString,request.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},request.serialize={"application/x-www-form-urlencoded":serialize,"application/json":JSON.stringify},request.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 type(str){return str.split(/ *; */).shift()}function params(str){return str.split(/ *; */).reduce(function(obj,str){var parts=str.split(/ *= */),key=parts.shift(),val=parts.shift();return key&&val&&(obj[key]=val),obj},{})}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 ct=this.header["content-type"]||"";this.type=type(ct);var obj=params(ct);for(var key in obj)this[key]=obj[key]},Response.prototype.parseBody=function(str){var parse=request.parse[this.type];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},request.Response=Response;function Request(method,url){var self=this;Emitter.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 Emitter,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}return this.header[field.toLowerCase()]=val,this},Request.prototype.type=function(type){return this.set("Content-Type",request.types[type]||type),this},Request.prototype.query=function(obj){this._query=this._query||{};for(var key in obj)this._query[key]=obj[key];return this},Request.prototype.send=function(data){if("GET"==this.method)return this.query(data);var obj=isObject(data),type=this.header["content-type"];if(obj&&isObject(this._data))for(var key in data)this._data[key]=data[key];else"string"==typeof data?(type||this.type("form"),type=this.header["content-type"],"application/x-www-form-urlencoded"==type?this._data=this._data?this._data+"&"+data:data:this._data=(this._data||"")+data):this._data=data;return obj?(type||this.type("json"),this):this},Request.prototype.end=function(fn){var self=this,xhr=this.xhr=getXHR(),query=this._query,data=this._data;this.callback=fn||noop,xhr.onreadystatechange=function(){4==xhr.readyState&&self.emit("end")},query&&(query=request.serializeObject(query),this.url+=~this.url.indexOf("?")?"&"+query:"?"+query),xhr.open(this.method,this.url,!0);if("GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof data){var serialize=request.serialize[this.header["content-type"]];serialize&&(data=serialize(data))}for(var field in this.header)xhr.setRequestHeader(field,this.header[field]);return xhr.send(data),this},request.Request=Request;function request(method,url){return"function"==typeof url?(new Request("GET",method)).end(url):1==arguments.length?new Request("GET",method):new Request(method,url)}request.get=function(url,data,fn){var req=request("GET",url);return isFunction(data)&&(fn=data,data=null),data&&req.send(data),fn&&req.end(fn),req},request.head=function(url,data,fn){var req=request("HEAD",url);return isFunction(data)&&(fn=data,data=null),data&&req.send(data),fn&&req.end(fn),req},request.del=function(url,fn){var req=request("DELETE",url);return fn&&req.end(fn),req},request.patch=function(url,data,fn){var req=request("PATCH",url);return data&&req.send(data),fn&&req.end(fn),req},request.post=function(url,data,fn){var req=request("POST",url);return data&&req.send(data),fn&&req.end(fn),req},request.put=function(url,data,fn){var req=request("PUT",url);return data&&req.send(data),fn&&req.end(fn),req},"undefined"==typeof exports?window.request=window.superagent=request:module.exports=request}();
*/function isArray(obj){return"[object Array]"=={}.toString.call(obj)}function EventEmitter(){}EventEmitter.prototype.on=function(name,fn){return this.$events||(this.$events={}),this.$events[name]?isArray(this.$events[name])?this.$events[name].push(fn):this.$events[name]=[this.$events[name],fn]:this.$events[name]=fn,this},EventEmitter.prototype.addListener=EventEmitter.prototype.on,EventEmitter.prototype.once=function(name,fn){var self=this;function on(){self.removeListener(name,on),fn.apply(this,arguments)}return on.listener=fn,this.on(name,on),this},EventEmitter.prototype.removeListener=function(name,fn){if(this.$events&&this.$events[name]){var list=this.$events[name];if(isArray(list)){var pos=-1;for(var i=0,l=list.length;i<l;i++)if(list[i]===fn||list[i].listener&&list[i].listener===fn){pos=i;break}if(pos<0)return this;list.splice(pos,1),list.length||delete this.$events[name]}else(list===fn||list.listener&&list.listener===fn)&&delete this.$events[name]}return this},EventEmitter.prototype.removeAllListeners=function(name){return name===undefined?(this.$events={},this):(this.$events&&this.$events[name]&&(this.$events[name]=null),this)},EventEmitter.prototype.listeners=function(name){return this.$events||(this.$events={}),this.$events[name]||(this.$events[name]=[]),isArray(this.$events[name])||(this.$events[name]=[this.$events[name]]),this.$events[name]},EventEmitter.prototype.emit=function(name){if(!this.$events)return!1;var handler=this.$events[name];if(!handler)return!1;var args=[].slice.call(arguments,1);if("function"==typeof handler)handler.apply(this,args);else{if(!isArray(handler))return!1;var listeners=handler.slice();for(var i=0,l=listeners.length;i<l;i++)listeners[i].apply(this,args)}return!0};var root=typeof window=="undefined"?this:window;(function(){var Emitter="undefined"==typeof exports?EventEmitter:require("emitter");function noop(){}function getXHR(){if(root.XMLHttpRequest&&("file:"!=root.location.protocol||!root.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 isObject(obj){return obj===Object(obj)}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("&")}request.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}request.parseString=parseString,request.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},request.serialize={"application/x-www-form-urlencoded":serialize,"application/json":JSON.stringify},request.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 type(str){return str.split(/ *; */).shift()}function params(str){return str.split(/ *; */).reduce(function(obj,str){var parts=str.split(/ *= */),key=parts.shift(),val=parts.shift();return key&&val&&(obj[key]=val),obj},{})}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 ct=this.header["content-type"]||"";this.type=type(ct);var obj=params(ct);for(var key in obj)this[key]=obj[key]},Response.prototype.parseBody=function(str){var parse=request.parse[this.type];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,this.forbidden=403==status},request.Response=Response;function Request(method,url){var self=this;Emitter.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 Emitter,Request.prototype.constructor=Request,Request.prototype.abort=function(){if(this.aborted)return;return this.xhr.abort(),this.emit("abort"),this.aborted=!0,this},Request.prototype.set=function(field,val){if(isObject(field)){for(var key in field)this.set(key,field[key]);return this}return this.header[field.toLowerCase()]=val,this},Request.prototype.type=function(type){return this.set("Content-Type",request.types[type]||type),this},Request.prototype.query=function(obj){this._query=this._query||{};for(var key in obj)this._query[key]=obj[key];return this},Request.prototype.send=function(data){var obj=isObject(data),type=this.header["content-type"];if(obj&&isObject(this._data))for(var key in data)this._data[key]=data[key];else"string"==typeof data?(type||this.type("form"),type=this.header["content-type"],"application/x-www-form-urlencoded"==type?this._data=this._data?this._data+"&"+data:data:this._data=(this._data||"")+data):this._data=data;return obj?(type||this.type("json"),this):this},Request.prototype.end=function(fn){var self=this,xhr=this.xhr=getXHR(),query=this._query,data=this._data;this.callback=fn||noop,xhr.onreadystatechange=function(){4==xhr.readyState&&self.emit("end")},query&&(query=request.serializeObject(query),this.url+=~this.url.indexOf("?")?"&"+query:"?"+query),xhr.open(this.method,this.url,!0);if("GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof data){var serialize=request.serialize[this.header["content-type"]];serialize&&(data=serialize(data))}for(var field in this.header)xhr.setRequestHeader(field,this.header[field]);return xhr.send(data),this},request.Request=Request;function request(method,url){return"function"==typeof url?(new Request("GET",method)).end(url):1==arguments.length?new Request("GET",method):new Request(method,url)}request.get=function(url,data,fn){var req=request("GET",url);return"function"==typeof data&&(fn=data,data=null),data&&req.query(data),fn&&req.end(fn),req},request.head=function(url,data,fn){var req=request("HEAD",url);return"function"==typeof data&&(fn=data,data=null),data&&req.send(data),fn&&req.end(fn),req},request.del=function(url,fn){var req=request("DELETE",url);return fn&&req.end(fn),req},request.patch=function(url,data,fn){var req=request("PATCH",url);return data&&req.send(data),fn&&req.end(fn),req},request.post=function(url,data,fn){var req=request("POST",url);return data&&req.send(data),fn&&req.end(fn),req},request.put=function(url,data,fn){var req=request("PUT",url);return data&&req.send(data),fn&&req.end(fn),req},"undefined"==typeof exports?root.request=root.superagent=request:module.exports=request})();
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc