Created
May 17, 2021 19:56
-
-
Save garand/deee6a30b79f4e4bc99ad668a69d932e to your computer and use it in GitHub Desktop.
Utility to convert object values to strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert object of unknown value types to strings for use as request query params | |
*/ | |
export function paramify<T>( | |
params?: T | |
): { [key in keyof T]: string } | undefined { | |
if (!params) return undefined; | |
return Object.fromEntries( | |
Object.entries(params).map((param) => [param[0], String(param[1])]) | |
) as { [key in keyof T]: string }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment