Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

htmlcomb

fengyuanchen562MITdeprecated0.3.1

No longer maintained.

A simple tool for combing HTML attributes.

attribute, format, comb, html, javascript, front-end, web, development

readme

HTMLComb

A simple tool for combing HTML attributes.

Main

dist/
├── htmlcomb.js      (8 KB)
└── htmlcomb.min.js  (4 KB)

Getting started

Quick start

Three quick start options are available:

Usage

Browser

<script src="/path/to/htmlcomb.js"></script>
var htmlcomb = new HTMLComb(options);

htmlcomb.format(source, function (result) {
  console.log(result);
});

NodeJS

var fs = require("fs");
var HTMLComb = require("htmlcomb");
var htmlcomb = new HTMLComb(options);

fs.readFile("/path/to/source.html", function(err, data) {
  if (err) {
    throw err;
  }

  fs.writeFile("/path/to/result.html", htmlcomb.format(data.toString()), function (err) {
    if (err) {
      throw err;
    }

    console.log("Done, without errors.");
  });
});

Options

requireDoubleQuotationMarks

  • Type: Boolean
  • Default: true

For example:

<!-- Source -->
<div id=main></div>

<!-- Result -->
<div id="main"></div>

replaceSingleQuotationMarks

  • Type: Boolean
  • Default: true

For example:

<!-- Source -->
<div id='main'></div>

<!-- Result -->
<div id="main"></div>

removeEmptyValues

  • Type: Boolean
  • Default: true

For example:

<!-- Source -->
<div class="     " id=""></div>

<!-- Result -->
<div class id></div>

removeNewlines

  • Type: Boolean
  • Default: true

Also removes the indentation after the newline.

For example:

<!-- Source -->
<div data-search="{
  'url': 'https://github.com/search',
  'q': 'htmlcomb'
}"></div>

<!-- Result -->
<div data-search="{ 'url': 'https://github.com/search', 'q': 'htmlcomb'}"></div>

removeMultipleSpaces

  • Type: Boolean
  • Default: true

For example:

<!-- Source -->
<div class="foo   bar     baz"></div>

<!-- Result -->
<div class="foo bar baz"></div>

order

  • Type: Array
  • Default:
    [
    "class",
    "id",
    "name",
    "data",
    "src",
    "for",
    "type",
    "href",
    "value",
    "title",
    "alt",
    "role",
    "aria"
    ]

The default order references to the Code Guide's attribute order.

For example:

<!-- Source -->
<input required class="input-email" type="email" id="inputEmail" name="email">

<!-- Result -->
<input class="input-email" id="inputEmail" name="email" type="email" required>

Methods

setup(options)

Parameters Type Description
options Object Custom options

Change the default options.

format(source[, options[, callback]])

  • Alias: comb
Parameters Type Description
source String The source text for combing
options (optional) Object Change the default options temporarily
callback (optional) Function e.g: function (result) {}

Format source HTML attributes.

Browser support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Opera (latest)
  • Edge (latest)
  • Internet Explorer 8+

Versioning

Maintained under the Semantic Versioning guidelines.

License

MIT © Fengyuan Chen

changelog

Changelog

0.3.1 (Jun 10, 2016)

  • Add support for Vue.js template.

0.3.0 (Sep 3, 2015)

  • Add "options" parameter back to "format" method.
  • Improve the "setup" method.
  • Export static methods.

0.2.0 (Dec 12, 2014)

  • Supports more browsers.
  • Add 2 options: "removeNewlines", "removeMultipleSpaces".
  • Rename "removeEmptyValue" option to "removeEmptyValues".
  • Remove "options" parameter of "format" method.

0.1.2 (Nov 28, 2014)

  • Improves the "format" method.

0.1.1 (Nov 13, 2014)

  • Add method: "setup"
  • Add alias "comb" for "format" method

0.1.0 (Nov 9, 2014)

  • Supports options: "requireDoubleQuotationMarks", "replaceSingleQuotationMarks", "removeEmptyValue", "order"
  • Supports method: "format"