refactoring

This commit is contained in:
Hakim El Hattab
2020-03-10 20:40:35 +01:00
parent 3d6212378a
commit ac15678dea
5 changed files with 69 additions and 53 deletions

View File

@ -158,4 +158,30 @@ export const createStyleSheet = ( value ) => {
return tag;
}
/**
* Returns a key:value hash of all query params.
*/
export const getQueryHash = () => {
let query = {};
location.search.replace( /[A-Z0-9]+?=([\w\.%-]*)/gi, a => {
query[ a.split( '=' ).shift() ] = a.split( '=' ).pop();
} );
// Basic deserialization
for( let i in query ) {
let value = query[ i ];
query[ i ] = deserialize( unescape( value ) );
}
// Do not accept new dependencies via query config to avoid
// the potential of malicious script injection
if( typeof query['dependencies'] !== 'undefined' ) delete query['dependencies'];
return query;
}