npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

seo-defects

v1.0.0

Published

Scan an HTML file and show all SEO defects.

Readme

Synopsis

seo-defects let you create rules to detect SEO defects in a HTML, and report accordingly.

Features

  • DSL to create condtions on tags and their attributes.
  • DSL to create rules to detect and report SEO defects.
  • Work on files and streams.

Installation

Install it like a npm module:

npm install seo-defects

Usage

Import seo-defects and get API classes:

var seodd = require('seo-defects');
var Detector = seodd.Detector;
var Rule = seodd.Rule;
var Condition = seodd.Condition;

DSL to create conditions

Use Condition class to create conditions for tags.

Examples:

  • a meta tag has attribute name="description":
Condition().tag('meta').attr('name').is('description')
  • an img tag has no attribute alt:
Condition().tag('img').attr('alt').notExist()
  • a head tag doesn't have a <meta name="descriptions" ...> tag:
Condition().tag('head').notHave(Condition().tag('meta').attr('name').is('descriptions'))

DSL to create rules

A Rule has:

  • a Condition: Detector will count the number of tags matched with this condition.

  • many messages to report, based on the number of matched values. %NUM% is the placeholder that Detector will insert the number of matched values in to reported messages.

Examples:

  • report This HTML without <title> tag if the header tag doesn't have title tag:
Rule().cond(Condition().tag('head').notHave(Condition().tag('title')))
  .greaterThan(0).msg('This HTML without <title> tag');
  • report There are %NUM% <img> tag without alt attribute:
Rule().cond(Condition().tag('img').attr('alt').notExist())
  .greaterThan(0).msg('There are %NUM% <img> tag without alt attribute');

Pre-defined rules:

  SEODefectDetector.imgWithoutAlt
  SEODefectDetector.aWithoutRel
  SEODefectDetector.headerNoTitle
  SEODefectDetector.headerNoMetaDescriptions
  SEODefectDetector.headerNoMetaKeywords
  SEODefectDetector.moreThan15Strong
  SEODefectDetector.moreThan1H1

Detector

Create a Detector with input, output and the list of rules to apply checking. Input and output can be filenames or streams.

Call method detect to perform checking for SEO defects. Register a callback for event complete when the checking is done.

Examples:

var detector = new Detector('input1', process.stdout, [
  Detector.imgWithoutAlt,
  Detector.aWithoutRel,
  Detector.headerNoTitle,
  Detector.headerNoMetaDescription,
  Detector.headerNoMetaKeywords,
  Detector.moreThan15Strong,
  Detector.moreThan1H1,
  Rule().cond(Condition().tag('meta').attr('name').is('robots'))
    .equal(0).msg('This HTML doesnt have meta robots')
]);

detector.detect().on('complete', function() {
  console.log('\ndone');
});

API

Condition Instance Methods

tag()

function Condition#tag(type)
@param type {String} Tag type (eg: head, meta, ...).

This method will create a condition based on the tag provided. Then other methods can be chained to each other.

attr()

function Condition#attr(name)
@param name {String} Attribute name (eg: id, rel, alt, ...).

is(), isNot()

function Condition#is(value)
@param value {String} The value of the attribute specified in the `attr` clause.

function Condition#isNot(value)
@param value {String} The value of the attribute specified in the `attr` clause.

exist(), notExist()

function Condition#exists()

function Condition#notExist()

has(), notHave()

function Condition#has(elem)
@param elem {Condition} The child tag condition that the current tag must have.

function Condition#notHave(elem)
@param elem {Condition} The child tag condition that the current tag must not have.

descend()

function Condition#descend(elem)
@param elem {Condition} Create a new condition whose main tag that Detector counted for is this tag condition.

Rule Instance Methods

cond()

function Rule#cond(condition)
@param condition {Condition} Set the condition for this rule.

This method will create a rule based on the condition provided. Then other methods can be chained to each other.

msg()

function Rule#msg(message)
@param message {String} The message for current comparison.

equal(), lessThan(), greaterThan()

function Rule#equal(value)
@param value {Number} The value to be used in an equal comparison.

function Rule#lessThan(value)
@param value {Number} The value to be used in an less-than comparison.

function Rule#greaterThan(value)
@param value {Number} The value to be used in an greater-than comparison.

Detector Constructor

function Detector(input, output, rules)
@param input {String,Readable} The input source contains the HTML.
@param output {String,Writable} The output.
@param rules {Array} The array of rules.

Detector Instance Methods

detect()

function Detector#detect()

This method performs the checking and then reports to the output stream. When done, it emits the complete event.

License

Copyright (c) 2018 Vu To [email protected]