2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00

Using more strict eslint rules

This commit is contained in:
Matt Zabriskie
2015-12-14 20:06:57 -07:00
parent 2b147fb0b7
commit f28a4a8248
16 changed files with 230 additions and 93 deletions
+136 -1
View File
@@ -9,6 +9,141 @@
"node": true "node": true
}, },
"rules": { "rules": {
"quotes": [2, "single"] /**
* Strict mode
*/
"strict": [2, "global"], // http://eslint.org/docs/rules/strict
/**
* Variables
*/
"no-shadow": 2, // http://eslint.org/docs/rules/no-shadow
"no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names
"no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars
"vars": "local",
"args": "after-used"
}],
"no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define
/**
* Possible errors
*/
"comma-dangle": [2, "never"], // http://eslint.org/docs/rules/comma-dangle
"no-cond-assign": [2, "except-parens"], // http://eslint.org/docs/rules/no-cond-assign
"no-console": 1, // http://eslint.org/docs/rules/no-console
"no-debugger": 1, // http://eslint.org/docs/rules/no-debugger
"no-alert": 1, // http://eslint.org/docs/rules/no-alert
"no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition
"no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys
"no-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case
"no-empty": 2, // http://eslint.org/docs/rules/no-empty
"no-ex-assign": 2, // http://eslint.org/docs/rules/no-ex-assign
"no-extra-boolean-cast": 0, // http://eslint.org/docs/rules/no-extra-boolean-cast
"no-extra-semi": 2, // http://eslint.org/docs/rules/no-extra-semi
"no-func-assign": 2, // http://eslint.org/docs/rules/no-func-assign
"no-inner-declarations": 2, // http://eslint.org/docs/rules/no-inner-declarations
"no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp
"no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace
"no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls
"no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays
"no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable
"use-isnan": 2, // http://eslint.org/docs/rules/use-isnan
"block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var
/**
* Best practices
*/
"consistent-return": 2, // http://eslint.org/docs/rules/consistent-return
"curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly
"default-case": 2, // http://eslint.org/docs/rules/default-case
"dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation
"allowKeywords": true
}],
"eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq
"guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in
"no-caller": 2, // http://eslint.org/docs/rules/no-caller
"no-else-return": 2, // http://eslint.org/docs/rules/no-else-return
"no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null
"no-eval": 2, // http://eslint.org/docs/rules/no-eval
"no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native
"no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind
"no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough
"no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal
"no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval
"no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks
"no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func
"no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str
"no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign
"no-new": 2, // http://eslint.org/docs/rules/no-new
"no-new-func": 2, // http://eslint.org/docs/rules/no-new-func
"no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers
"no-octal": 2, // http://eslint.org/docs/rules/no-octal
"no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape
"no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign
"no-proto": 2, // http://eslint.org/docs/rules/no-proto
"no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare
"no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign
"no-script-url": 2, // http://eslint.org/docs/rules/no-script-url
"no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare
"no-sequences": 2, // http://eslint.org/docs/rules/no-sequences
"no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal
"no-with": 2, // http://eslint.org/docs/rules/no-with
"radix": 2, // http://eslint.org/docs/rules/radix
"vars-on-top": 0, // http://eslint.org/docs/rules/vars-on-top
"wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife
"yoda": 2, // http://eslint.org/docs/rules/yoda
/**
* Style
*/
"indent": [2, 2], // http://eslint.org/docs/rules/indent
"brace-style": [2, // http://eslint.org/docs/rules/brace-style
"1tbs", {
"allowSingleLine": true
}],
"quotes": [
2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes
],
"camelcase": [2, { // http://eslint.org/docs/rules/camelcase
"properties": "never"
}],
"comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing
"before": false,
"after": true
}],
"comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style
"eol-last": 2, // http://eslint.org/docs/rules/eol-last
"func-names": 1, // http://eslint.org/docs/rules/func-names
"key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing
"beforeColon": false,
"afterColon": true
}],
"new-cap": [2, { // http://eslint.org/docs/rules/new-cap
"newIsCap": true
}],
"no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines
"max": 2
}],
"no-nested-ternary": 2, // http://eslint.org/docs/rules/no-nested-ternary
"no-new-object": 2, // http://eslint.org/docs/rules/no-new-object
"no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func
"no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces
"no-extra-parens": [2, "functions"], // http://eslint.org/docs/rules/no-extra-parens
"no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle
"one-var": [2, "never"], // http://eslint.org/docs/rules/one-var
"padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks
"semi": [2, "always"], // http://eslint.org/docs/rules/semi
"semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing
"before": false,
"after": true
}],
"space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords
"space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks
"space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren
"space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops
"space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
"spaced-comment": [2, "always", {// http://eslint.org/docs/rules/spaced-comment
"markers": ["global", "eslint"]
}]
} }
} }
+18 -18
View File
@@ -68,35 +68,35 @@ module.exports = function httpAdapter(resolve, reject, config) {
// Create the request // Create the request
var transport = parsed.protocol === 'https:' ? https : http; var transport = parsed.protocol === 'https:' ? https : http;
var req = transport.request(options, function (res) { var req = transport.request(options, function handleResponse(res) {
// uncompress the response body transparently if required // uncompress the response body transparently if required
var stream = res; var stream = res;
switch(res.headers['content-encoding']) { switch (res.headers['content-encoding']) {
case 'gzip': /*eslint default-case:0*/
case 'compress': case 'gzip':
case 'deflate': { case 'compress':
// add the unzipper to the body stream processing pipeline case 'deflate':
stream = stream.pipe(zlib.createUnzip()); // add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
// remove the content-encoding in order to not confuse downstream operations // remove the content-encoding in order to not confuse downstream operations
delete res.headers['content-encoding']; delete res.headers['content-encoding'];
} break;
} }
var responseBuffer = []; var responseBuffer = [];
stream.on('data', function (chunk) { stream.on('data', function handleStreamData(chunk) {
responseBuffer.push(chunk); responseBuffer.push(chunk);
}); });
stream.on('end', function () { stream.on('end', function handleStreamEnd() {
var data = Buffer.concat(responseBuffer); var d = Buffer.concat(responseBuffer);
if (config.responseType !== 'arraybuffer') { if (config.responseType !== 'arraybuffer') {
data = data.toString('utf8'); d = d.toString('utf8');
} }
var response = { var response = {
data: transformData( data: transformData(
data, d,
res.headers, res.headers,
config.transformResponse config.transformResponse
), ),
@@ -114,12 +114,12 @@ module.exports = function httpAdapter(resolve, reject, config) {
}); });
// Handle errors // Handle errors
req.on('error', function (err) { req.on('error', function handleRequestError(err) {
reject(err); reject(err);
}); });
// Handle request timeout // Handle request timeout
req.setTimeout(config.timeout, function () { req.setTimeout(config.timeout, function handleRequestTimeout() {
req.abort(); req.abort();
}); });
+10 -11
View File
@@ -29,13 +29,13 @@ module.exports = function xhrAdapter(resolve, reject, config) {
delete requestHeaders['Content-Type']; // Let the browser set it delete requestHeaders['Content-Type']; // Let the browser set it
} }
var adapter = (XMLHttpRequest || ActiveXObject); var Adapter = (XMLHttpRequest || ActiveXObject);
var loadEvent = 'onreadystatechange'; var loadEvent = 'onreadystatechange';
var xDomain = false; var xDomain = false;
// For IE 8/9 CORS support // For IE 8/9 CORS support
if(!isURLSameOrigin(config.url) && window.XDomainRequest){ if (!isURLSameOrigin(config.url) && window.XDomainRequest) {
adapter = window.XDomainRequest; Adapter = window.XDomainRequest;
loadEvent = 'onload'; loadEvent = 'onload';
xDomain = true; xDomain = true;
} }
@@ -44,18 +44,18 @@ module.exports = function xhrAdapter(resolve, reject, config) {
if (config.auth) { if (config.auth) {
var username = config.auth.username || ''; var username = config.auth.username || '';
var password = config.auth.password || ''; var password = config.auth.password || '';
requestHeaders['Authorization'] = 'Basic ' + btoa(username + ':' + password); requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
} }
// Create the request // Create the request
var request = new adapter('Microsoft.XMLHTTP'); var request = new Adapter('Microsoft.XMLHTTP');
request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true); request.open(config.method.toUpperCase(), buildURL(config.url, config.params, config.paramsSerializer), true);
// Set the request timeout in MS // Set the request timeout in MS
request.timeout = config.timeout; request.timeout = config.timeout;
// Listen for ready state // Listen for ready state
request[loadEvent] = function () { request[loadEvent] = function handleReadyState() {
if (request && (request.readyState === 4 || xDomain)) { if (request && (request.readyState === 4 || xDomain)) {
// Prepare the response // Prepare the response
var responseHeaders = xDomain ? null : parseHeaders(request.getAllResponseHeaders()); var responseHeaders = xDomain ? null : parseHeaders(request.getAllResponseHeaders());
@@ -99,13 +99,12 @@ module.exports = function xhrAdapter(resolve, reject, config) {
// Add headers to the request // Add headers to the request
if (!xDomain) { if (!xDomain) {
utils.forEach(requestHeaders, function (val, key) { utils.forEach(requestHeaders, function setRequestHeader(val, key) {
// Remove Content-Type if data is undefined
if (!data && key.toLowerCase() === 'content-type') { if (!data && key.toLowerCase() === 'content-type') {
// Remove Content-Type if data is undefined
delete requestHeaders[key]; delete requestHeaders[key];
} } else {
// Otherwise add header to the request // Otherwise add header to the request
else {
request.setRequestHeader(key, val); request.setRequestHeader(key, val);
} }
}); });
+14 -21
View File
@@ -6,8 +6,9 @@ var dispatchRequest = require('./core/dispatchRequest');
var InterceptorManager = require('./core/InterceptorManager'); var InterceptorManager = require('./core/InterceptorManager');
var isAbsoluteURL = require('./helpers/isAbsoluteURL'); var isAbsoluteURL = require('./helpers/isAbsoluteURL');
var combineURLs = require('./helpers/combineURLs'); var combineURLs = require('./helpers/combineURLs');
var bind = require('./helpers/bind');
function Axios (defaultConfig) { function Axios(defaultConfig) {
this.defaultConfig = utils.merge({ this.defaultConfig = utils.merge({
headers: {}, headers: {},
timeout: defaults.timeout, timeout: defaults.timeout,
@@ -21,7 +22,8 @@ function Axios (defaultConfig) {
}; };
} }
Axios.prototype.request = function (config) { Axios.prototype.request = function request(config) {
/*eslint no-param-reassign:0*/
// Allow for axios('example/url'[, config]) a la fetch API // Allow for axios('example/url'[, config]) a la fetch API
if (typeof config === 'string') { if (typeof config === 'string') {
config = utils.merge({ config = utils.merge({
@@ -42,11 +44,11 @@ Axios.prototype.request = function (config) {
var chain = [dispatchRequest, undefined]; var chain = [dispatchRequest, undefined];
var promise = Promise.resolve(config); var promise = Promise.resolve(config);
this.interceptors.request.forEach(function (interceptor) { this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
chain.unshift(interceptor.fulfilled, interceptor.rejected); chain.unshift(interceptor.fulfilled, interceptor.rejected);
}); });
this.interceptors.response.forEach(function (interceptor) { this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
chain.push(interceptor.fulfilled, interceptor.rejected); chain.push(interceptor.fulfilled, interceptor.rejected);
}); });
@@ -61,7 +63,7 @@ var defaultInstance = new Axios();
var axios = module.exports = bind(Axios.prototype.request, defaultInstance); var axios = module.exports = bind(Axios.prototype.request, defaultInstance);
axios.create = function (defaultConfig) { axios.create = function create(defaultConfig) {
return new Axios(defaultConfig); return new Axios(defaultConfig);
}; };
@@ -69,7 +71,7 @@ axios.create = function (defaultConfig) {
axios.defaults = defaults; axios.defaults = defaults;
// Expose all/spread // Expose all/spread
axios.all = function (promises) { axios.all = function all(promises) {
return Promise.all(promises); return Promise.all(promises);
}; };
axios.spread = require('./helpers/spread'); axios.spread = require('./helpers/spread');
@@ -77,20 +79,10 @@ axios.spread = require('./helpers/spread');
// Expose interceptors // Expose interceptors
axios.interceptors = defaultInstance.interceptors; axios.interceptors = defaultInstance.interceptors;
// Helpers
function bind (fn, thisArg) {
return function () {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
return fn.apply(thisArg, args);
};
}
// Provide aliases for supported request methods // Provide aliases for supported request methods
utils.forEach(['delete', 'get', 'head'], function (method) { utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
Axios.prototype[method] = function (url, config) { /*eslint func-names:0*/
Axios.prototype[method] = function(url, config) {
return this.request(utils.merge(config || {}, { return this.request(utils.merge(config || {}, {
method: method, method: method,
url: url url: url
@@ -99,8 +91,9 @@ utils.forEach(['delete', 'get', 'head'], function (method) {
axios[method] = bind(Axios.prototype[method], defaultInstance); axios[method] = bind(Axios.prototype[method], defaultInstance);
}); });
utils.forEach(['post', 'put', 'patch'], function (method) { utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
Axios.prototype[method] = function (url, data, config) { /*eslint func-names:0*/
Axios.prototype[method] = function(url, data, config) {
return this.request(utils.merge(config || {}, { return this.request(utils.merge(config || {}, {
method: method, method: method,
url: url, url: url,
+5 -5
View File
@@ -14,7 +14,7 @@ function InterceptorManager() {
* *
* @return {Number} An ID used to remove interceptor later * @return {Number} An ID used to remove interceptor later
*/ */
InterceptorManager.prototype.use = function (fulfilled, rejected) { InterceptorManager.prototype.use = function use(fulfilled, rejected) {
this.handlers.push({ this.handlers.push({
fulfilled: fulfilled, fulfilled: fulfilled,
rejected: rejected rejected: rejected
@@ -27,7 +27,7 @@ InterceptorManager.prototype.use = function (fulfilled, rejected) {
* *
* @param {Number} id The ID that was returned by `use` * @param {Number} id The ID that was returned by `use`
*/ */
InterceptorManager.prototype.eject = function (id) { InterceptorManager.prototype.eject = function eject(id) {
if (this.handlers[id]) { if (this.handlers[id]) {
this.handlers[id] = null; this.handlers[id] = null;
} }
@@ -37,12 +37,12 @@ InterceptorManager.prototype.eject = function (id) {
* Iterate over all the registered interceptors * Iterate over all the registered interceptors
* *
* This method is particularly useful for skipping over any * This method is particularly useful for skipping over any
* interceptors that may have become `null` calling `remove`. * interceptors that may have become `null` calling `eject`.
* *
* @param {Function} fn The function to call for each interceptor * @param {Function} fn The function to call for each interceptor
*/ */
InterceptorManager.prototype.forEach = function (fn) { InterceptorManager.prototype.forEach = function forEach(fn) {
utils.forEach(this.handlers, function (h) { utils.forEach(this.handlers, function forEachHandler(h) {
if (h !== null) { if (h !== null) {
fn(h); fn(h);
} }
+4 -5
View File
@@ -8,14 +8,13 @@
* @returns {Promise} The Promise to be fulfilled * @returns {Promise} The Promise to be fulfilled
*/ */
module.exports = function dispatchRequest(config) { module.exports = function dispatchRequest(config) {
return new Promise(function (resolve, reject) { return new Promise(function executor(resolve, reject) {
try { try {
// For browsers use XHR adapter
if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) { if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) {
// For browsers use XHR adapter
require('../adapters/xhr')(resolve, reject, config); require('../adapters/xhr')(resolve, reject, config);
} } else if (typeof process !== 'undefined') {
// For node use HTTP adapter // For node use HTTP adapter
else if (typeof process !== 'undefined') {
require('../adapters/http')(resolve, reject, config); require('../adapters/http')(resolve, reject, config);
} }
} catch (e) { } catch (e) {
+5 -4
View File
@@ -8,8 +8,8 @@ var DEFAULT_CONTENT_TYPE = {
}; };
module.exports = { module.exports = {
transformRequest: [function (data, headers) { transformRequest: [function transformResponseJSON(data, headers) {
if(utils.isFormData(data)) { if (utils.isFormData(data)) {
return data; return data;
} }
if (utils.isArrayBuffer(data)) { if (utils.isArrayBuffer(data)) {
@@ -21,7 +21,7 @@ module.exports = {
if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) { if (utils.isObject(data) && !utils.isFile(data) && !utils.isBlob(data)) {
// Set application/json if no Content-Type has been specified // Set application/json if no Content-Type has been specified
if (!utils.isUndefined(headers)) { if (!utils.isUndefined(headers)) {
utils.forEach(headers, function (val, key) { utils.forEach(headers, function processContentTypeHeader(val, key) {
if (key.toLowerCase() === 'content-type') { if (key.toLowerCase() === 'content-type') {
headers['Content-Type'] = val; headers['Content-Type'] = val;
} }
@@ -36,7 +36,8 @@ module.exports = {
return data; return data;
}], }],
transformResponse: [function (data) { transformResponse: [function transformResponseJSON(data) {
/*eslint no-param-reassign:0*/
if (typeof data === 'string') { if (typeof data === 'string') {
data = data.replace(PROTECTION_PREFIX, ''); data = data.replace(PROTECTION_PREFIX, '');
try { try {
+5 -4
View File
@@ -11,11 +11,12 @@ InvalidCharacterError.prototype = new Error;
InvalidCharacterError.prototype.code = 5; InvalidCharacterError.prototype.code = 5;
InvalidCharacterError.prototype.name = 'InvalidCharacterError'; InvalidCharacterError.prototype.name = 'InvalidCharacterError';
function btoa (input) { function btoa(input) {
var str = String(input); var str = String(input);
var output = '';
for ( for (
// initialize result and counter // initialize result and counter
var block, charCode, idx = 0, map = chars, output = ''; var block, charCode, idx = 0, map = chars;
// if the next str index does not exist: // if the next str index does not exist:
// change the mapping table to "=" // change the mapping table to "="
// check if d has no fractional digits // check if d has no fractional digits
@@ -23,13 +24,13 @@ function btoa (input) {
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8 // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
output += map.charAt(63 & block >> 8 - idx % 1 * 8) output += map.charAt(63 & block >> 8 - idx % 1 * 8)
) { ) {
charCode = str.charCodeAt(idx += 3/4); charCode = str.charCodeAt(idx += 3 / 4);
if (charCode > 0xFF) { if (charCode > 0xFF) {
throw new InvalidCharacterError('INVALID_CHARACTER_ERR: DOM Exception 5'); throw new InvalidCharacterError('INVALID_CHARACTER_ERR: DOM Exception 5');
} }
block = block << 8 | charCode; block = block << 8 | charCode;
} }
return output; return output;
}; }
module.exports = btoa; module.exports = btoa;
+5 -6
View File
@@ -21,6 +21,7 @@ function encode(val) {
* @returns {string} The formatted url * @returns {string} The formatted url
*/ */
module.exports = function buildURL(url, params, paramsSerializer) { module.exports = function buildURL(url, params, paramsSerializer) {
/*eslint no-param-reassign:0*/
if (!params) { if (!params) {
return url; return url;
} }
@@ -28,11 +29,10 @@ module.exports = function buildURL(url, params, paramsSerializer) {
var serializedParams; var serializedParams;
if (paramsSerializer) { if (paramsSerializer) {
serializedParams = paramsSerializer(params); serializedParams = paramsSerializer(params);
} } else {
else {
var parts = []; var parts = [];
utils.forEach(params, function (val, key) { utils.forEach(params, function serialize(val, key) {
if (val === null || typeof val === 'undefined') { if (val === null || typeof val === 'undefined') {
return; return;
} }
@@ -45,11 +45,10 @@ module.exports = function buildURL(url, params, paramsSerializer) {
val = [val]; val = [val];
} }
utils.forEach(val, function (v) { utils.forEach(val, function parseValue(v) {
if (utils.isDate(v)) { if (utils.isDate(v)) {
v = v.toISOString(); v = v.toISOString();
} } else if (utils.isObject(v)) {
else if (utils.isObject(v)) {
v = JSON.stringify(v); v = JSON.stringify(v);
} }
parts.push(encode(key) + '=' + encode(v)); parts.push(encode(key) + '=' + encode(v));
+2 -2
View File
@@ -6,7 +6,7 @@ module.exports = (
utils.isStandardBrowserEnv() ? utils.isStandardBrowserEnv() ?
// Standard browser envs support document.cookie // Standard browser envs support document.cookie
(function () { (function standardBrowserEnv() {
return { return {
write: function write(name, value, expires, path, domain, secure) { write: function write(name, value, expires, path, domain, secure) {
var cookie = []; var cookie = [];
@@ -43,7 +43,7 @@ module.exports = (
})() : })() :
// Non standard browser env (web workers, react-native) lack needed support. // Non standard browser env (web workers, react-native) lack needed support.
(function () { (function nonStandardBrowserEnv() {
return { return {
write: function write() {}, write: function write() {},
read: function read() { return null; }, read: function read() { return null; },
+2
View File
@@ -1,5 +1,7 @@
'use strict'; 'use strict';
/*eslint no-console:0*/
/** /**
* Supply a warning to the developer that a method they are using * Supply a warning to the developer that a method they are using
* has been deprecated. * has been deprecated.
+2 -2
View File
@@ -7,7 +7,7 @@ module.exports = (
// Standard browser envs have full support of the APIs needed to test // Standard browser envs have full support of the APIs needed to test
// whether the request URL is of the same origin as current location. // whether the request URL is of the same origin as current location.
(function () { (function standardBrowserEnv() {
var msie = /(msie|trident)/i.test(navigator.userAgent); var msie = /(msie|trident)/i.test(navigator.userAgent);
var urlParsingNode = document.createElement('a'); var urlParsingNode = document.createElement('a');
var originURL; var originURL;
@@ -60,7 +60,7 @@ module.exports = (
})() : })() :
// Non standard browser envs (web workers, react-native) lack needed support. // Non standard browser envs (web workers, react-native) lack needed support.
(function () { (function nonStandardBrowserEnv() {
return function isURLSameOrigin() { return function isURLSameOrigin() {
return true; return true;
}; };
+5 -2
View File
@@ -16,11 +16,14 @@ var utils = require('./../utils');
* @returns {Object} Headers parsed into an object * @returns {Object} Headers parsed into an object
*/ */
module.exports = function parseHeaders(headers) { module.exports = function parseHeaders(headers) {
var parsed = {}, key, val, i; var parsed = {};
var key;
var val;
var i;
if (!headers) { return parsed; } if (!headers) { return parsed; }
utils.forEach(headers.split('\n'), function(line) { utils.forEach(headers.split('\n'), function parser(line) {
i = line.indexOf(':'); i = line.indexOf(':');
key = utils.trim(line.substr(0, i)).toLowerCase(); key = utils.trim(line.substr(0, i)).toLowerCase();
val = utils.trim(line.substr(i + 1)); val = utils.trim(line.substr(i + 1));
+1 -1
View File
@@ -21,7 +21,7 @@
* @returns {Function} * @returns {Function}
*/ */
module.exports = function spread(callback) { module.exports = function spread(callback) {
return function (arr) { return function wrap(arr) {
return callback.apply(null, arr); return callback.apply(null, arr);
}; };
}; };
+2 -1
View File
@@ -11,7 +11,8 @@ var utils = require('./../utils');
* @returns {*} The resulting transformed data * @returns {*} The resulting transformed data
*/ */
module.exports = function transformData(data, headers, fns) { module.exports = function transformData(data, headers, fns) {
utils.forEach(fns, function (fn) { /*eslint no-param-reassign:0*/
utils.forEach(fns, function transform(fn) {
data = fn(data, headers); data = fn(data, headers);
}); });
+14 -10
View File
@@ -43,11 +43,13 @@ function isFormData(val) {
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
*/ */
function isArrayBufferView(val) { function isArrayBufferView(val) {
var result;
if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) { if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
return ArrayBuffer.isView(val); result = ArrayBuffer.isView(val);
} else { } else {
return (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer); result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
} }
return result;
} }
/** /**
@@ -171,17 +173,17 @@ function forEach(obj, fn) {
// Force an array if not already something iterable // Force an array if not already something iterable
if (typeof obj !== 'object' && !isArray(obj)) { if (typeof obj !== 'object' && !isArray(obj)) {
/*eslint no-param-reassign:0*/
obj = [obj]; obj = [obj];
} }
// Iterate over array values
if (isArray(obj)) { if (isArray(obj)) {
// Iterate over array values
for (var i = 0, l = obj.length; i < l; i++) { for (var i = 0, l = obj.length; i < l; i++) {
fn.call(null, obj[i], i, obj); fn.call(null, obj[i], i, obj);
} }
} } else {
// Iterate over object keys // Iterate over object keys
else {
for (var key in obj) { for (var key in obj) {
if (obj.hasOwnProperty(key)) { if (obj.hasOwnProperty(key)) {
fn.call(null, obj[key], key, obj); fn.call(null, obj[key], key, obj);
@@ -207,11 +209,13 @@ function forEach(obj, fn) {
* @param {Object} obj1 Object to merge * @param {Object} obj1 Object to merge
* @returns {Object} Result of all merge properties * @returns {Object} Result of all merge properties
*/ */
function merge(/*obj1, obj2, obj3, ...*/) { function merge(/* obj1, obj2, obj3, ... */) {
var result = {}; var result = {};
var assignValue = function (val, key) { result[key] = val; }; function assignValue(val, key) {
var length = arguments.length; result[key] = val;
for (var i = 0; i < length; i++) { }
for (var i = 0, l = arguments.length; i < l; i++) {
forEach(arguments[i], assignValue); forEach(arguments[i], assignValue);
} }
return result; return result;