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

@html-validate/plugin-utils

v4.3.0

Published

Plugin utilities and helpers for writing plugins to HTML-Validate

Readme

@html-validate/plugin-utils`

Plugin utilities and helpers for writing plugins to HTML-Validate

API

import { Source } from "html-validate";

export interface Position {
  column: number;
  line: number;
}

export function positionFromOffset(text: string, offset: number): [line: number, column: number];

export function positionToOffset(position: Position, data: string): number;

export class TemplateExtractor {
  static fromString(source: string, filename?: string): TemplateExtractor;
  extractObjectProperty(key: string): Source[];
}

Usage

TemplateExtractor

Extracts HTML-snippets from Javascript based files.

/* javascript with HTML in the "template" property */
const sourceCode = `
  export default {
    template: "<p>lorem ipsum</i>",
  }
`;

/* extract HTML snippets */
const templateExtractor = TemplateExtractor.fromString(sourceCode);
const snippets = templateExtractor.extractObjectProperty("template");

Typically used in a transformation plugin to but it could also be validated directly:

for (const snippet of snippets) {
  const result = htmlvalidate.validateSource(snippet);
  console.log(result);
}

Test utils

normalizeReport

Normalizes a report so it is suitable for unittesting:

  • filePath is normalized to a path relative to rootDir.
  • fixable{Error,Warning}Count is reset to 0.

The version option should be the version of html-validate the original report was generated. The returned report is updated to the latest supported version.

Syntax

import { type Result } from "html-validate";

function normalizeReport(
  report: Report,
  options: {
    rootDir: string;
    version: string;
  },
): Report;

Parameters

  • report the original report.
  • options.rootDir - path to rewrite report paths to be relative to.
  • options.version - the version of html-validate that was used to generate the report.

Return value

A normalized copy of the report.

runCli

Run the html-validate CLI, typically for an integration test.

The CLI is run in a child process and the report is read from a separate file descriptor so it is not mixed with stdout.

Syntax

import { type Report } from "html-validate";

function runCli(options: {
  cliPath: string;
  cwd: string;
  args: string[];
  formatter: "json";
}): Promise<{
  exitCode: number;
  stdout: string;
  stderr: string;
  report: string;
  json(): Report;
}>;

Parameters

  • options.cliPath - resolved path to the html-validate binary (e.g. bin/html-validate.mjs).
  • options.cwd - working directory to run the CLI in.
  • options.args - additional CLI arguments, e.g. the files to validate.
  • options.formatter - formatter used for the report, currently only "json" is supported.

Return value

A promise resolving to an object with:

  • exitCode - the exit code of the process.
  • stdout - captured standard output.
  • stderr - captured standard error.
  • report - the raw report as a string.
  • json() - parses report and returns it as an object.

The promise is rejected if the process fails to start or is terminated by a signal.

Example

import path from "node:path";
import { runCli } from "@html-validate/plugin-utils/test-utils";

const pkg = require.resolve("html-validate/package.json");
const cliPath = path.join(path.dirname(pkg), "bin/html-validate.mjs");

const result = await runCli({
  cliPath,
  cwd: "path/to/project",
  args: ["src/index.html"],
  formatter: "json",
});
expect(result.exitCode).toBe(0);
expect(result.json().valid).toBe(true);