Files
shields/frontend/lib/resolve-url.js
Paul Melnikow 7a664ca3e8 Run prettier (#1866)
Merging this separately so the commit with the tooling change is readable. This is a follow-on to #1167 which turned prettier on.
2018-08-08 17:57:14 -04:00

15 lines
625 B
JavaScript

// I played with build-url and url-resolve-browser and neither of them did the
// right thing. Previously this was based on url-path, which patched around
// the URL API. This caused problems in Firefox 57, but only in the production
// build.
import { resolve, parse, format } from 'url'
// baseUrl and queryParams are optional.
export default function resolveUrl(url, baseUrl, queryParams) {
const resolved = baseUrl ? resolve(baseUrl, url) : url
const parsed = parse(resolved, /* parseQueryString */ true)
parsed.query = Object.assign({}, parsed.query, queryParams)
delete parsed.search
return format(parsed)
}