Last active
March 15, 2018 13:02
-
-
Save zburgermeiszter/ed1b92b3f9efd20bf6862dfab5ff201a to your computer and use it in GitHub Desktop.
ES6 tagged template literal example
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
import * as _ from 'lodash' | |
const uppercase = (strings, ...values) => { | |
const upper = (input) => _.isString(input) ? input.toUpperCase() : input; | |
const zipped = _.zipWith(strings, values, (text, variable) => [text, upper(variable)]); | |
const flat = _.flattenDeep(zipped); | |
return flat.join(''); | |
} | |
const user = 'John Doe'; | |
const subscription = 'pro'; | |
const expiry = 'tomorrow'; | |
console.log(uppercase`Hi, ${user}, you have ${subscription} package until ${expiry}.`); | |
// Hi, JOHN DOE, you have PRO package until TOMORROW. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment