Jeheonjeol
1/14/2019 - 1:53 AM

add or update query string parameters

add or update query string parameters

import * as qs from 'qs'
import { parse, UrlWithParsedQuery } from 'url'

public static updateQueryStringParams(url: string, params: {[key: string]: any}): string {
	const _url: UrlWithParsedQuery = parse(url, true)
	const _params: {[key: string]: any} = { ..._url.query, ...params }
	
	return `${_url.protocol}//${_url.host}${_url.pathname}?${qs.stringify(_params)}`
}