Completed
Push — master ( 0669d1...20d753 )
by Dimas
09:15 queued 01:26
created

libs/js/url.ts   A

Complexity

Total Complexity 6
Complexity/F 6

Size

Lines of Code 23
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 6
mnd 5
bc 5
fnc 1
bpm 5
cpm 6
noi 0
1
/**
2
 * get url parameter by name
3
 * @param name parameter name
4
 * @param url url target, null for current location.href
5
 */
6
function getParameterByName(name: string, url: string | null) {
7
  if (typeof URLSearchParams !== 'undefined') {
8
    if (!window.location.search) {
9
      url = window.location.href;
10
    }
11
    const urlParams = new URLSearchParams(url);
12
    return urlParams.get(name);
13
  }
14
  if (!url) {
15
    url = window.location.href;
16
  }
17
  name = name.replace(/[\[\]]/g, '\\$&');
18
  var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
19
    results = regex.exec(url);
20
  if (!results) return null;
21
  if (!results[2]) return '';
22
  return decodeURIComponent(results[2].replace(/\+/g, ' '));
23
}