Socket
Book a DemoInstallSign in
Socket

seo-validator

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seo-validator

A Node.js package scan a HTML content and show all of SEO defects

1.0.1
latest
Source
npmnpm
Version published
Weekly downloads
23
35.29%
Maintainers
1
Weekly downloads
 
Created
Source

seo-validator

A Node.js package scan a HTML content and show all of SEO defects.

const { Validator, FileInput, ConsoleOutput } = require('seo-validator')

const validator = new Validator()
const filePath = __dirname + '/index.html'
const input = new FileInput(filePath)
const output = new ConsoleOutput()

// Skip predefined rules
validator.skipRules([1,4,5])

validator.setInput(input)
validator.setOutput(output)

try {
  validator
    .validate()
    .then(async () => {
      await validator.getResult()
    })
} catch (err) {
  console.error(err)
}

Requirements

Node.js 8.0 or greater

Installation

npm install seo-validator

Predefined Rules

  • Detect if there are any <img /> tags without alt attribute
  • Detect if there are any <a /> tags without rel attribute
  • Detect if there is any header that doesn’t have <title> tag
  • Detect if there is any header that doesn’t have <meta name="descriptions" … /> tag
  • Detect if there is any header that doesn’t have <meta name="keywords" … /> tag
  • Detect if there are more than 15 <strong> tag in HTML
  • Detect if a HTML have more than one <h1> tag

API

Rule

const {
    RuleExistTag,
    RuleTagExistAttribute,
    RuleTagExistAttributeValue,
    RuleTagCountLimit,
    RuleTagCountWithoutAttribute
} = require('seo-validator')

new RuleExistTag('head', 'title')
new RuleTagExistAttribute('head', 'img', 'alt')
new RuleTagExistAttributeValue('head', 'meta', 'name', 'description')
new RuleTagCountLimit('', 'strong', 15)
new RuleTagCountWithoutAttribute('', 'img', 'alt')

// Add rules
validator.addRule(new RuleExistTag('head', 'title'))
validator.addRule(new RuleTagExistAttribute('head', 'img', 'alt'))

Input

const fs = require('fs')
const { FileInput, StreamInput } = require('seo-validator')

const filePath = __dirname + '/index.html'
const input = new FileInput(filePath)

//const stream = fs.createReadStream(filePath)
//const input = new StreamOutput(stream)

validator.setInput(input)

Output

const fs = require('fs')
const { ConsoleOutput, FileOutput, StreamOutput } = require('seo-validator')

const filePath = __dirname + '/result.log'
const output = new ConsoleOutput()

//output = new FileOutput(filePath)

//const stream = fs.createWriteStream(filePath)
//const output = new StreamOutput(stream)

validator.setOutput(output)

Validator

constructor(skipPredefinedRules)

const { Validator } = require('seo-validator')
const validator = new Validator(true)
//const validator = new Validator(false)

skipRules(indexes)

validator.skipRules([1,4,5])

setInput(input)

const { FileInput } = require('seo-validator')
const filePath = __dirname + '/index.html'
const input = new FileInput(filePath)

validator.setInput(input)

setOutput(output)

const { ConsoleOutput } = require('seo-validator')
const filePath = __dirname + '/result.log'
const output = new ConsoleOutput()

validator.setOutput(output)

addRule(rule)

validator.addRule(new RuleExistTag('head', 'title'))

validate() && getResult()

try {
  validator
    .validate()
    .then(async () => {
      await validator.getResult()
    })
} catch (err) {
  console.error(err)
}

Custom Rules

const { Rule } = require('seo-validator')

class NewRule extends Rule {
  constructor(rootTag, ...params) {
    super(rootTag)
    ...
  }

  validate() {
    // Write logic
    this.isValid = true // or false
  }

  error() {
    return !this.isValid ? `Error message` : ''
  }
}

Keywords

seo

FAQs

Package last updated on 09 Feb 2018

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.