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-checker-js

v0.2.1

Published

Check search engine optimize tags with some rules

Downloads

4

Readme

SEO checker js

Check given HTML with rules commit the expect on NodeJS

CircleCI

Installation

npm install seo-checker-js

Getting Start

const checker = require('seo-checker-js');

checker.check('file.html', checker.rule_img_without_alt, console);
  • The first parameter can be file path or Readable stream
  • The second parameter is object (or array of objects) of Rule
  • The last parameter can be file path, Writable stream or console

For example:

const fs = require('fs');
const https = require('https');
const checker = require('seo-checker-js');

// merge all default rules
var default_rules = checker.mergeRules(
  checker.rule_img_without_alt,
  checker.rule_a_without_rel,
  checker.rule_head_has_title_and_meta,
  checker.rule_strong_gt_15,
  checker.rule_h1_gt_1
);

// get webpage content as readable stream
https.get('https://cloud.google.com/', (rs) => {
  // prepare writable stream for output file
  var ws = fs.createWriteStream('result.txt');
  checker.check(rs, default_rules, ws);
});

Rule

The pacakge supports 5 default rules in this pacakge:

  • rule_img_without_alt - shows number of <img> without alt attrubite
  • rule_a_without_rel - shows number of <a> without rel attribute
  • rule_head_has_title_and_meta -
    • shows <head> does not have <title>
    • shows <head> does not have <meta name="descriptions">
    • shows <head> does not have <meta name="keywords">
  • rule_strong_gt_15 - shows html has more than 15 <strong>
  • rule_h1_gt_1 - shows html has more than 1 <h1>

Rule also can be customized, for example:

We want to shows html has more than 5 <strong> tags, and have another rule to check if html has <meta name="robots">

const checker = require('seo-checker-js');

// just clone from default rule for strong tag
let rule_custom1 = checker.rule_strong_gt_15.clone();
// assign new counting number 
rule_custom1.greater(5);
// create a new rule check if html has <meta name="robots">
let rule_custom2 = new checker.Rule('html').included('meta', 'name', 'robots');
// Merge rules
let rules = checker.mergeRules(rule_custom1, rule_custom2);
// Do check output to file
checker.check('input.html', rules, 'output.log');
  • .with() number of elements with given element, shows result if not expected

  • .without() number of elements without given attribute, shows result if not expected

  • .included() element should be has given element, shows message if not expected

  • .excluded() element shouldn't contain given element, shows message if not expected

  • .greater() element shouldn't had more than given number, shows message if not expected

Rule supprted methods all have JSDoc for reference

Output

output will be looks like:

number of img without [alt] expect=0 actual=2
number of a without [rel] expect=0 actual=2
head does not have title
head does not have meta[name="descriptions"]
head does not have meta[name="keywords"]
number of strong greater than 15
number of h1 greater than 1