Skip to content

Commit

Permalink
chore: upgrade eslint and add fix command
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Apr 7, 2018
1 parent 0d110da commit 22c2baf
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 83 deletions.
4 changes: 2 additions & 2 deletions lib/adapters/xhr.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ module.exports = function xhrAdapter(config) {

// Add xsrf header
var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
cookies.read(config.xsrfCookieName) :
undefined;
cookies.read(config.xsrfCookieName) :
undefined;

if (xsrfValue) {
requestHeaders[config.xsrfHeaderName] = xsrfValue;
Expand Down
82 changes: 41 additions & 41 deletions lib/helpers/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,48 @@ module.exports = (
utils.isStandardBrowserEnv() ?

// Standard browser envs support document.cookie
(function standardBrowserEnv() {
return {
write: function write(name, value, expires, path, domain, secure) {
var cookie = [];
cookie.push(name + '=' + encodeURIComponent(value));

if (utils.isNumber(expires)) {
cookie.push('expires=' + new Date(expires).toGMTString());
(function standardBrowserEnv() {
return {
write: function write(name, value, expires, path, domain, secure) {
var cookie = [];
cookie.push(name + '=' + encodeURIComponent(value));

if (utils.isNumber(expires)) {
cookie.push('expires=' + new Date(expires).toGMTString());
}

if (utils.isString(path)) {
cookie.push('path=' + path);
}

if (utils.isString(domain)) {
cookie.push('domain=' + domain);
}

if (secure === true) {
cookie.push('secure');
}

document.cookie = cookie.join('; ');
},

read: function read(name) {
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
},

remove: function remove(name) {
this.write(name, '', Date.now() - 86400000);
}

if (utils.isString(path)) {
cookie.push('path=' + path);
}

if (utils.isString(domain)) {
cookie.push('domain=' + domain);
}

if (secure === true) {
cookie.push('secure');
}

document.cookie = cookie.join('; ');
},

read: function read(name) {
var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
},

remove: function remove(name) {
this.write(name, '', Date.now() - 86400000);
}
};
})() :
};
})() :

// Non standard browser env (web workers, react-native) lack needed support.
(function nonStandardBrowserEnv() {
return {
write: function write() {},
read: function read() { return null; },
remove: function remove() {}
};
})()
(function nonStandardBrowserEnv() {
return {
write: function write() {},
read: function read() { return null; },
remove: function remove() {}
};
})()
);
76 changes: 38 additions & 38 deletions lib/helpers/isURLSameOrigin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,62 @@ 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 standardBrowserEnv() {
var msie = /(msie|trident)/i.test(navigator.userAgent);
var urlParsingNode = document.createElement('a');
var originURL;
(function standardBrowserEnv() {
var msie = /(msie|trident)/i.test(navigator.userAgent);
var urlParsingNode = document.createElement('a');
var originURL;

/**
/**
* Parse a URL to discover it's components
*
* @param {String} url The URL to be parsed
* @returns {Object}
*/
function resolveURL(url) {
var href = url;
function resolveURL(url) {
var href = url;

if (msie) {
if (msie) {
// IE needs attribute set twice to normalize properties
urlParsingNode.setAttribute('href', href);
href = urlParsingNode.href;
}
urlParsingNode.setAttribute('href', href);
href = urlParsingNode.href;
}

urlParsingNode.setAttribute('href', href);
urlParsingNode.setAttribute('href', href);

// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
return {
href: urlParsingNode.href,
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
host: urlParsingNode.host,
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
hostname: urlParsingNode.hostname,
port: urlParsingNode.port,
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
urlParsingNode.pathname :
'/' + urlParsingNode.pathname
};
}
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
return {
href: urlParsingNode.href,
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
host: urlParsingNode.host,
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
hostname: urlParsingNode.hostname,
port: urlParsingNode.port,
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
urlParsingNode.pathname :
'/' + urlParsingNode.pathname
};
}

originURL = resolveURL(window.location.href);
originURL = resolveURL(window.location.href);

/**
/**
* Determine if a URL shares the same origin as the current location
*
* @param {String} requestURL The URL to test
* @returns {boolean} True if URL shares the same origin, otherwise false
*/
return function isURLSameOrigin(requestURL) {
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
return (parsed.protocol === originURL.protocol &&
return function isURLSameOrigin(requestURL) {
var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
return (parsed.protocol === originURL.protocol &&
parsed.host === originURL.host);
};
})() :
};
})() :

// Non standard browser envs (web workers, react-native) lack needed support.
(function nonStandardBrowserEnv() {
return function isURLSameOrigin() {
return true;
};
})()
(function nonStandardBrowserEnv() {
return function isURLSameOrigin() {
return true;
};
})()
);
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"version": "npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json",
"postversion": "git push && git push --tags",
"examples": "node ./examples/server.js",
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"fix": "eslint --fix lib/**/*.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,7 +41,7 @@
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^19.0.0",
"grunt-eslint": "^20.1.0",
"grunt-karma": "^2.0.0",
"grunt-ts": "^6.0.0-beta.19",
"grunt-webpack": "^1.0.18",
Expand Down

0 comments on commit 22c2baf

Please sign in to comment.