verdnatura-chat/app/lib/methods/helpers/parseQuery.ts

19 lines
535 B
TypeScript
Raw Normal View History

2022-02-28 18:00:47 +00:00
/**
*
* @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;
}, {});
}