New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you deal with leading/trailing line breaks in template literals? #10
Comments
It was such a missed opportunity how template literals were designed. In Swift, this does exactly what you want: foo(
"""
Foo
Bar
"""
) let foo = """
Foo
""" |
Back to your request, I'm willing to add an option for this. Any suggestion what it should be called? I think the only thing missing is trimming the string before stripping indentation. |
const fire = stripIndent(`
THIS IS FINE.
I'M OK WITH THE EVENTS UNFOLDING CURRENTLY.
`, {trimNewLines: true});
// => '\tTHIS IS FINE.\nI'M OK WITH THE EVENTS UNFOLDING CURRENTLY.' |
Not exact enough. It doesn't trim all newlines, just the leading/trailing newlines. I guess |
A bit. Autocomplete cam help but there's still too much room for error/typos. |
|
For the record, However it trims even some indentation that shouldn't be, like the first one |
Isn't this request equivalent to outdent? |
@sindresorhus @fregante I created a proposal to extend es6 template literals to allow for triple-backtick delimited literals that automatically strip margins: https://github.com/mmkal/proposal-multi-backtick-templates It'd be great to get any feedback based on usage of this library on how you think things like this should be handled. My hope is for the default behaviour to be "what you want" for the majority of cases, therefore avoiding the need for runtime string formatting as much as possible. |
This would be my main use case, but
strip-indent
only literally strips the indentation.I'm currently using this instead of
strip-indent
but maybe you have a better solution (or can extendstrip-indent
)The text was updated successfully, but these errors were encountered: