Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save martinhj/a5af86b2a631729be2f3c16878ca561c to your computer and use it in GitHub Desktop.
Save martinhj/a5af86b2a631729be2f3c16878ca561c to your computer and use it in GitHub Desktop.
Generate Search Query With Tagged Template Literals
const linkPath = '/workingMode/distracted/aBit'
const isDarkTheme = true
const generateSearchQuery = (strings, linkExp, searchArgument = 'gaveUp') => {
let searchQuery = '?search='
const [,searchQueryArg ,] = strings
const themeString = isDarkTheme ? 'dark' : 'light'
if (searchQueryArg !== '') searchQuery = searchQueryArg
return `/en-us${linkExp}${searchQuery}${searchArgument}?themeType=${themeString}`
}
const generatePath = (index) => generateSearchQuery`${linkPath}?action=${'tryABitMore'}`
// `-> '/en-us/workingMode/distracted/aBit?action=tryABitMore?themeType=dark'
const generatePath = (index) => generateSearchQuery`${linkPath}?action=`
// `-> '/en-us/workingMode/distracted/aBit?action=gaveUp?themeType=dark'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment