Skip to content

Instantly share code, notes, and snippets.

@FireNeslo FireNeslo/demo.es6
Last active Jan 2, 2018

Embed
What would you like to do?
Simple es6 heredoc thingy
var html = heredoc `
<section>
<h1> title</h1>
<p>content</p>
</section>
`
function leastSpaces(length, line) {
if(!line.length) return length
var spaces = line.match(/^\s+/).pop().length
return spaces < length ? spaces : length
}
function heredoc(strings) {
var lines = strings.join('').split(/\r?\n/)
var spaces = lines.reduce(leastSpaces, Infinity)
return lines.map(line => line.substring(spaces)).join('\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.