Skip to content

Commit c56b551

Browse files
committedApr 21, 2020
refactor: remove example and gulp, upgraded rollup build process, add prettier
1 parent ff1360b commit c56b551

30 files changed

+4611
-26159
lines changed
 

‎.prettierrc.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"useTabs": false,
7+
"printWidth": 80,
8+
"arrowParens": "avoid"
9+
}

‎build/build.js

-64
This file was deleted.

‎build/build.rollup.js

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
var fs = require('fs');
2+
var rollup = require('rollup');
3+
var uglify = require('uglify-js');
4+
var buble = require('@rollup/plugin-buble');
5+
var uglify = require('rollup-plugin-uglify').uglify;
6+
var rollupBanner = require('rollup-plugin-banner').default;
7+
var package = require('../package.json');
8+
9+
var banner =
10+
'vue-authenticate v' +
11+
package.version +
12+
'\n' +
13+
'https://github.com/dgrubelic/vue-authenticate\n' +
14+
'Released under the MIT License.\n';
15+
16+
function buildSource(inputOptions, outputOptions) {
17+
rollup.rollup(inputOptions).then(function (bundle) {
18+
return bundle.generate(outputOptions).then(function (output) {
19+
bundle.write(outputOptions);
20+
});
21+
});
22+
}
23+
24+
buildSource(
25+
{
26+
input: 'src/index.js',
27+
plugins: [buble(), rollupBanner(banner)],
28+
},
29+
{
30+
file: 'dist/vue-authenticate.js',
31+
format: 'umd',
32+
name: 'VueAuthenticate',
33+
}
34+
);
35+
36+
buildSource(
37+
{
38+
input: 'src/index.js',
39+
plugins: [buble(), uglify(), rollupBanner(banner)],
40+
},
41+
{
42+
file: 'dist/vue-authenticate.min.js',
43+
format: 'umd',
44+
name: 'VueAuthenticate',
45+
}
46+
);
47+
48+
buildSource(
49+
{
50+
input: 'src/index.js',
51+
plugins: [rollupBanner(banner)],
52+
},
53+
{
54+
file: 'dist/vue-authenticate.esm.js',
55+
format: 'es',
56+
}
57+
);
58+
59+
buildSource(
60+
{
61+
input: 'src/index.js',
62+
plugins: [rollupBanner(banner)],
63+
},
64+
{
65+
file: 'dist/vue-authenticate.common.js',
66+
format: 'cjs',
67+
}
68+
);
69+
70+
// rollup.rollup({
71+
// input: 'src/index.js',
72+
// plugins: [buble()]
73+
// })
74+
// .then(function (bundle) {
75+
// return bundle.write('dist/vue-authenticate.js', bundle.generate({
76+
// format: 'umd',
77+
// banner: banner,
78+
// name: 'VueAuthenticate'
79+
// }).code, bundle);
80+
// })
81+
// .then(function (bundle) {
82+
// return bundle.write('dist/vue-authenticate.min.js',
83+
// banner + '\n' + uglify.minify('dist/vue-authenticate.js').code,
84+
// bundle);
85+
// })
86+
// .then(function (bundle) {
87+
// return bundle.write('dist/vue-authenticate.es2015.js', bundle.generate({
88+
// format: 'es',
89+
// banner: banner,
90+
// footer: 'export { VueAuthenticate };'
91+
// }).code, bundle);
92+
// })
93+
// .then(function (bundle) {
94+
// return bundle.write('dist/vue-authenticate.common.js', bundle.generate({
95+
// format: 'cjs',
96+
// banner: banner
97+
// }).code, bundle);
98+
// })
99+
// .catch(logError);
100+
101+
function write(dest, code, bundle) {
102+
return new Promise(function (resolve, reject) {
103+
fs.writeFile(dest, code, function (err) {
104+
if (err) return reject(err);
105+
console.log(blue(dest) + ' ' + getSize(code));
106+
resolve(bundle);
107+
});
108+
});
109+
}
110+
111+
function getSize(code) {
112+
return (((code && code.length) || 0) / 1024).toFixed(2) + 'kb';
113+
}
114+
115+
function logError(e) {
116+
console.log(e);
117+
}
118+
119+
function blue(str) {
120+
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m';
121+
}

‎dist/vue-authenticate.common.js

+596-643
Large diffs are not rendered by default.

‎dist/vue-authenticate.es2015.js

-1,511
This file was deleted.

‎dist/vue-authenticate.esm.js

+1,463
Large diffs are not rendered by default.

‎dist/vue-authenticate.js

+1,282-1,316
Large diffs are not rendered by default.

‎dist/vue-authenticate.min.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎example/config.json

-36
This file was deleted.

‎example/index.html

-81
This file was deleted.

‎example/index.js

-161
This file was deleted.

‎example/server.js

-344
This file was deleted.

‎example/vue-authenticate.js

-1,518
This file was deleted.

‎gulpfile.js

-34
This file was deleted.

‎package-lock.json

-12,533
This file was deleted.

‎package.json

+29-44
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,25 @@
22
"name": "vue-authenticate",
33
"version": "1.4.1",
44
"description": "Authentication library for Vue.js",
5-
"main": "dist/vue-authenticate.min.js",
6-
"module": "dist/vue-authenticate.es2015.js",
5+
"main": "dist/vue-authenticate.common.js",
6+
"module": "dist/vue-authenticate.esm.js",
77
"unpkg": "dist/vue-authenticate.js",
88
"scripts": {
9-
"dev": "concurrently --kill-others \"node-dev ./example/server.js\" \"gulp dev\"",
10-
"build": "node build/build.js && cp ./dist/vue-authenticate.js ./example/"
9+
"build": "node build/build.rollup.js"
1110
},
12-
"keywords": ["vue", "vue.js", "vuejs", "json", "jwt", "token", "auth", "authentication", "oauth", "oauth1", "oauth2"],
11+
"keywords": [
12+
"vue",
13+
"vue.js",
14+
"vuejs",
15+
"json",
16+
"jwt",
17+
"token",
18+
"auth",
19+
"authentication",
20+
"oauth",
21+
"oauth1",
22+
"oauth2"
23+
],
1324
"author": {
1425
"name": "Davor Grubelic",
1526
"email": "davor.grubelic@gmail.com",
@@ -19,46 +30,22 @@
1930
"type": "git",
2031
"url": "https://github.com/dgrubelic/vue-authenticate.git"
2132
},
22-
"files": ["dist"],
33+
"files": [
34+
"dist"
35+
],
2336
"license": "MIT",
2437
"devDependencies": {
25-
"@babel/core": "^7.4.3",
26-
"@babel/preset-env": "^7.4.3",
27-
"babel-loader": "^8.0.5",
28-
"babel-preset-es2015": "^6.24.1",
29-
"babel-preset-es2015-rollup": "^3.0.0",
30-
"body-parser": "^1.17.1",
31-
"concurrently": "^4.1.0",
32-
"connect-history-api-fallback": "^1.6.0",
33-
"cors": "^2.8.5",
34-
"express": "^4.16.4",
35-
"gulp": "3.9.1",
36-
"gulp-connect": "^5.7.0",
37-
"gulp-webpack": "^1.5.0",
38-
"node-dev": "^3.1.3",
39-
"oauth": "^0.9.15",
40-
"oauth-signature": "^1.3.1",
41-
"request": "^2.81.0",
42-
"rollup": "^0.41.6",
43-
"rollup-plugin-babel": "^2.7.1",
44-
"rollup-plugin-buble": "^0.15.0",
45-
"rollup-plugin-commonjs": "^8.0.2",
46-
"rollup-plugin-node-resolve": "^3.0.0",
47-
"rollup-plugin-uglify": "^1.0.1",
48-
"rollup-stream": "^1.19.0",
49-
"uglify-js": "^2.8.22",
50-
"unix-timestamp": "^0.2.0",
51-
"vinyl-source-stream": "^1.1.0",
52-
"vue-router": "^3.0.5",
53-
"vuex": "^3.1.0",
54-
"webpack": "^4.30.0",
55-
"webpack-dev-server": "^3.3.1"
56-
},
57-
"peerDependencies": {
58-
"acorn-dynamic-import": "^4.0.0",
59-
"acorn": "^6.0.0",
60-
"ajv": "^6.9.1"
38+
"@babel/core": "^7.9.0",
39+
"@rollup/plugin-buble": "^0.21.3",
40+
"acorn": "^6.1.1",
41+
"ajv": "^6.10.0",
42+
"rollup": "^2.6.1",
43+
"rollup-plugin-babel": "^4.4.0",
44+
"rollup-plugin-banner": "^0.2.1",
45+
"rollup-plugin-uglify": "^6.0.4",
46+
"uglify-js": "^3.9.1"
6147
},
48+
"peerDependencies": {},
6249
"tags": [
6350
"auth",
6451
"authentication",
@@ -77,8 +64,6 @@
7764
"oauth 2.0"
7865
],
7966
"dependencies": {
80-
"acorn": "^6.1.1",
81-
"ajv": "^6.10.0",
8267
"axios": "^0.18.0",
8368
"vue": "^2.6.10",
8469
"vue-axios": "^2.1.4"

‎src/authenticate.js

+158-107
Large diffs are not rendered by default.

‎src/index.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import './utils.js'
2-
import Promise from './promise.js'
3-
import VueAuthenticate from './authenticate.js'
1+
import './utils.js';
2+
import VueAuthenticate from './authenticate.js';
43

54
/**
65
* VueAuthenticate plugin
@@ -9,9 +8,10 @@ import VueAuthenticate from './authenticate.js'
98
*/
109
function plugin(Vue, options) {
1110
if (plugin.installed) {
12-
return
11+
return;
1312
}
14-
plugin.installed = true
13+
14+
plugin.installed = true;
1515

1616
let vueAuthInstance = null;
1717
Object.defineProperties(Vue.prototype, {
@@ -20,15 +20,15 @@ function plugin(Vue, options) {
2020
if (!vueAuthInstance) {
2121
// Request handler library not found, throw error
2222
if (!this.$http) {
23-
throw new Error('Request handler instance not found')
23+
throw new Error('Request handler instance not found');
2424
}
2525

26-
vueAuthInstance = new VueAuthenticate(this.$http, options)
26+
vueAuthInstance = new VueAuthenticate(this.$http, options);
2727
}
28-
return vueAuthInstance
29-
}
30-
}
31-
})
28+
return vueAuthInstance;
29+
},
30+
},
31+
});
3232
}
3333

3434
/**
@@ -38,7 +38,7 @@ function plugin(Vue, options) {
3838
* @return {VueAuthenticate} VueAuthenticate instance
3939
*/
4040
plugin.factory = function ($http, options) {
41-
return new VueAuthenticate($http, options)
42-
}
41+
return new VueAuthenticate($http, options);
42+
};
4343

44-
export default plugin
44+
export default plugin;

‎src/oauth/oauth1.js

+64-40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import OAuthPopup from './popup.js'
1+
import OAuthPopup from './popup.js';
22
import { $window } from '../globals.js';
3-
import { objectExtend, isString, isObject, isFunction, joinUrl } from '../utils.js'
3+
import {
4+
objectExtend,
5+
isString,
6+
isObject,
7+
isFunction,
8+
joinUrl,
9+
} from '../utils.js';
410

511
const defaultProviderConfig = {
612
name: null,
@@ -13,53 +19,63 @@ const defaultProviderConfig = {
1319
requiredUrlParams: null,
1420
defaultUrlParams: null,
1521
oauthType: '1.0',
16-
popupOptions: {}
17-
}
22+
popupOptions: {},
23+
};
1824

1925
export default class OAuth {
2026
constructor($http, storage, providerConfig, options) {
21-
this.$http = $http
22-
this.storage = storage
23-
this.providerConfig = objectExtend({}, defaultProviderConfig)
24-
this.providerConfig = objectExtend(this.providerConfig, providerConfig)
25-
this.options = options
27+
this.$http = $http;
28+
this.storage = storage;
29+
this.providerConfig = objectExtend({}, defaultProviderConfig);
30+
this.providerConfig = objectExtend(this.providerConfig, providerConfig);
31+
this.options = options;
2632
}
2733

2834
/**
29-
* Initialize OAuth1 process
35+
* Initialize OAuth1 process
3036
* @param {Object} userData User data
3137
* @return {Promise}
3238
*/
3339
init(userData) {
34-
this.oauthPopup = new OAuthPopup('about:blank', this.providerConfig.name, this.providerConfig.popupOptions)
40+
this.oauthPopup = new OAuthPopup(
41+
'about:blank',
42+
this.providerConfig.name,
43+
this.providerConfig.popupOptions
44+
);
3545

3646
if (!$window['cordova']) {
37-
this.oauthPopup.open(this.providerConfig.redirectUri, true)
47+
this.oauthPopup.open(this.providerConfig.redirectUri, true);
3848
}
3949

40-
return this.getRequestToken().then((response) => {
41-
return this.openPopup(response).then((popupResponse) => {
42-
return this.exchangeForToken(popupResponse, userData)
43-
})
44-
})
50+
return this.getRequestToken().then(response => {
51+
return this.openPopup(response).then(popupResponse => {
52+
return this.exchangeForToken(popupResponse, userData);
53+
});
54+
});
4555
}
4656

4757
/**
4858
* Get OAuth1 request token
4959
* @return {Promise}
5060
*/
5161
getRequestToken() {
52-
let requestOptions = {}
53-
requestOptions.method = 'POST'
54-
requestOptions[this.options.requestDataKey] = objectExtend({}, this.providerConfig)
55-
requestOptions.withCredentials = this.options.withCredentials
62+
let requestOptions = {};
63+
requestOptions.method = 'POST';
64+
requestOptions[this.options.requestDataKey] = objectExtend(
65+
{},
66+
this.providerConfig
67+
);
68+
requestOptions.withCredentials = this.options.withCredentials;
5669
if (this.options.baseUrl) {
57-
requestOptions.url = joinUrl(this.options.baseUrl, this.providerConfig.url)
70+
requestOptions.url = joinUrl(
71+
this.options.baseUrl,
72+
this.providerConfig.url
73+
);
5874
} else {
59-
requestOptions.url = this.providerConfig.url
75+
requestOptions.url = this.providerConfig.url;
6076
}
6177

62-
return this.$http(requestOptions)
78+
return this.$http(requestOptions);
6379
}
6480

6581
/**
@@ -68,13 +84,16 @@ export default class OAuth {
6884
* @return {Promise}
6985
*/
7086
openPopup(response) {
71-
const url = [this.providerConfig.authorizationEndpoint, this.buildQueryString(response[this.options.responseDataKey])].join('?');
87+
const url = [
88+
this.providerConfig.authorizationEndpoint,
89+
this.buildQueryString(response[this.options.responseDataKey]),
90+
].join('?');
7291

73-
this.oauthPopup.popup.location = url
92+
this.oauthPopup.popup.location = url;
7493
if ($window['cordova']) {
75-
return this.oauthPopup.open(this.providerConfig.redirectUri)
94+
return this.oauthPopup.open(this.providerConfig.redirectUri);
7695
} else {
77-
return this.oauthPopup.pooling(this.providerConfig.redirectUri)
96+
return this.oauthPopup.pooling(this.providerConfig.redirectUri);
7897
}
7998
}
8099

@@ -85,26 +104,31 @@ export default class OAuth {
85104
* @return {Promise}
86105
*/
87106
exchangeForToken(oauth, userData) {
88-
let payload = objectExtend({}, userData)
89-
payload = objectExtend(payload, oauth)
90-
let requestOptions = {}
91-
requestOptions.method = 'POST'
92-
requestOptions[this.options.requestDataKey] = payload
93-
requestOptions.withCredentials = this.options.withCredentials
107+
let payload = objectExtend({}, userData);
108+
payload = objectExtend(payload, oauth);
109+
let requestOptions = {};
110+
requestOptions.method = 'POST';
111+
requestOptions[this.options.requestDataKey] = payload;
112+
requestOptions.withCredentials = this.options.withCredentials;
94113
if (this.options.baseUrl) {
95-
requestOptions.url = joinUrl(this.options.baseUrl, this.providerConfig.url)
114+
requestOptions.url = joinUrl(
115+
this.options.baseUrl,
116+
this.providerConfig.url
117+
);
96118
} else {
97-
requestOptions.url = this.providerConfig.url
119+
requestOptions.url = this.providerConfig.url;
98120
}
99-
return this.$http(requestOptions)
121+
return this.$http(requestOptions);
100122
}
101123

102124
buildQueryString(params) {
103125
const parsedParams = [];
104126
for (var key in params) {
105-
let value = params[key]
106-
parsedParams.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
127+
let value = params[key];
128+
parsedParams.push(
129+
encodeURIComponent(key) + '=' + encodeURIComponent(value)
130+
);
107131
}
108132
return parsedParams.join('&');
109133
}
110-
}
134+
}

‎src/oauth/oauth2.js

+98-62
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import OAuthPopup from './popup.js'
2-
import { camelCase, isFunction, isString, objectExtend, joinUrl } from '../utils.js'
1+
import OAuthPopup from './popup.js';
2+
import {
3+
camelCase,
4+
isFunction,
5+
isString,
6+
objectExtend,
7+
joinUrl,
8+
} from '../utils.js';
39

410
/**
511
* Default provider configuration
@@ -21,116 +27,142 @@ const defaultProviderConfig = {
2127
responseParams: {
2228
code: 'code',
2329
clientId: 'clientId',
24-
redirectUri: 'redirectUri'
30+
redirectUri: 'redirectUri',
2531
},
2632
oauthType: '2.0',
27-
popupOptions: {}
28-
}
33+
popupOptions: {},
34+
};
2935

3036
export default class OAuth2 {
3137
constructor($http, storage, providerConfig, options) {
32-
this.$http = $http
33-
this.storage = storage
34-
this.providerConfig = objectExtend({}, defaultProviderConfig)
35-
this.providerConfig = objectExtend(this.providerConfig, providerConfig)
36-
this.options = options
38+
this.$http = $http;
39+
this.storage = storage;
40+
this.providerConfig = objectExtend({}, defaultProviderConfig);
41+
this.providerConfig = objectExtend(this.providerConfig, providerConfig);
42+
this.options = options;
3743
}
3844

3945
init(userData) {
4046
let stateName = this.providerConfig.name + '_state';
4147
if (isFunction(this.providerConfig.state)) {
42-
this.storage.setItem(stateName, this.providerConfig.state())
48+
this.storage.setItem(stateName, this.providerConfig.state());
4349
} else if (isString(this.providerConfig.state)) {
44-
this.storage.setItem(stateName, this.providerConfig.state)
50+
this.storage.setItem(stateName, this.providerConfig.state);
4551
}
4652

47-
let url = [this.providerConfig.authorizationEndpoint, this._stringifyRequestParams()].join('?')
53+
let url = [
54+
this.providerConfig.authorizationEndpoint,
55+
this._stringifyRequestParams(),
56+
].join('?');
57+
58+
this.oauthPopup = new OAuthPopup(
59+
url,
60+
this.providerConfig.name,
61+
this.providerConfig.popupOptions
62+
);
4863

49-
this.oauthPopup = new OAuthPopup(url, this.providerConfig.name, this.providerConfig.popupOptions)
50-
5164
return new Promise((resolve, reject) => {
52-
this.oauthPopup.open(this.providerConfig.redirectUri).then((response) => {
53-
if (this.providerConfig.responseType === 'token' || !this.providerConfig.url) {
54-
return resolve(response)
55-
}
65+
this.oauthPopup
66+
.open(this.providerConfig.redirectUri)
67+
.then(response => {
68+
if (
69+
this.providerConfig.responseType === 'token' ||
70+
!this.providerConfig.url
71+
) {
72+
return resolve(response);
73+
}
5674

57-
if (response.state && response.state !== this.storage.getItem(stateName)) {
58-
return reject(new Error('State parameter value does not match original OAuth request state value'))
59-
}
75+
if (
76+
response.state &&
77+
response.state !== this.storage.getItem(stateName)
78+
) {
79+
return reject(
80+
new Error(
81+
'State parameter value does not match original OAuth request state value'
82+
)
83+
);
84+
}
6085

61-
resolve(this.exchangeForToken(response, userData))
62-
}).catch((err) => {
63-
reject(err)
64-
})
65-
})
86+
resolve(this.exchangeForToken(response, userData));
87+
})
88+
.catch(err => {
89+
reject(err);
90+
});
91+
});
6692
}
6793

6894
/**
6995
* Exchange temporary oauth data for access token
7096
* @author Sahat Yalkabov <https://github.com/sahat>
7197
* @copyright Method taken from https://github.com/sahat/satellizer
72-
*
98+
*
7399
* @param {[type]} oauth [description]
74100
* @param {[type]} userData [description]
75101
* @return {[type]} [description]
76102
*/
77103
exchangeForToken(oauth, userData) {
78-
let payload = objectExtend({}, userData)
104+
let payload = objectExtend({}, userData);
79105

80106
for (let key in this.providerConfig.responseParams) {
81-
let value = this.providerConfig.responseParams[key]
107+
let value = this.providerConfig.responseParams[key];
82108

83-
switch(key) {
109+
switch (key) {
84110
case 'code':
85-
payload[key] = oauth.code
86-
break
111+
payload[key] = oauth.code;
112+
break;
87113
case 'clientId':
88-
payload[key] = this.providerConfig.clientId
89-
break
114+
payload[key] = this.providerConfig.clientId;
115+
break;
90116
case 'redirectUri':
91-
payload[key] = this.providerConfig.redirectUri
92-
break
117+
payload[key] = this.providerConfig.redirectUri;
118+
break;
93119
default:
94-
payload[key] = oauth[key]
120+
payload[key] = oauth[key];
95121
}
96122
}
97123

98124
if (oauth.state) {
99-
payload.state = oauth.state
125+
payload.state = oauth.state;
100126
}
101127

102-
let exchangeTokenUrl
128+
let exchangeTokenUrl;
103129
if (this.options.baseUrl) {
104-
exchangeTokenUrl = joinUrl(this.options.baseUrl, this.providerConfig.url)
130+
exchangeTokenUrl = joinUrl(this.options.baseUrl, this.providerConfig.url);
105131
} else {
106-
exchangeTokenUrl = this.providerConfig.url
132+
exchangeTokenUrl = this.providerConfig.url;
107133
}
108134

109135
return this.$http.post(exchangeTokenUrl, payload, {
110-
withCredentials: this.options.withCredentials
111-
})
136+
withCredentials: this.options.withCredentials,
137+
});
112138
}
113139

114140
/**
115141
* Stringify oauth params
116142
* @author Sahat Yalkabov <https://github.com/sahat>
117143
* @copyright Method taken from https://github.com/sahat/satellizer
118-
*
144+
*
119145
* @return {String}
120146
*/
121147
_stringifyRequestParams() {
122-
let keyValuePairs = []
123-
let paramCategories = ['defaultUrlParams', 'requiredUrlParams', 'optionalUrlParams']
148+
let keyValuePairs = [];
149+
let paramCategories = [
150+
'defaultUrlParams',
151+
'requiredUrlParams',
152+
'optionalUrlParams',
153+
];
124154

125-
paramCategories.forEach((categoryName) => {
126-
if (!this.providerConfig[categoryName]) return
127-
if (!Array.isArray(this.providerConfig[categoryName])) return
155+
paramCategories.forEach(categoryName => {
156+
if (!this.providerConfig[categoryName]) return;
157+
if (!Array.isArray(this.providerConfig[categoryName])) return;
128158

129-
this.providerConfig[categoryName].forEach((paramName) => {
130-
let camelCaseParamName = camelCase(paramName)
131-
let paramValue = isFunction(this.providerConfig[paramName]) ? this.providerConfig[paramName]() : this.providerConfig[camelCaseParamName]
159+
this.providerConfig[categoryName].forEach(paramName => {
160+
let camelCaseParamName = camelCase(paramName);
161+
let paramValue = isFunction(this.providerConfig[paramName])
162+
? this.providerConfig[paramName]()
163+
: this.providerConfig[camelCaseParamName];
132164

133-
if (paramName === 'redirect_uri' && !paramValue) return
165+
if (paramName === 'redirect_uri' && !paramValue) return;
134166

135167
if (paramName === 'state') {
136168
let stateName = this.providerConfig.name + '_state';
@@ -139,16 +171,20 @@ export default class OAuth2 {
139171
if (paramName === 'scope' && Array.isArray(paramValue)) {
140172
paramValue = paramValue.join(this.providerConfig.scopeDelimiter);
141173
if (this.providerConfig.scopePrefix) {
142-
paramValue = [this.providerConfig.scopePrefix, paramValue].join(this.providerConfig.scopeDelimiter);
174+
paramValue = [this.providerConfig.scopePrefix, paramValue].join(
175+
this.providerConfig.scopeDelimiter
176+
);
143177
}
144178
}
145179

146-
keyValuePairs.push([paramName, paramValue])
147-
})
148-
})
180+
keyValuePairs.push([paramName, paramValue]);
181+
});
182+
});
149183

150-
return keyValuePairs.map((param) => {
151-
return param.join('=')
152-
}).join('&')
184+
return keyValuePairs
185+
.map(param => {
186+
return param.join('=');
187+
})
188+
.join('&');
153189
}
154-
}
190+
}

‎src/oauth/popup.js

+53-36
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,106 @@
1-
import Promise from '../promise.js'
1+
import Promise from '../promise.js';
22
import { $document, $window } from '../globals.js';
3-
import { objectExtend, parseQueryString, getFullUrlPath, isUndefined } from '../utils.js'
3+
import {
4+
objectExtend,
5+
parseQueryString,
6+
getFullUrlPath,
7+
isUndefined,
8+
} from '../utils.js';
49

510
/**
611
* OAuth2 popup management class
7-
*
12+
*
813
* @author Sahat Yalkabov <https://github.com/sahat>
9-
* @copyright Class mostly taken from https://github.com/sahat/satellizer
14+
* @copyright Class mostly taken from https://github.com/sahat/satellizer
1015
* and adjusted to fit vue-authenticate library
1116
*/
1217
export default class OAuthPopup {
1318
constructor(url, name, popupOptions) {
14-
this.popup = null
15-
this.url = url
16-
this.name = name
17-
this.popupOptions = popupOptions
19+
this.popup = null;
20+
this.url = url;
21+
this.name = name;
22+
this.popupOptions = popupOptions;
1823
}
1924

2025
open(redirectUri, skipPooling) {
2126
try {
22-
this.popup = $window.open(this.url, this.name, this._stringifyOptions())
27+
this.popup = $window.open(this.url, this.name, this._stringifyOptions());
2328
if (this.popup && this.popup.focus) {
24-
this.popup.focus()
29+
this.popup.focus();
2530
}
2631

2732
if (skipPooling) {
28-
return Promise.resolve()
33+
return Promise.resolve();
2934
} else {
30-
return this.pooling(redirectUri)
35+
return this.pooling(redirectUri);
3136
}
32-
} catch(e) {
33-
return Promise.reject(new Error('OAuth popup error occurred'))
37+
} catch (e) {
38+
return Promise.reject(new Error('OAuth popup error occurred'));
3439
}
3540
}
3641

3742
pooling(redirectUri) {
3843
return new Promise((resolve, reject) => {
39-
const redirectUriParser = $document.createElement('a')
40-
redirectUriParser.href = redirectUri
41-
const redirectUriPath = getFullUrlPath(redirectUriParser)
44+
const redirectUriParser = $document.createElement('a');
45+
redirectUriParser.href = redirectUri;
46+
const redirectUriPath = getFullUrlPath(redirectUriParser);
4247

4348
let poolingInterval = setInterval(() => {
44-
if (!this.popup || this.popup.closed || this.popup.closed === undefined) {
45-
clearInterval(poolingInterval)
46-
poolingInterval = null
47-
reject(new Error('Auth popup window closed'))
49+
if (
50+
!this.popup ||
51+
this.popup.closed ||
52+
this.popup.closed === undefined
53+
) {
54+
clearInterval(poolingInterval);
55+
poolingInterval = null;
56+
reject(new Error('Auth popup window closed'));
4857
}
4958

5059
try {
51-
const popupWindowPath = getFullUrlPath(this.popup.location)
60+
const popupWindowPath = getFullUrlPath(this.popup.location);
5261

5362
if (popupWindowPath === redirectUriPath) {
5463
if (this.popup.location.search || this.popup.location.hash) {
55-
const query = parseQueryString(this.popup.location.search.substring(1).replace(/\/$/, ''));
56-
const hash = parseQueryString(this.popup.location.hash.substring(1).replace(/[\/$]/, ''));
64+
const query = parseQueryString(
65+
this.popup.location.search.substring(1).replace(/\/$/, '')
66+
);
67+
const hash = parseQueryString(
68+
this.popup.location.hash.substring(1).replace(/[\/$]/, '')
69+
);
5770
let params = objectExtend({}, query);
58-
params = objectExtend(params, hash)
71+
params = objectExtend(params, hash);
5972

6073
if (params.error) {
6174
reject(new Error(params.error));
6275
} else {
6376
resolve(params);
6477
}
6578
} else {
66-
reject(new Error('OAuth redirect has occurred but no query or hash parameters were found.'))
79+
reject(
80+
new Error(
81+
'OAuth redirect has occurred but no query or hash parameters were found.'
82+
)
83+
);
6784
}
6885

69-
clearInterval(poolingInterval)
70-
poolingInterval = null
71-
this.popup.close()
86+
clearInterval(poolingInterval);
87+
poolingInterval = null;
88+
this.popup.close();
7289
}
73-
} catch(e) {
90+
} catch (e) {
7491
// Ignore DOMException: Blocked a frame with origin from accessing a cross-origin frame.
7592
}
76-
}, 250)
77-
})
93+
}, 250);
94+
});
7895
}
7996

8097
_stringifyOptions() {
81-
let options = []
98+
let options = [];
8299
for (var optionKey in this.popupOptions) {
83100
if (!isUndefined(this.popupOptions[optionKey])) {
84-
options.push(`${optionKey}=${this.popupOptions[optionKey]}`)
101+
options.push(`${optionKey}=${this.popupOptions[optionKey]}`);
85102
}
86103
}
87-
return options.join(',')
104+
return options.join(',');
88105
}
89-
}
106+
}

‎src/options.js

+25-24
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import { $window } from './globals';
33

44
export function getCookieDomainUrl() {
55
try {
6-
return $window.location.hostname
6+
return $window.location.hostname;
77
} catch (e) {}
88

99
return '';
1010
}
1111

