Chore: Migrate methods/helpers/parseQuery to Typescript (#3742)

* Chore: Migrate methods/helpers/parseQuery to Typescript

* tweak in example
This commit is contained in:
Reinaldo Neto 2022-02-16 12:20:55 -03:00 committed by GitHub
parent 941a21dac6
commit 9b369e548e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View File

@ -1,7 +0,0 @@
export default function (query) {
return (/^[?#]/.test(query) ? query.slice(1) : query).split('&').reduce((params, param) => {
const [key, value] = param.split('=');
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
return params;
}, {});
}

View File

@ -0,0 +1,18 @@
/**
*
* @example
* parseQuery("host=open.rocket.chat&path=channel/general/thread/meRK2nfjR99MjLn55")
* // the return will be
* {
* host: "open.rocket.chat",
* path: "channel/general/thread/meRK2nfjR99MjLn55"
* }
*/
export default function (query: string) {
return (/^[?#]/.test(query) ? query.slice(1) : query).split('&').reduce((params: { [key: string]: string }, param) => {
const [key, value] = param.split('=');
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
return params;
}, {});
}