Skip to content

Instantly share code, notes, and snippets.

@charly-palencia
Created November 29, 2019 20:36
Show Gist options
  • Select an option

  • Save charly-palencia/aa41cd9fa5ae69d00e73438399adcf33 to your computer and use it in GitHub Desktop.

Select an option

Save charly-palencia/aa41cd9fa5ae69d00e73438399adcf33 to your computer and use it in GitHub Desktop.
JS Template Literals: Tagged templates
const styled;
const myTag = (strings, ...args) => {
const emojiFruits= {
"bannana": "🍌",
"pear": "🍎",
"apple": "🍐",
};
// input: ["Let's make some mix juice with ", ' in the ', '' ]
const [str0, str1] = strings;
// input: [ [ 'bannana', 'apple', 'pear' ] ]
const [fruits] = args;
const emojis = fruits.map(fruit => emojiFruits[fruit]).join();
// Concat Em All!
return [str0, emojis, str1].join("");
};
const fruits = ["bannana", "apple", "pear"];
myTag`Let's make some mix juice with ${fruits}!!!`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment