htmlcombdeprecated

A simple tool for combing HTML attributes.

Usage no npm install needed!

<script type="module">
  import htmlcomb from 'https://cdn.skypack.dev/htmlcomb';
</script>

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