Honestly way too much went into this single commit. I am so sorry future me
This commit is contained in:
20
project-warstone/src/utils/queryParams.ts
Normal file
20
project-warstone/src/utils/queryParams.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export class QueryParams {
|
||||
private params = new Map<string, string>()
|
||||
constructor(options?: {clean: boolean}) {
|
||||
if (!options?.clean) {
|
||||
const {search} = location;
|
||||
for (const [key, value] of search.replace('?', '').split('&').map(e => e.split('='))) {
|
||||
this.params.set(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get = this.params.get
|
||||
set = this.params.set
|
||||
delete = this.params.delete
|
||||
clear = this.params.clear
|
||||
|
||||
apply() {
|
||||
location.search = '?' + encodeURIComponent(Array.from(this.params.entries()).map(e => e.join('=')).join('&'))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user