tweb/src/helpers/string/parseUriParams.ts

24 lines
552 B
TypeScript
Raw Normal View History

2022-11-18 10:43:52 +01:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
export default function parseUriParams(uri: string, splitted = uri.split('?')) {
2023-03-01 11:56:06 +01:00
return parseUriParamsLine(splitted?.[1]);
}
export function parseUriParamsLine(line: string) {
2022-11-18 10:43:52 +01:00
const params: any = {};
2023-03-01 11:56:06 +01:00
if(!line) {
return params;
}
line.split('&').forEach((item) => {
const [key, value = ''] = item.split('=');
params[key] = decodeURIComponent(value);
2022-11-18 10:43:52 +01:00
});
return params;
}