Socket
Socket
Sign inDemoInstall

seo-inspector

Package Overview
Dependencies
92
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    seo-inspector

SEO Inspector


Version published
Weekly downloads
3
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

SEO Checker

A library for scanning a HTML file to show all of the SEO defects

Usage

Install with npm npm install seo-inspector --save

Getting started

Require the library and then all the methods listed below will be made available to you.

new SeoInspector(<options>).read(<input>).addRule(<rule>).addRule(<rule>).write(<output>);

Usage:

  • options.done: callback function.
  • input: a HTML file path
  • output: a file path
  • rule: predefined rule name and settings.
One way: read from a HTML file, write result to a file
import fs from 'fs';
const SeoInspector = require('seo-inspector')
new SeoInspector({ done:
                    (err, data) => {
                        if (err) throw err;
                    }
                })
.read('source/target.html')
.write('destination/report.txt');
Two way: read from a Node Readable Stream, write result to a Node Writable Stream
import fs from 'fs';
const SeoInspector = require('seo-inspector')
new SeoInspector({ done:
                    (err, data) => {
                        if (err) throw err;
                    }
                })
.read(fs.createReadStream('source/target.html'))
.write(fs.createWriteStream('destination/report.txt'));
Three way: read from a HTML file, write result to console
import fs from 'fs';
const SeoInspector = require('seo-inspector')
new SeoInspector({ done:
                    (err, data) => {
                        if (err) throw err;
                    }
                })
.read('source/target.html')
.write(console);
Example output to show all SEO defects
SEO defects found:
There are 2 <img> tag without alt attribute
There are 2 <a> tag without rel attribute
This HTML without <title> tag
This HTML without <meta name="descriptions"> tag
This HTML without <meta name="keywords"> tag
This HTML have more than 15 <strong> tags
This HTML have more than one <h1> tag

or

No any SEO defect found.
Chaining any rules and config check options, or just to apply all rules by default

Now supported and predefined SEO rules are ImgTagWithAltAttritube, ATagWithRelAttritube, HeadTagWithTitleAndDescriptionsKeywordsMeta, NoTooManyStrongTags and NoMoreThanOneH1Tag

...
.addRule('ImgTagWithAltAttritube')
.addRule('NoTooManyStrongTags', { threshold: 20 })
...
Add custom rule by creating a class to extend base rule and implement check method.

The object key is required setting for check options :

import UserCustomRule from './UserCustomRule';
...
.addRule('UserCustom', { object: new UserCustomRule({ threshold: 5 }) })
...

Implement your custom rule checker class, extend base rule class is mandatory :

'use strict'

import BaseRule from './BaseRule'

class NoTooManyStrongTagsRule extends BaseRule {
  check (dom) {
    if (this.options.enabled === 0) {
      return
    }
    let report = ''
    const elements = dom.window.document.querySelectorAll('strong')
    if (elements && elements.length > this.options.threshold) {
      report += 'This HTML have more than ' + this.options.threshold + ' <strong> tags'
    }
    return report
  }
}

export default NoTooManyStrongTagsRule

Keywords

FAQs

Last updated on 03 Dec 2017

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc