Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cowboy/node-heredoc-tag
Heredoc helpers for ES2015 template strings
https://github.com/cowboy/node-heredoc-tag
Last synced: 2 months ago
JSON representation
Heredoc helpers for ES2015 template strings
- Host: GitHub
- URL: https://github.com/cowboy/node-heredoc-tag
- Owner: cowboy
- License: mit
- Created: 2016-01-22T15:56:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-22T18:11:56.000Z (almost 9 years ago)
- Last Synced: 2024-10-04T00:35:51.336Z (3 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# heredoc-tag
> Heredoc helpers for ES2015 template strings
[![Build Status](https://travis-ci.org/cowboy/node-heredoc-tag.svg?branch=master)](https://travis-ci.org/cowboy/node-heredoc-tag)
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)## Installation
```
npm install heredoc-tag
```## Examples
_(Taken from the [examples](examples/examples.js) file)_
```js
import heredoc from 'heredoc-tag';
let str;// Trim
str = heredoc.trim`this is a test
`;
console.log(`"${str}"`); // "this is a test"// Remove newlines
str = heredoc.oneline`
Here is a sentence
split across
multiple lines.
`;
console.log(`"${str}"`); // " Here is a sentence split across multiple lines."// Remove newlines, trim each line, then join lines with a space
str = heredoc.oneline.trim`
Here is a sentence
split across
multiple lines.
`;
console.log(`"${str}"`); // "Here is a sentence split across multiple lines."// Unindent as far as possible
str = heredoc.unindent`
This is an example
where some text is indented more
and some text is indented less
for whatever reason.
`;
console.log(`"${str}"`);
// "
// This is an example
// where some text is indented more
// and some text is indented less
// for whatever reason.
// "// Unindent, trim the ends of lines, trim leading/trailing whitespace
str = heredoc.unindent.trim`
This is an example
where some text is indented more
and some text is indented less
for whatever reason.
`;
console.log(`"${str}"`);
// " This is an example
// where some text is indented more
// and some text is indented less
// for whatever reason."
```