Created
February 25, 2019 22:44
-
-
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).
This file contains 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
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