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

simple-website-audit

v1.2.0

Published

The simple package API to check the health of your site.

Downloads

2

Readme

Simple Website Audit

The simple package API to check the health of your site.

Features

  • HTTP status code check.
  • Ignore HTTP codes for filtering results.
  • Search regex in your HTML results (Did you miss a <?php in your code?).
  • Full redirect path, specifing code and URL where is redirecting through.
  • AMP Audit validation.
  • W3C Audit validation.
  • Set all the URLs you want to add, set URLs from a sitemap.xml
  • Mocking userAgent if you have a mobile version working in your SSR.
  • Simple API and chaining methods.
  • Full report.

Requisites

NodeJS > 10 LTS

Installing

npm install simple-website-audit

Usage

const simpleWebsiteAudit = require("simple-website-audit");

const auditInstance = simpleWebsiteAudit();

auditInstance
  .setUrls(["https://www.google.com"])
  .make()
  .then(report => console.log(report))
  .catch(error => console.error(error));

The Audit Instance

  • audits: Specify all the audit instances that will execute:
    • redirect (boolean, default false): This audit will include in the report all the redirect path that a URL made, i.e. if the URL has a redirect 301 or 302 the redirect path will show you which code was used.
    • regex (Array<string | RegExp>, default []): This audit will look for all the coincidences in the HTML code for all the values in the array. If it found a coincidence, it will show you the code fragment in that coincidende.
    • w3c (boolean, default false): This audit will validate your HTML code with the W3C validator, it will show you all the errors and warnings from your code.
    • amp (boolean, default false): This will run the AMP validation for your HTML code, it will show you all the errors found.
  • configuration: Here are some values to use in the audits or in the HTTP request:
    • offsetRegex (number, default 200): If you are using the regex audit, this configuration specifies how many characters from the code will be used to show you the fragment, i.e. if you set to 100, once the regex coincidence is found, it will show you a fragment from the 100 chars before the coincidence to the 100 chars after the coincidence.
    • maxTime (number, default 5000): Miliseconds that the HTTP request will wait for a response before drop it.
    • maxRedirects (number, default 5): Number of redirects that the HTTP request will consider before it will treat as a infinite server redirect error.
    • resolveWithFullResponse (number, default true): This is used by the request to build the redirect path.
    • followAllRedirects (number, default true): This is also used by the request to build the redirect path.
    • ignoreHttpCodes (Array, default []): You can specify in this configuration which HTTP codes the audit will ignore, the custom audits will not run on these URLs and they will not be included in the report.
    • sitemapUrl (string, default ""): Specifies the URL of the sitemap the the setUrlsFromSitemap method will use to look for URLs.
    • userAgent (string, default ""): Specifies the userAgent that the request will use in its headers, you can also set this value with setUserAgent method, this is useful if you render a different HTML code for a mobile userAgent.
  • urls: This is the store for the urls that the instance will use for the audit.
  • report: This is the store for the report that is generated by the make method.

API:

setAudits

Set the audits that the instance will execute. The params will merge with the current audits configuration. Returns the auditInstance

instance.setAudits({
  amp: true,
  w3c: true,
  regex: ["<?php"],
  redirect: false
});

setUrls

Set the urls that the instance will look for. The params will replace with the current urls in the instance. If you set a URL that doesn't specify http or https it will be transformed to https. Returns the auditInstance

//  It can be a string
instance.setUrls("https://www.google.com");

//  Or ot can be an array
instance.setUrls(["https://www.google.com", "https://www.npmjs.com"]);

// If you don't specify http or https in the URL it will be transformed to https
instance.setUrls("www.google.com"); // Will look for http://www.google.com

addUrls

Same as setUrls but this will add the URLs to the instance instead of replace it. Returns the auditInstance

//  Set URLs
instance.setUrls("https://www.google.com");

//  Add some more to audit
instance.addUrls(["https://www.microsoft.com", "https://www.npmjs.com"]);

setUserAgent

Sets the userAgent to use in all the requests of the instance. Returns the auditInstance

//  Make the requests as an iPhone
instance.setUserAgent(
  "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
);

setConfiguration

Sets the configuration of the instance. The params will merge with the current configuration. Returns the auditInstance

instance.setConfiguration({
  sitemapUrl: "https://mysite.com/sitemap.xml",
  maxRedirects: 3
});

setUrlsFromSitemap

Sets the URLs from the sitemap specified in the configuration, the URLs will replace the current URLs in the instance. This method is async and return the auditInstance

//  Inside an async function
await instance.setUrlsFromSitemap();

make

Execute the audit, this method returns the audit report and also stores that result inside the auditInstance.

const report = await instance.make();

Chaining API

You can also use it as a chainable API

const report = await instance
  .setUrls("https://www.mysite.com")
  .setAudits({ redirect: true, w3c: true })
  .make();

Test

npm test

Contributing

Contributions are welcome, please free to send a PR or open new issues. You can also contact me at @mikz439