SEO checker js
Check given HTML with rules commit the expect on NodeJS
Installation
npm install seo-checker-js
Getting Start
const checker = ; checker;
- 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 = ;const https = ;const checker = ; // merge all default rulesvar default_rules = checker; // get webpage content as readable streamhttps;
Rule
The pacakge supports 5 default rules in this pacakge:
rule_img_without_alt
- shows number of<img>
withoutalt
attrubiterule_a_without_rel
- shows number of<a>
withoutrel
attributerule_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">
- shows
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 = ; // just clone from default rule for strong taglet rule_custom1 = checkerrule_strong_gt_15;// assign new counting number rule_custom1;// create a new rule check if html has <meta name="robots">let rule_custom2 = 'html';// Merge ruleslet rules = checker;// Do check output to filechecker;
-
.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