outerspace
v0.5.2
Published
Preserve whitespace surrounding expressions in a template string.
Downloads
34
Maintainers
Readme
outerspace
Preserve whitespace surrounding expressions in a template string.
Outerspace helps to preserve outer whitespace when prefixing and suffixing a string by moving any leading/trailing whitespace in the original string to the start/end of the return.
const outerspace = require('outerspace')
outerspace`**${'\n Exclamation! \n\n'}**`
// '\n **Exclamation!** \n\n'
outerspace`**${'\n\n Holy'} ${'Exclamation '}${'Batman! \n'}**`
// '\n\n **Holy Exclamation Batman!** \n'
outerspace.wrap('Holy ', '\n\n Exclamation \n', ' Batman!')
// '\n\n Holy Exclamation Batman! \n'
outerspace.before('\n\n Exclamation Batman! \n', 'Holy ')
// '\n\n Holy Exclamation Batman! \n'
outerspace.after('\n\n Holy Exclamation \n', ' Batman!')
// '\n\n Holy Exclamation Batman! \n'
API
outerspace`[before]${[exprs]}...[after]`
Tagged template function: move any leading whitespace in the first expression to the start of the return, and any trailing whitespace in the last expression to the end of the return.
outerspace.wrap(before, string, after)
Concatenate the given strings in order and move leading/trailing whitespace in
string
to the start/end of the return.
outerspace.before(string, before)
Concatenate the given strings in the order before + string
and move leading
whitespace in string
to the start of the return;
outerspace.after(string, after)
Concatenate the given strings in the order string + after
and move trailing
whitespace in string
to the end of the return;