Total Complexity | 6 |
Complexity/F | 6 |
Lines of Code | 23 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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 | } |