# domdefect

> Provide the functionalities to check if given HTML DOM elements match the user-defined rules

Latest version **0.0.1** (published 2018-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install domdefect
pnpm add domdefect
yarn add domdefect
bun add domdefect
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-06-18 |
| First published | 2018-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 49.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | rakasha |

## Links

- npm: https://www.npmjs.com/package/domdefect
- Repository: https://github.com/Rakasha/seo_defect
- Homepage: https://github.com/Rakasha/seo_defect#readme
- Issues: https://github.com/Rakasha/seo_defect/issues
- npm.io page: https://npm.io/package/domdefect

## Dependencies (4)

- [debug](https://npm.io/package/debug.md) ^3.1.0
- [jsdom](https://npm.io/package/jsdom.md) ^11.11.0
- [is-url](https://npm.io/package/is-url.md) ^1.2.4
- [lodash](https://npm.io/package/lodash.md) ^4.17.10

## Recent versions

- 0.0.1 (latest) — 2018-06-18

## README

dom-defect
=================
Detect defections from HTML DOM-Elements

## Installation

```bash
npm install domdefect
```

## Usage

Initialize the client

```javascript
const domdefect = require('domdefect');
let detector = new domdefect.Detector();
```
Set the rules for the detector

```javascript
// Using pre-defined rule
const {rules} = domdefect;
detector.rules_to_apply = [rules.PREDEFINED[0], rules.PREDEFINED[1]]
// Or customize your rule from Meta rules
let myRule = rules.Meta.checkNumberOfSelected('strong', '<', 2);
let myRule2 = rules.Meta.checkElementAttributes('input', ['value', 'id', 'yo']);
detector.rules_to_apply.push(myRule);
detector.rules_to_apply.push(myRule2);
```

Load the HTML from source (URL or file path).
Then run the detector to get the report.

```javascript
// Load HTML then run validations
// You can also load HTML from file by passing file path
// like: setDocumentSource('index.html')
detector.setDocumentSource('http://www.example.com')
 .then( () => {
    detector.run();
    
    // Aftter running , the results is stored 
    // in the `report` object in JSON format:
    detector.report.detail()
    
    // You can pretty-print the data
    detector.report.print();
    
    // Output the report into file
    detector.report.toFile('myreport.txt').then(...);
    
    // Or write into a writable stream
    detector.report.writeToStream(stream).then(...);
    
 });

```
## How to cusomize rules for the detector
Using the high order functions inside `lib/rules.js`.

For exmaple, calling

```javascript
const {rules} = require('domdefect');
let myRule = rules.Meta.checkNumberOfSelected('strong', '<', 2);
```
Generates a rule which checks if the number of `<strong>` tags is less than 2

## API
(TBD)





```
                       _oo0oo_
                      o8888888o
                      88" . "88
                      (| -_- |)
                      0\  =  /0
                    ___/`---'\___
                  .' \\|     |// '.
                 / \\|||  :  |||// \
                / _||||| -:- |||||- \
               |   | \\\  -  /// |   |
               | \_|  ''\---/''  |_/ |
               \  .-\__  '-'  ___/-. /
             ___'. .'  /--.--\  `. .'___
          ."" '<  `.___\_<|>_/___.' >' "".
         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
         \  \ `_.   \_ __\ /__ _/   .-` /  /
     =====`-.____`.___ \_____/___.-`___.-'=====
                       `=---='


     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                       佛系開發
```

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