Skip to content

Instantly share code, notes, and snippets.

@flisboac
Created February 25, 2019 22:44
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 flisboac/e9136a63d984ad3a7ef788939d2ae40c to your computer and use it in GitHub Desktop.
Save flisboac/e9136a63d984ad3a7ef788939d2ae40c to your computer and use it in GitHub Desktop.
Generic method to (re-)construct a string from a tagged template string literal. Useful for shims (e.g. fool your editor into thinking there's a `gql` tag).
function s(strings: ReadonlyArray<string>, ...exprs: any[]): string {
return strings.reduce((accum, elem, idx) => `${accum}${elem}${idx < exprs.length ? exprs[idx] : ''}`, '');
}
// Example:
// s`a_${10}_b` -> "a_10_b"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment