Git Product home page Git Product logo

seo_defect's Introduction

Build Status Coverage Status npm version

dom-defect

Detect defections from HTML DOM-Elements

Installation

npm install domdefect

Usage

Initialize the client

const domdefect = require('domdefect');
let detector = new domdefect.Detector();

Set the rules for the detector

// 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.

// 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 defined in lib/rules.js.

For exmaple, calling

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)

Test

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


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

                       佛系開發

seo_defect's People

Contributors

rakasha avatar

Watchers

James Cloos avatar  avatar

seo_defect's Issues

Use function reference instead of string tokens to assemble the DOM-checking rules.

Change the data structure for representing a Rule :
from ["DOM-selector name", "DOM-validator name"]
to [dom_selector_function, dom_validator_function]


Currently the checking-rules are represented by an array of strings which consists of the name of DOM-selector function and DOM-validation function.

For example, the predefined rule "all images have alt text": ["All <img> tags", "all have attributes alt"] means that when validating the HTML DOMs it will:

  1. Lookup the DOM-Selector function with the name "All <img> tags" and use it to acquire the DOM(s)
  2. Lookup the validation function "all have attributes alt" and use it to verify the DOMs

For keeping things simple we should use function reference instead of string

Allow various output format

According to this note
We should at least provide the following output format:

  • Console
  • A file (User is able to config the output destination)
  • Node Writable Stream (definition, detail)

Checklist:

  • Console (human readable)
  • File (configurable path)
  • Node writable stream
  • (Not Mandatory) Structured data in JSON

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.