PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / utils / get-url-parameter.js

get-url-parameter.js in Extendify trunk, at src/Shared/utils/get-url-parameter.js

25 lines 680 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { sanitizeString } from '@shared/utils/sanitize';
2
3 export const getUrlParameter = (parameterName, cleanUrl = true) => {
4 const urlParams = new URLSearchParams(window.location.search);
5 if (!urlParams.has(parameterName)) return null;
6
7 const sanitizedParameter = sanitizeString(urlParams.get(parameterName));
8
9 if (cleanUrl) {
10 urlParams.delete(parameterName);
11 const cleanedSearchParameters = urlParams.toString();
12 const searchParametersToUrl = cleanedSearchParameters
13 ? `?${cleanedSearchParameters}`
14 : '';
15
16 window.history.replaceState(
17 {},
18 document.title,
19 `${window.location.pathname}${searchParametersToUrl}`,
20 );
21 }
22
23 return sanitizedParameter;
24 };
25