1212
export function getRedirectUri(uri) {
1313
try {
14-
return (!isUndefined(uri))
14+
return !isUndefined(uri)
1515
? `${$window.location.origin}${uri}`
16-
: $window.location.origin
16+
: $window.location.origin;
1717
} catch (e) {}
1818

1919
return uri || null;
@@ -37,7 +37,7 @@ export default {
3737
cookieStorage: {
3838
domain: getCookieDomainUrl(),
3939
path: '/',
40-
secure: false
40+
secure: false,
4141
},
4242
requestDataKey: 'data',
4343
responseDataKey: 'data',
@@ -49,16 +49,17 @@ export default {
4949
bindRequestInterceptor: function ($auth) {
5050
const tokenHeader = $auth.options.tokenHeader;
5151

52-
$auth.$http.interceptors.request.use((config) => {
52+
$auth.$http.interceptors.request.use(config => {
5353
if ($auth.isAuthenticated()) {
5454
config.headers[tokenHeader] = [
55-
$auth.options.tokenType, $auth.getToken()
56-
].join(' ')
55+
$auth.options.tokenType,
56+
$auth.getToken(),
57+
].join(' ');
5758
} else {
58-
delete config.headers[tokenHeader]
59+
delete config.headers[tokenHeader];
5960
}
60-
return config
61-
})
61+
return config;
62+
});
6263
},
6364

6465
providers: {
@@ -72,7 +73,7 @@ export default {
7273
scopeDelimiter: ',',
7374
display: 'popup',
7475
oauthType: '2.0',
75-
popupOptions: { width: 580, height: 400 }
76+
popupOptions: { width: 580, height: 400 },
7677
},
7778

7879
google: {
@@ -87,7 +88,7 @@ export default {
8788
scopeDelimiter: ' ',
8889
display: 'popup',
8990
oauthType: '2.0',
90-
popupOptions: { width: 452, height: 633 }
91+
popupOptions: { width: 452, height: 633 },
9192
},
9293

9394
github: {
@@ -99,7 +100,7 @@ export default {
99100
scope: ['user:email'],
100101
scopeDelimiter: ' ',
101102
oauthType: '2.0',
102-
popupOptions: { width: 1020, height: 618 }
103+
popupOptions: { width: 1020, height: 618 },
103104
},
104105

105106
instagram: {
@@ -111,7 +112,7 @@ export default {
111112
scope: ['basic'],
112113
scopeDelimiter: '+',
113114
oauthType: '2.0',
114-
popupOptions: { width: null, height: null }
115+
popupOptions: { width: null, height: null },
115116
},
116117

117118
twitter: {
@@ -120,7 +121,7 @@ export default {
120121
authorizationEndpoint: 'https://api.twitter.com/oauth/authenticate',
121122
redirectUri: getRedirectUri(),
122123
oauthType: '1.0',
123-
popupOptions: { width: 495, height: 645 }
124+
popupOptions: { width: 495, height: 645 },
124125
},
125126

126127
bitbucket: {
@@ -132,7 +133,7 @@ export default {
132133
scope: ['email'],
133134
scopeDelimiter: ' ',
134135
oauthType: '2.0',
135-
popupOptions: { width: 1020, height: 618 }
136+
popupOptions: { width: 1020, height: 618 },
136137
},
137138

138139
linkedin: {
@@ -145,7 +146,7 @@ export default {
145146
scopeDelimiter: ' ',
146147
state: 'STATE',
147148
oauthType: '2.0',
148-
popupOptions: { width: 527, height: 582 }
149+
popupOptions: { width: 527, height: 582 },
149150
},
150151

151152
live: {
@@ -158,7 +159,7 @@ export default {
158159
scopeDelimiter: ' ',
159160
display: 'popup',
160161
oauthType: '2.0',
161-
popupOptions: { width: 500, height: 560 }
162+
popupOptions: { width: 500, height: 560 },
162163
},
163164

164165
oauth1: {
@@ -167,7 +168,7 @@ export default {
167168
authorizationEndpoint: null,
168169
redirectUri: getRedirectUri(),
169170
oauthType: '1.0',
170-
popupOptions: null
171+
popupOptions: null,
171172
},
172173

173174
oauth2: {
@@ -189,8 +190,8 @@ export default {
189190
responseParams: {
190191
code: 'code',
191192
clientId: 'clientId',
192-
redirectUri: 'redirectUri'
193-
}
194-
}
195-
}
196-
}
193+
redirectUri: 'redirectUri',
194+
},
195+
},
196+
},
197+
};

‎src/promise.js

+35-19
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function bind(fn, thisArg) {
1212
}
1313

1414
function Promise(fn) {
15-
if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new');
15+
if (typeof this !== 'object')
16+
throw new TypeError('Promises must be constructed via new');
1617
if (typeof fn !== 'function') throw new TypeError('not a function');
1718
this._state = 0;
1819
this._handled = false;
@@ -51,8 +52,12 @@ function handle(self, deferred) {
5152
function resolve(self, newValue) {
5253
try {
5354
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
54-
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.');
55-
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
55+
if (newValue === self)
56+
throw new TypeError('A promise cannot be resolved with itself.');
57+
if (
58+
newValue &&
59+
(typeof newValue === 'object' || typeof newValue === 'function')
60+
) {
5661
var then = newValue.then;
5762
if (newValue instanceof Promise) {
5863
self._state = 3;
@@ -80,7 +85,7 @@ function reject(self, newValue) {
8085

8186
function finale(self) {
8287
if (self._state === 2 && self._deferreds.length === 0) {
83-
Promise._immediateFn(function() {
88+
Promise._immediateFn(function () {
8489
if (!self._handled) {
8590
Promise._unhandledRejectionFn(self._value);
8691
}
@@ -108,15 +113,18 @@ function Handler(onFulfilled, onRejected, promise) {
108113
function doResolve(fn, self) {
109114
var done = false;
110115
try {
111-
fn(function (value) {
112-
if (done) return;
113-
done = true;
114-
resolve(self, value);
115-
}, function (reason) {
116-
if (done) return;
117-
done = true;
118-
reject(self, reason);
119-
});
116+
fn(
117+
function (value) {
118+
if (done) return;
119+
done = true;
120+
resolve(self, value);
121+
},
122+
function (reason) {
123+
if (done) return;
124+
done = true;
125+
reject(self, reason);
126+
}
127+
);
120128
} catch (ex) {
121129
if (done) return;
122130
done = true;
@@ -129,7 +137,7 @@ Promise.prototype['catch'] = function (onRejected) {
129137
};
130138

131139
Promise.prototype.then = function (onFulfilled, onRejected) {
132-
var prom = new (this.constructor)(noop);
140+
var prom = new this.constructor(noop);
133141

134142
handle(this, new Handler(onFulfilled, onRejected, prom));
135143
return prom;
@@ -147,9 +155,13 @@ Promise.all = function (arr) {
147155
if (val && (typeof val === 'object' || typeof val === 'function')) {
148156
var then = val.then;
149157
if (typeof then === 'function') {
150-
then.call(val, function (val) {
151-
res(i, val);
152-
}, reject);
158+
then.call(
159+
val,
160+
function (val) {
161+
res(i, val);
162+
},
163+
reject
164+
);
153165
return;
154166
}
155167
}
@@ -193,7 +205,11 @@ Promise.race = function (values) {
193205
};
194206

195207
// Use polyfill for setImmediate for performance gains
196-
Promise._immediateFn = (typeof setImmediate === 'function' && function (fn) { setImmediate(fn); }) ||
208+
Promise._immediateFn =
209+
(typeof setImmediate === 'function' &&
210+
function (fn) {
211+
setImmediate(fn);
212+
}) ||
197213
function (fn) {
198214
setTimeoutFunc(fn, 0);
199215
};
@@ -222,4 +238,4 @@ Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
222238
Promise._unhandledRejectionFn = fn;
223239
};
224240

225-
export default Promise;
241+
export default Promise;

‎src/storage.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
import { $window } from './globals';
22
import CookieStorage from './storage/cookie-storage.js';
3-
import LocalStorage from './storage/local-storage.js'
4-
import MemoryStorage from './storage/memory-storage.js'
5-
import SessionStorage from './storage/session-storage.js'
3+
import LocalStorage from './storage/local-storage.js';
4+
import MemoryStorage from './storage/memory-storage.js';
5+
import SessionStorage from './storage/session-storage.js';
66

77
export default function StorageFactory(options) {
88
switch (options.storageType) {
99
case 'localStorage':
1010
try {
11-
$window.localStorage.setItem('testKey', 'test')
12-
$window.localStorage.removeItem('testKey')
13-
return new LocalStorage(options.storageNamespace)
14-
} catch(e) {}
11+
$window.localStorage.setItem('testKey', 'test');
12+
$window.localStorage.removeItem('testKey');
13+
return new LocalStorage(options.storageNamespace);
14+
} catch (e) {}
1515

1616
case 'sessionStorage':
1717
try {
18-
$window.sessionStorage.setItem('testKey', 'test')
19-
$window.sessionStorage.removeItem('testKey')
20-
return new SessionStorage(options.storageNamespace)
18+
$window.sessionStorage.setItem('testKey', 'test');
19+
$window.sessionStorage.removeItem('testKey');
20+
return new SessionStorage(options.storageNamespace);
2121
} catch (e) {}
22-
22+
2323
case 'cookieStorage':
2424
return new CookieStorage(options.cookieStorage);
2525

26-
case 'memoryStorage':
26+
case 'memoryStorage':
2727
default:
28-
return new MemoryStorage(options.storageNamespace)
28+
return new MemoryStorage(options.storageNamespace);
2929
break;
3030
}
31-
}
31+
}

‎src/storage/cookie-storage.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import { $document } from '../globals.js';
2-
import {
3-
objectExtend,
4-
formatCookie,
5-
parseCookies
6-
} from '../utils.js';
2+
import { objectExtend, formatCookie, parseCookies } from '../utils.js';
73
import { getCookieDomainUrl } from '../options.js';
84

95
class CookieStorage {
106
constructor(defaultOptions) {
11-
this._defaultOptions = objectExtend({
12-
domain: getCookieDomainUrl(),
13-
expires: null,
14-
path: '/',
15-
secure: false
16-
}, defaultOptions);
7+
this._defaultOptions = objectExtend(
8+
{
9+
domain: getCookieDomainUrl(),
10+
expires: null,
11+
path: '/',
12+
secure: false,
13+
},
14+
defaultOptions
15+
);
1716
}
1817

1918
setItem(key, value) {
@@ -31,17 +30,17 @@ class CookieStorage {
3130
const value = '';
3231
const defaultOptions = objectExtend({}, this._defaultOptions);
3332
const options = objectExtend(defaultOptions, {
34-
expires: new Date(0)
33+
expires: new Date(0),
3534
});
3635
const cookie = formatCookie(key, value, options);
3736
this._setCookie(cookie);
3837
}
3938

4039
_getCookie() {
4140
try {
42-
return $document.cookie === 'undefined' ? '' : $document.cookie
41+
return $document.cookie === 'undefined' ? '' : $document.cookie;
4342
} catch (e) {}
44-
43+
4544
return '';
4645
}
4746

@@ -52,4 +51,4 @@ class CookieStorage {
5251
}
5352
}
5453

55-
export default CookieStorage
54+
export default CookieStorage;

‎src/storage/local-storage.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ import { $window } from '../globals.js';
22

33
class LocalStorage {
44
constructor(namespace) {
5-
this.namespace = namespace || null
5+
this.namespace = namespace || null;
66
}
77

88
setItem(key, value) {
9-
$window.localStorage.setItem(this._getStorageKey(key), value)
9+
$window.localStorage.setItem(this._getStorageKey(key), value);
1010
}
1111

1212
getItem(key) {
13-
return $window.localStorage.getItem(this._getStorageKey(key))
13+
return $window.localStorage.getItem(this._getStorageKey(key));
1414
}
1515

1616
removeItem(key) {
17-
$window.localStorage.removeItem(this._getStorageKey(key))
17+
$window.localStorage.removeItem(this._getStorageKey(key));
1818
}
1919

2020
_getStorageKey(key) {
2121
if (this.namespace) {
22-
return [this.namespace, key].join('.')
22+
return [this.namespace, key].join('.');
2323
}
2424
return key;
2525
}
2626
}
2727

28-
export default LocalStorage
28+
export default LocalStorage;

‎src/storage/memory-storage.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
class MemoryStorage {
22
constructor(namespace) {
3-
this.namespace = namespace || null
4-
this._storage = {}
3+
this.namespace = namespace || null;
4+
this._storage = {};
55
}
66

77
setItem(key, value) {
8-
this._storage[this._getStorageKey(key)] = value
8+
this._storage[this._getStorageKey(key)] = value;
99
}
1010

1111
getItem(key) {
12-
return this._storage[this._getStorageKey(key)]
12+
return this._storage[this._getStorageKey(key)];
1313
}
1414

1515
removeItem(key) {
16-
delete this._storage[this._getStorageKey(key)]
16+
delete this._storage[this._getStorageKey(key)];
1717
}
1818

1919
_getStorageKey(key) {
2020
if (this.namespace) {
21-
return [this.namespace, key].join('.')
21+
return [this.namespace, key].join('.');
2222
}
2323
return key;
2424
}
2525
}
2626

27-
export default MemoryStorage
27+
export default MemoryStorage;

‎src/storage/session-storage.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ import { $window } from '../globals.js';
22

33
class SessionStorage {
44
constructor(namespace) {
5-
this.namespace = namespace || null
5+
this.namespace = namespace || null;
66
}
77

88
setItem(key, value) {
9-
$window.sessionStorage.setItem(this._getStorageKey(key), value)
9+
$window.sessionStorage.setItem(this._getStorageKey(key), value);
1010
}
1111

1212
getItem(key) {
13-
return $window.sessionStorage.getItem(this._getStorageKey(key))
13+
return $window.sessionStorage.getItem(this._getStorageKey(key));
1414
}
1515

1616
removeItem(key) {
17-
$window.sessionStorage.removeItem(this._getStorageKey(key))
17+
$window.sessionStorage.removeItem(this._getStorageKey(key));
1818
}
1919

2020
_getStorageKey(key) {
2121
if (this.namespace) {
22-
return [this.namespace, key].join('.')
22+
return [this.namespace, key].join('.');
2323
}
2424
return key;
2525
}
2626
}
2727

28-
export default LocalStorage
28+
export default LocalStorage;

‎src/utils.js

+80-59
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
if (typeof Object.assign != 'function') {
2-
Object.assign = function(target, varArgs) {
2+
Object.assign = function (target, varArgs) {
33
'use strict';
44
if (target == null) {
55
throw new TypeError('Cannot convert undefined or null to object');
@@ -10,7 +10,8 @@ if (typeof Object.assign != 'function') {
1010
for (var index = 1; index < arguments.length; index++) {
1111
var nextSource = arguments[index];
1212

13-
if (nextSource != null) { // Skip over if undefined or null
13+
if (nextSource != null) {
14+
// Skip over if undefined or null
1415
for (var nextKey in nextSource) {
1516
// Avoid bugs when hasOwnProperty is shadowed
1617
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
@@ -24,37 +25,41 @@ if (typeof Object.assign != 'function') {
2425
}
2526

2627
export function camelCase(name) {
27-
return name.replace(/([\:\-\_]+(.))/g, function (_, separator, letter, offset) {
28+
return name.replace(/([\:\-\_]+(.))/g, function (
29+
_,
30+
separator,
31+
letter,
32+
offset
33+
) {
2834
return offset ? letter.toUpperCase() : letter;
2935
});
3036
}
3137

3238
export function isUndefined(value) {
33-
return typeof value === 'undefined'
39+
return typeof value === 'undefined';
3440
}
3541

3642
export function isDefined(value) {
37-
return typeof value !== 'undefined'
43+
return typeof value !== 'undefined';
3844
}
3945

4046
export function isObject(value) {
41-
return value !== null && typeof value === 'object'
47+
return value !== null && typeof value === 'object';
4248
}
4349

4450
export function isString(value) {
45-
return typeof value === 'string'
51+
return typeof value === 'string';
4652
}
4753

4854
export function isNumber(value) {
49-
return typeof value === 'number'
55+
return typeof value === 'number';
5056
}
5157

5258
export function isFunction(value) {
53-
return typeof value === 'function'
59+
return typeof value === 'function';
5460
}
5561

5662
export function objectExtend(a, b) {
57-
5863
// Don't touch 'null' or 'undefined' objects.
5964
if (a == null || b == null) {
6065
return a;
@@ -73,14 +78,14 @@ export function objectExtend(a, b) {
7378
});
7479

7580
return a;
76-
};
81+
}
7782

7883
/**
7984
* Assemble url from two segments
80-
*
85+
*
8186
* @author Sahat Yalkabov <https://github.com/sahat>
8287
* @copyright Method taken from https://github.com/sahat/satellizer
83-
*
88+
*
8489
* @param {String} baseUrl Base url
8590
* @param {String} url URI
8691
* @return {String}
@@ -102,38 +107,45 @@ export function joinUrl(baseUrl, url) {
102107

103108
/**
104109
* Get full path based on current location
105-
*
110+
*
106111
* @author Sahat Yalkabov <https://github.com/sahat>
107112
* @copyright Method taken from https://github.com/sahat/satellizer
108-
*
113+
*
109114
* @param {Location} location
110115
* @return {String}
111116
*/
112117
export function getFullUrlPath(location) {
113118
const isHttps = location.protocol === 'https:';
114-
return location.protocol + '//' + location.hostname +
115-
':' + (location.port || (isHttps ? '443' : '80')) +
116-
(/^\//.test(location.pathname) ? location.pathname : '/' + location.pathname);
119+
return (
120+
location.protocol +
121+
'//' +
122+
location.hostname +
123+
':' +
124+
(location.port || (isHttps ? '443' : '80')) +
125+
(/^\//.test(location.pathname)
126+
? location.pathname
127+
: '/' + location.pathname)
128+
);
117129
}
118130

119131
/**
120132
* Parse query string variables
121-
*
133+
*
122134
* @author Sahat Yalkabov <https://github.com/sahat>
123135
* @copyright Method taken from https://github.com/sahat/satellizer
124-
*
136+
*
125137
* @param {String} Query string
126138
* @return {String}
127139
*/
128140
export function parseQueryString(str) {
129141
let obj = {};
130142
let key;
131143
let value;
132-
(str || '').split('&').forEach((keyValue) => {
144+
(str || '').split('&').forEach(keyValue => {
133145
if (keyValue) {
134146
value = keyValue.split('=');
135147
key = decodeURIComponent(value[0]);
136-
obj[key] = (!!value[1]) ? decodeURIComponent(value[1]) : true;
148+
obj[key] = !!value[1] ? decodeURIComponent(value[1]) : true;
137149
}
138150
});
139151
return obj;
@@ -143,7 +155,7 @@ export function parseQueryString(str) {
143155
* Decode base64 string
144156
* @author Sahat Yalkabov <https://github.com/sahat>
145157
* @copyright Method taken from https://github.com/sahat/satellizer
146-
*
158+
*
147159
* @param {String} str base64 encoded string
148160
* @return {Object}
149161
*/
@@ -159,32 +171,37 @@ export function decodeBase64(str) {
159171

160172
let fromCharCode = String.fromCharCode;
161173

162-
let re_btou = new RegExp([
163-
'[\xC0-\xDF][\x80-\xBF]',
164-
'[\xE0-\xEF][\x80-\xBF]{2}',
165-
'[\xF0-\xF7][\x80-\xBF]{3}'
166-
].join('|'), 'g');
174+
let re_btou = new RegExp(
175+
[
176+
'[\xC0-\xDF][\x80-\xBF]',
177+
'[\xE0-\xEF][\x80-\xBF]{2}',
178+
'[\xF0-\xF7][\x80-\xBF]{3}',
179+
].join('|'),
180+
'g'
181+
);
167182

168183
let cb_btou = function (cccc) {
169184
switch (cccc.length) {
170185
case 4:
171-
let cp = ((0x07 & cccc.charCodeAt(0)) << 18)
172-
| ((0x3f & cccc.charCodeAt(1)) << 12)
173-
| ((0x3f & cccc.charCodeAt(2)) << 6)
174-
| (0x3f & cccc.charCodeAt(3));
186+
let cp =
187+
((0x07 & cccc.charCodeAt(0)) << 18) |
188+
((0x3f & cccc.charCodeAt(1)) << 12) |
189+
((0x3f & cccc.charCodeAt(2)) << 6) |
190+
(0x3f & cccc.charCodeAt(3));
175191
let offset = cp - 0x10000;
176-
return (fromCharCode((offset >>> 10) + 0xD800)
177-
+ fromCharCode((offset & 0x3FF) + 0xDC00));
192+
return (
193+
fromCharCode((offset >>> 10) + 0xd800) +
194+
fromCharCode((offset & 0x3ff) + 0xdc00)
195+
);
178196
case 3:
179197
return fromCharCode(
180-
((0x0f & cccc.charCodeAt(0)) << 12)
181-
| ((0x3f & cccc.charCodeAt(1)) << 6)
182-
| (0x3f & cccc.charCodeAt(2))
198+
((0x0f & cccc.charCodeAt(0)) << 12) |
199+
((0x3f & cccc.charCodeAt(1)) << 6) |
200+
(0x3f & cccc.charCodeAt(2))
183201
);
184202
default:
185203
return fromCharCode(
186-
((0x1f & cccc.charCodeAt(0)) << 6)
187-
| (0x3f & cccc.charCodeAt(1))
204+
((0x1f & cccc.charCodeAt(0)) << 6) | (0x3f & cccc.charCodeAt(1))
188205
);
189206
}
190207
};
@@ -193,18 +210,22 @@ export function decodeBase64(str) {
193210
return b.replace(re_btou, cb_btou);
194211
};
195212

196-
let _decode = buffer ? function (a) {
197-
return (a.constructor === buffer.constructor
198-
? a : new buffer(a, 'base64')).toString();
199-
}
213+
let _decode = buffer
214+
? function (a) {
215+
return (a.constructor === buffer.constructor
216+
? a
217+
: new buffer(a, 'base64')
218+
).toString();
219+
}
200220
: function (a) {
201-
return btou(atob(a));
202-
};
221+
return btou(atob(a));
222+
};
203223

204224
return _decode(
205-
String(str).replace(/[-_]/g, function (m0) {
206-
return m0 === '-' ? '+' : '/';
207-
})
225+
String(str)
226+
.replace(/[-_]/g, function (m0) {
227+
return m0 === '-' ? '+' : '/';
228+
})
208229
.replace(/[^A-Za-z0-9\+\/]/g, '')
209230
);
210231
}
@@ -213,37 +234,37 @@ export function parseCookies(str = '') {
213234
if (str.length === 0) return {};
214235
const parsed = {};
215236
const pattern = new RegExp('\\s*;\\s*');
216-
str.split(pattern).forEach((i) => {
237+
str.split(pattern).forEach(i => {
217238
const [encodedKey, encodedValue] = i.split('=');
218239
const key = decodeURIComponent(encodedKey);
219240
const value = decodeURIComponent(encodedValue);
220241
parsed[key] = value;
221242
});
222243
return parsed;
223-
};
244+
}
224245

225246
export function formatOptions(options) {
226247
const { path, domain, expires, secure } = options;
227248
return [
228-
typeof path === 'undefined' || path === null
229-
? '' : ';path=' + path,
230-
typeof domain === 'undefined' || domain === null
231-
? '' : ';domain=' + domain,
249+
typeof path === 'undefined' || path === null ? '' : ';path=' + path,
250+
typeof domain === 'undefined' || domain === null ? '' : ';domain=' + domain,
232251
typeof expires === 'undefined' || expires === null
233-
? '' : ';expires=' + expires.toUTCString(),
252+
? ''
253+
: ';expires=' + expires.toUTCString(),
234254
typeof secure === 'undefined' || secure === null || secure === false
235-
? '' : ';secure'
255+
? ''
256+
: ';secure',
236257
].join('');
237-
};
258+
}
238259

239260
export function formatCookie(key, value, options) {
240261
return [
241262
encodeURIComponent(key),
242263
'=',
243264
encodeURIComponent(value),
244-
formatOptions(options)
265+
formatOptions(options),
245266
].join('');
246-
};
267+
}
247268

248269
export function getObjectProperty(objectRef, propertyName) {
249270
let value = undefined;

‎yarn.lock

+534-7,463
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.