mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Simplify url utils
This commit is contained in:
parent
67169e2a6a
commit
3412201532
5 changed files with 8 additions and 30 deletions
|
@ -1,26 +1,8 @@
|
|||
export const getWindowLocationSearch = (win?: Window | null | undefined) => {
|
||||
let search = (win || window).location.search;
|
||||
|
||||
if (!search) {
|
||||
const index = window.location.href.indexOf('?');
|
||||
|
||||
if (index != -1) {
|
||||
search = window.location.href.substring(index);
|
||||
}
|
||||
}
|
||||
|
||||
return search || '';
|
||||
};
|
||||
|
||||
export const getParameterByName = (name: string, url?: string | null | undefined) => {
|
||||
name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
const regexS = '[\\?&]' + name + '=([^&#]*)';
|
||||
const regex = new RegExp(regexS, 'i');
|
||||
const results = regex.exec(url || getWindowLocationSearch());
|
||||
|
||||
if (results == null) {
|
||||
return '';
|
||||
if (!url) {
|
||||
url = window.location.search;
|
||||
}
|
||||
|
||||
return decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
// eslint-disable-next-line compat/compat
|
||||
return new URLSearchParams(url).get(name) || '';
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue