# html-rulechecker

> Check HTML by custom rule

Latest version **1.0.6** (published 2018-06-22) · ISC license · 0 weekly downloads

## Install

```sh
npm install html-rulechecker
pnpm add html-rulechecker
yarn add html-rulechecker
bun add html-rulechecker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2018-06-22 |
| First published | 2018-06-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Mike |
| Maintainers | eva0919 |

## Links

- npm: https://www.npmjs.com/package/html-rulechecker
- npm.io page: https://npm.io/package/html-rulechecker

## Dependencies (1)

- [jsdom](https://npm.io/package/jsdom.md) ^11.11.0

## Recent versions

- 1.0.6 (latest) — 2018-06-22
- 1.0.5 — 2018-06-22
- 1.0.4 — 2018-06-22
- 1.0.3 — 2018-06-19
- 1.0.2 — 2018-06-19
- 1.0.1 — 2018-06-19
- 1.0.0 — 2018-06-19

## README

## Installation
```sh
$ npm i --save html-rulechecker
```
     
## Demo Code       
Demo#1 : Input from file stream, and ouput to another file stream. Moreover, show how to add new rule by yourself.       
```js
const fs = require('fs');
const htmlChecker = require('html-rulechecker');
const {
    Checker,
    RuleCreator
} = htmlChecker;

function testFileStream() {
    const rs = fs.createReadStream('./test/sample.html');
    const ws = fs.createWriteStream('./test/result');
    const checker = Checker(rs, ws)
    const ruleCreator = RuleCreator()
    const rules = ruleCreator.defaultRules();
    const newRule = ruleCreator.createRuleObject(
        ruleCreator.createNumberChecker(
            "head>meta[name=robots]", 1, "min"
        ),
        `Header doesn't have <meta name="robots"> tag`
    );
    const customRule = {
        judgeFunction: function(document) {
            return document.querySelectorAll('meta[name=hellochecker]').length > 0
        },
        message: `Doesn't pass custom rule.`
    }
    const newRules = [...rules, newRule, customRule]
    checker.updateRules(newRules);
    checker.check().then(() => {
        console.log("Check Finished");
    })
}

```
     
Demo#2 : Input from http stream, and ouput to console. Apply rule masks at check 2 processing.     
```js
const fs = require('fs');
const https = require('https');
const htmlChecker = require('html-rulechecker');
const {
    Checker,
    RuleCreator
} = htmlChecker;

function testHttp() {
    https.get('https://nodejs.org/en/', (rs) => {
        const checker = Checker(rs)
        const ruleCreator = RuleCreator()
        const rules = ruleCreator.defaultRules();
        checker.updateRules(rules);
        checker.check().then(() => {
            console.log("Check #1 Finished");
            checker.updateRules(rules, [0, 1, 2, 5, 4]);
            return checker.check()
        }).then(() => {
            console.log("Check #2 Finished");
        })

    });
}
```

---
_Source: https://npm.io/package/html-rulechecker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
