1.0.6 • Published 6 years ago

simplehtmlchecker v1.0.6

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

simplehtmlchecker

A simple HTML checker

Installation

npm install eslint -g

Getting started

...
const {Checker, InputType, OutputType} = require('simplehtmlchecker');
...
var checker = new Checker();
checker
.input(InputType.Text, "<html></html>")
.output(OutputType.Console)
.check();

Check analyze result

...
checker
.input(InputType.Text, "<html></html>")
.output(OutputType.Console)
.check(function(result, messages){
    ...
});

Set rule's params

...
checker.registeredRules.MoreThanNStrongTagRule.params.maxStrongTagCount = 15;
checker
.input(InputType.Text, "<html></html>")
.output(OutputType.Console)
.check();

Set rule's active status

...
checker.registeredRules.ImgTagShouldHaveAltAttributeRule.isActive = false;
checker
.input(InputType.Text, "<html></html>")
.output(OutputType.Console)
.check();

Create custom rule

...
class ATagShuldHaveHrefAttributeRule extends Rule {
    constructor(){
        super('ATagShuldHaveHrefAttributeRule', 'a:not([href])', function(length) { return 'There are ' + length + ' <a> tag without href attribute.'; });
     }
}

module.exports = ATagShuldHaveHrefAttributeRule;
...
var aTagShouldHaveHrefAttributeRule = new Rule('ATagShouldHaveHrefAttributeRule', 'a:not([href])', function(length) { return 'There are ' + length + ' <a> tag without href attribute.'; });

Register custom rule

...
checker.registerRules([ATagShuldHaveHrefAttributeRule]);
checker
.input(InputType.Text, "<html></html>")
.output(OutputType.Console)
.check();

Use custom rule

...
checker
.input(InputType.Text, "<html></html>")
.output(OutputType.Console)
.rules([aTagShouldHaveHrefAttributeRule])
.check();

Input form stream

...
checker
.input(InputType.Stream, stream)
.check();

Input form file

...
checker
.input(InputType.File, file)
.check();

Output to stream

...
checker
.input(InputType.Text, "<head><title></title><meta name='descriptions'/><meta name='keywords'/></head><img/>")
.output(OutputType.Stream, stream)
.check();

Output to file

...
checker
.input(InputType.Text, "<head><title></title><meta name='descriptions'/><meta name='keywords'/></head><img/>")
.output(OutputType.File, file)
.check();
1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago