From 9b369e548e618b5d979a590f314d887fe961ae42 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Wed, 16 Feb 2022 12:20:55 -0300 Subject: [PATCH] Chore: Migrate methods/helpers/parseQuery to Typescript (#3742) * Chore: Migrate methods/helpers/parseQuery to Typescript * tweak in example --- app/lib/methods/helpers/parseQuery.js | 7 ------- app/lib/methods/helpers/parseQuery.ts | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) delete mode 100644 app/lib/methods/helpers/parseQuery.js create mode 100644 app/lib/methods/helpers/parseQuery.ts diff --git a/app/lib/methods/helpers/parseQuery.js b/app/lib/methods/helpers/parseQuery.js deleted file mode 100644 index 30f1bb3c6..000000000 --- a/app/lib/methods/helpers/parseQuery.js +++ /dev/null @@ -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; - }, {}); -} diff --git a/app/lib/methods/helpers/parseQuery.ts b/app/lib/methods/helpers/parseQuery.ts new file mode 100644 index 000000000..c6e2bb5fd --- /dev/null +++ b/app/lib/methods/helpers/parseQuery.ts @@ -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; + }, {}); +}