Created
April 30, 2019 00:36
-
-
Save aleph-naught2tog/810630cbe3cbaa9a00cf6541150e6008 to your computer and use it in GitHub Desktop.
Template tags
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
/* | |
Some languages, like Elixir, have sigils -- things that often look like a ~, a letter, and then some delimiters | |
with a string between them. | |
One handy one is: `~w` -- in Elixir, you can look it up in the Kernel as `sigil_w`. | |
*/ | |
// this is a one-liner of the function in the earlier file | |
const basicTag = (slots, ...values) => slots.map((slot, index) => [slot, values[index]].join('')).join(''); | |
function w(pieces, ...values) { | |
return basicTag(pieces, ...values).split(/\s/); | |
} | |
const letters = w`a b c d e f g h`; // => ["a", "b", "c", "d", "e", "f", "g", "h"] | |
const firstMessage = w`hello world`; // => ["hello", "world"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment