1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

Filter out falsey opts in /relations API hits (#2059)

This commit is contained in:
Michael Telatynski
2021-12-13 15:38:03 +00:00
committed by GitHub
parent 6244d77d44
commit 169b6b5572
4 changed files with 20 additions and 8 deletions

View File

@@ -27,12 +27,19 @@ import type NodeCrypto from "crypto";
/**
* Encode a dictionary of query parameters.
* Omits any undefined/null values.
* @param {Object} params A dict of key/values to encode e.g.
* {"foo": "bar", "baz": "taz"}
* @return {string} The encoded string e.g. foo=bar&baz=taz
*/
export function encodeParams(params: Record<string, string>): string {
return new URLSearchParams(params).toString();
export function encodeParams(params: Record<string, string | number | boolean>): string {
const searchParams = new URLSearchParams();
for (const [key, val] of Object.entries(params)) {
if (val !== undefined && val !== null) {
searchParams.set(key, String(val));
}
}
return searchParams.toString();
}
export type QueryDict = Record<string, string | string[]>;