Socket
Book a DemoInstallSign in
Socket

htmlcomb

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlcomb

A simple tool for combing HTML attributes.

latest
Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
204
-28.17%
Maintainers
1
Weekly downloads
 
Created
Source

HTMLComb

A simple tool for combing HTML attributes.

  • Website

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)

ParametersTypeDescription
optionsObjectCustom options

Change the default options.

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

  • Alias: comb
ParametersTypeDescription
sourceStringThe source text for combing
options (optional)ObjectChange the default options temporarily
callback (optional)Functione.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

Keywords

attribute

FAQs

Package last updated on 10 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts