Created
September 21, 2017 07:57
-
-
Save Shuumatsu/73434a1b607d78741150f88fe860fb14 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const ensureStartsWith = (start, str) => str.startsWith(start) ? str : start + str | |
const setSearchParam = searchStr => | |
(key, value) => { | |
if (!value) return searchStr | |
const searchParams = new URLSearchParams(searchStr) | |
searchParams.set(key, value) | |
const newSearchStr = | |
ensureStartsWith('?', searchParams.toString()) | |
return newSearchStr | |
} | |
export default setSearchParam |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment