Skip to content

Instantly share code, notes, and snippets.

@zburgermeiszter
Last active March 15, 2018 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zburgermeiszter/ed1b92b3f9efd20bf6862dfab5ff201a to your computer and use it in GitHub Desktop.
Save zburgermeiszter/ed1b92b3f9efd20bf6862dfab5ff201a to your computer and use it in GitHub Desktop.
ES6 tagged template literal example
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