From 22c2baf20563c767945e28ab3c54d51a6a1887c5 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 6 Apr 2018 21:50:20 -0700 Subject: [PATCH] chore: upgrade eslint and add fix command --- lib/adapters/xhr.js | 4 +- lib/helpers/cookies.js | 80 +++++++++++++++++----------------- lib/helpers/isURLSameOrigin.js | 76 ++++++++++++++++---------------- package.json | 5 ++- 4 files changed, 83 insertions(+), 82 deletions(-) diff --git a/lib/adapters/xhr.js b/lib/adapters/xhr.js index d0d6902..5e06453 100644 --- a/lib/adapters/xhr.js +++ b/lib/adapters/xhr.js @@ -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; diff --git a/lib/helpers/cookies.js b/lib/helpers/cookies.js index e45a4f9..5a8a666 100644 --- a/lib/helpers/cookies.js +++ b/lib/helpers/cookies.js @@ -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)); + (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.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() {} + }; + })() ); diff --git a/lib/helpers/isURLSameOrigin.js b/lib/helpers/isURLSameOrigin.js index e292745..f1d89ad 100644 --- a/lib/helpers/isURLSameOrigin.js +++ b/lib/helpers/isURLSameOrigin.js @@ -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 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.setAttribute('href', href); + originURL = resolveURL(window.location.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 - }; - } - - 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; + }; + })() ); diff --git a/package.json b/package.json index 9eda1b1..47c2e10 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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",