-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
29 lines (28 loc) · 951 Bytes
/
helpers.js
File metadata and controls
29 lines (28 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function getURLComponents(url, removeParams) {
var pattern = /(.+:\/\/)?([^\/]+)(\/.*)*/i;
var arr = pattern.exec(url);
var cleanURL = arr[0].replace(/\/+$/, '')
var page = arr[3]
if(removeParams) {
var split = cleanURL.split('?')
// console.log(split, "cleaning url")
cleanURL = split[0]
page = page.split('?')[0]
}
return {
url: cleanURL,
protocal: arr[1],
hostname: arr[2],
page: page
}
}
function getQueryStringParams(params, url) {
// first decode URL to get readable data
var href = decodeURIComponent(url || window.location.href);
// regular expression to get value
var regEx = new RegExp('[?&]' + params + '=([^&#]*)', 'i');
var value = regEx.exec(href);
// return the value if exist
return value ? value[1] : null;
};
module.exports = {getURLComponents, getQueryStringParams}