Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukekarrys/html-tagged-literals
Tagged literals for modifying newlines and whitespace in HTML string literals.
https://github.com/lukekarrys/html-tagged-literals
Last synced: 3 days ago
JSON representation
Tagged literals for modifying newlines and whitespace in HTML string literals.
- Host: GitHub
- URL: https://github.com/lukekarrys/html-tagged-literals
- Owner: lukekarrys
- License: mit
- Created: 2016-02-11T03:21:48.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-17T02:50:55.000Z (over 7 years ago)
- Last Synced: 2025-01-02T23:49:41.906Z (5 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
html-tagged-literals
==================[![NPM](https://nodei.co/npm/html-tagged-literals.png)](https://nodei.co/npm/html-tagged-literals/)
[![Build Status](https://travis-ci.org/lukekarrys/html-tagged-literals.png?branch=master)](https://travis-ci.org/lukekarrys/html-tagged-literals)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)
[![Greenkeeper badge](https://badges.greenkeeper.io/lukekarrys/html-tagged-literals.svg)](https://greenkeeper.io/)## Install
```sh
npm install html-tagged-literals --save
```## Usage
ES2015 template strings are nice for generating HTML, but can be annoying because of stuff like this:
```js
const html = () => {
const css = '/path/to/theme.css'
const js = '/path/to/app.js'// The code looks readable and nice but now the html will have leading and
// trailing newlines and each line will be indented by 4 extra spaces
return `
`
}
```This module gives you a few tagged template literals for either stripping all newlines and whitespace or just unindenting the string literal:
```js
import {minify, unindent} from 'html-tagged-literals'const html = () => {
const css = '/path/to/theme.css'
const js = '/path/to/app.js'// This will now be a single line of html.
// Use unindent to preserve the original indentation but to get rid of
// leading/trailing newlines and the first 4 spaces before each line.
return minify`
`
}
```## API
- `minify`
This will take the template string and remove all newlines followed by any number of spaces.
- `unindent`
This will take the template string and do the following:
* Remove leading/trailing newliens
* Remove empty lines
* Count the number of whitespace before the first non-empty line and remove those from the start of each line### LICENSE
MIT