Skip to content

Instantly share code, notes, and snippets.

@employee451
Created May 30, 2022 11:55
Show Gist options
  • Save employee451/56f88d0e45e0dfd6630cb350c8e8a34f to your computer and use it in GitHub Desktop.
Save employee451/56f88d0e45e0dfd6630cb350c8e8a34f to your computer and use it in GitHub Desktop.
/**
* Takes an object of key-value pairs, and assembles them to a URI string
* @param { Object } object
* @returns { String } A URI string
*/
export const objectToUriString = (object: {
[key: string]: string | number | null | undefined
}): string =>
Object.keys(object)
.map((key) => key + '=' + encodeURIComponent(object[key] || ''))
.join('&')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment