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 🙏

© 2024 – Pkg Stats / Ryan Hefner

seo-detector-demo

v1.0.2

Published

<h1 align="center">seo-detect</h1> <h5 align="center">A Node.js package scan a HTML content and show all of SEO defects.</h5>

Downloads

7

Readme

const {
 detector,
 ReaderType,
 WriteType,
 DefaultRule,
 SupportedRuleEngine
} = require('seo-detector-demo');

var fileOption = {
  input: {
    type : ReaderType.FILE,
    path: __dirname + '/exampleInput.html'
  },
  output: {
    type: WriteType.FILE,
    path: __dirname + '/exampleOutput.html'
  }
};

var ruleOptions = [];
// Filter default rule with index.
for (var i in DefaultRule) {
  var index = Object.keys(DefaultRule).indexOf(i);
  if (index >= 0) {
    ruleOptions.push({name: i});
  }
}

// customized rule with supported rule engine
ruleOptions.push({name: 'customized1',
                  engine: SupportedRuleEngine.tagWithoutAttrCount,
                  param: {root: '', tag:'foo', attr:'123'}});
ruleOptions.push({name: 'customized2',
                  engine: SupportedRuleEngine.tagExistence,
                  param: {root: '', tag:'foo'}});
ruleOptions.push({name: 'customized3',
                  engine: SupportedRuleEngine.tagExistenceWithAttrValue,
                  param: {root: '', tag:'foo', attr:'name', value:'seo'}});
ruleOptions.push({name: 'customized4',
                  engine: SupportedRuleEngine.tagLimitCount,
                  param: {root: '', tag:'foo', limit:1}});

// customized rule with customized rule engine
ruleOptions.push({name: 'customizedRuleEngine', ruleFn : $ => {
    var errors = '';
    if (!$('aaa').length) {
      errors = 'This html does not contains <aaa> tag!';
    }
   return errors;
}});

var seoDetector = new detector(fileOption.input, fileOption.output, ruleOptions);

seoDetector
  .detect()
  .then(async() => await seoDetector.writeResult())
  .catch(err => console.error(err));

Requirements

Node.js 8.9.1 or greater

Installation

npm install seo-detector-demo

Predefined Rules

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

Supported rule format

ruleOption = {
    name: 'defaultRuleName', // for default rule usage.
    engine: 'supportedRuleEngine', // for customized rule usage
    param: {
        root: 'head',
        tag: 'meta',
        attr: 'name',
        value: 'descriptions',
        limit: 0;
    },
    ruleFn: $ => {} // for new rule engine usage.
}

Default rule option

const { DefaultRule } = require('seo-detector-demo');

/** Default rule name
 * imgWithoutAlt,
 * aWithoutRel,
 * headerNoTitle,
 * headerNoMetaDescription,
 * headerNoMetaKeywords,
 * moreThan15Strong,
 * moreThan1H1
 */

var ruleOptions = [];
for (var i in DefaultRule) {
  var index = Object.keys(DefaultRule).indexOf(i);
  if (index >= 0) {
    ruleOptions.push({name: i});
  }
}

Customized rule option with default rule engine

const { SupportedRuleEngine } = require('seo-detector-demo');

/** Default rule engine name
 * tagWithoutAttrCount,
 * tagExistence,
 * tagExistenceWithAttrValue,
 * tagLimitCount
 */

var ruleOptions = [];
ruleOptions.push({name: 'customized1',
                  engine: SupportedRuleEngine.tagWithoutAttrCount,
                  param: {root: '', tag:'foo', attr:'123'}});
ruleOptions.push({name: 'customized2',
                  engine: SupportedRuleEngine.tagExistence,
                  param: {root: '', tag:'foo'}});
ruleOptions.push({name: 'customized3',
                  engine: SupportedRuleEngine.tagExistenceWithAttrValue,
                  param: {root: '', tag:'foo', attr:'name', value:'seo'}});
ruleOptions.push({name: 'customized4',
                  engine: SupportedRuleEngine.tagLimitCount,
                  param: {root: '', tag:'foo', limit:1}});

Customized rule option with customized rule engine

var ruleOptions = [];
ruleOptions.push({name: 'customizedRuleEngine', ruleFn : $ => {
    var errors = '';
    if (!$('aaa').length) {
      errors = 'This html does not contains <aaa> tag!';
    }
   return errors;
}});

Reader

There are 2 reader types: FILE and STREAM.

const { ReaderType } = require('seo-detector-demo');

var inputOption = {
    type : ReaderType.FILE,
    path: __dirname + '/exampleInput.html'
};

Writer

There are 3 writer types: FILE, STREAM, CONSOLE.

const { WriterType } = require('seo-detector-demo');

var inputOption = {
    type : Writer.FILE,
    path: __dirname + '/exampleOutput.html'
};

Detector

constructor(inputOption, outputOption, ruleOptions)

User can choose which pre-defined rule will be used through ruleOptions

const { detector } = require('seo-detector-demo');
const seoDetector = new detector(inputOption, outputOption, ruleOptions);
// skip pre-defined rules if it doesn't add into ruleOptions

Detect && WriteResult

seoDetector
  .detect()
  .then(async () => await seoDetector.writeResult())
  .catch(err => console.error(err));

Unit testing

Run npm test in the seo-detector-demo.