Last active
          May 16, 2019 12:43 
        
      - 
      
- 
        Save martinhj/a5af86b2a631729be2f3c16878ca561c to your computer and use it in GitHub Desktop. 
    Generate Search Query With Tagged Template Literals
  
        
  
    
      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 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