https://github.com/stefee/outerspace
https://github.com/stefee/outerspace
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/stefee/outerspace
- Owner: stefee
- License: mit
- Created: 2017-11-23T20:26:17.000Z (over 8 years ago)
- Default Branch: latest
- Last Pushed: 2021-08-08T18:49:21.000Z (almost 5 years ago)
- Last Synced: 2025-06-11T14:18:14.707Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# outerspace
[](https://npmjs.org/package/outerspace) [](https://travis-ci.com/stefee/outerspace)
[](https://npmjs.org/package/outerspace) [](https://github.com/feross/standard)
> 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.
```js
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;