the URL to encode
zero or more parameter objects to encode
the encoded URL
import { encodeUrlParams } from "@trashpanda001/helpers/string"
encodeUrlParams("/search", { limit: 200 }, { query: "foo bar" })
// "/search?limit=200&query=foo+bar"
encodeUrlParams("/search?limit=200", { query: "foo" }, { limit: 300 })
// "/search?limit=300&query=foo"
encodeUrlParams("/none")
// "/none"
Encode a URL with optional query parameters.
Automatically drops null or undefined parameter values (if needed, explicitly pass as string values). Handles the case if the
url
already contains some re-encoded query parameters. Accepts multiple parameter objects that will be merged, with later parameters overriding earlier ones.