2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +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
+5 -4
View File
@@ -11,11 +11,12 @@ InvalidCharacterError.prototype = new Error;
InvalidCharacterError.prototype.code = 5;
InvalidCharacterError.prototype.name = 'InvalidCharacterError';
function btoa (input) {
function btoa(input) {
var str = String(input);
var output = '';
for (
// 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:
// change the mapping table to "="
// 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
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
) {
charCode = str.charCodeAt(idx += 3/4);
charCode = str.charCodeAt(idx += 3 / 4);
if (charCode > 0xFF) {
throw new InvalidCharacterError('INVALID_CHARACTER_ERR: DOM Exception 5');
}
block = block << 8 | charCode;
}
return output;
};
}
module.exports = btoa;
+5 -6
View File
@@ -21,6 +21,7 @@ function encode(val) {
* @returns {string} The formatted url
*/
module.exports = function buildURL(url, params, paramsSerializer) {
/*eslint no-param-reassign:0*/
if (!params) {
return url;
}
@@ -28,11 +29,10 @@ module.exports = function buildURL(url, params, paramsSerializer) {
var serializedParams;
if (paramsSerializer) {
serializedParams = paramsSerializer(params);
}
else {
} else {
var parts = [];
utils.forEach(params, function (val, key) {
utils.forEach(params, function serialize(val, key) {
if (val === null || typeof val === 'undefined') {
return;
}
@@ -45,11 +45,10 @@ module.exports = function buildURL(url, params, paramsSerializer) {
val = [val];
}
utils.forEach(val, function (v) {
utils.forEach(val, function parseValue(v) {
if (utils.isDate(v)) {
v = v.toISOString();
}
else if (utils.isObject(v)) {
} else if (utils.isObject(v)) {
v = JSON.stringify(v);
}
parts.push(encode(key) + '=' + encode(v));
+2 -2
View File
@@ -6,7 +6,7 @@ module.exports = (
utils.isStandardBrowserEnv() ?
// Standard browser envs support document.cookie
(function () {
(function standardBrowserEnv() {
return {
write: function write(name, value, expires, path, domain, secure) {
var cookie = [];
@@ -43,7 +43,7 @@ module.exports = (
})() :
// Non standard browser env (web workers, react-native) lack needed support.
(function () {
(function nonStandardBrowserEnv() {
return {
write: function write() {},
read: function read() { return null; },
+2
View File
@@ -1,5 +1,7 @@
'use strict';
/*eslint no-console:0*/
/**
* Supply a warning to the developer that a method they are using
* 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
// whether the request URL is of the same origin as current location.
(function () {
(function standardBrowserEnv() {
var msie = /(msie|trident)/i.test(navigator.userAgent);
var urlParsingNode = document.createElement('a');
var originURL;
@@ -60,7 +60,7 @@ module.exports = (
})() :
// Non standard browser envs (web workers, react-native) lack needed support.
(function () {
(function nonStandardBrowserEnv() {
return function isURLSameOrigin() {
return true;
};
+5 -2
View File
@@ -16,11 +16,14 @@ var utils = require('./../utils');
* @returns {Object} Headers parsed into an object
*/
module.exports = function parseHeaders(headers) {
var parsed = {}, key, val, i;
var parsed = {};
var key;
var val;
var i;
if (!headers) { return parsed; }
utils.forEach(headers.split('\n'), function(line) {
utils.forEach(headers.split('\n'), function parser(line) {
i = line.indexOf(':');
key = utils.trim(line.substr(0, i)).toLowerCase();
val = utils.trim(line.substr(i + 1));
+1 -1
View File
@@ -21,7 +21,7 @@
* @returns {Function}
*/
module.exports = function spread(callback) {
return function (arr) {
return function wrap(arr) {
return callback.apply(null, arr);
};
};
+2 -1
View File
@@ -11,7 +11,8 @@ var utils = require('./../utils');
* @returns {*} The resulting transformed data
*/
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);
});