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

@anotherdat/schema-validator

v0.2.0

Published

Validate a destination folder against a file-structure schema, with pluggable per-file validators (css, with more kinds to come)

Downloads

230

Readme

@anotherdat/schema-validator

Validate a whole destination folder against a file-structure schema, with pluggable per-file validators for the files inside it.

  • validate(folder, schema, options) — the main validator. Checks that a destination folder (e.g. a theme like gob) matches a file-structure schema: required/optional files, and per-file content validators.
  • validators — the registry of per-file validators, keyed by kind, for validating a single file's content on its own.

| kind | validates | | ---------------- | ---------------------------------------------------- | | file-structure | a folder's tree (required/optional files + validators) | | css | CSS custom-property declarations (flat or per-block) |

More per-file kinds (json, svg, ...) are planned.

Install

npm install @anotherdat/schema-validator

Usage

Validate a whole folder

const fs = require('fs');
const path = require('path');
const { validate } = require('@anotherdat/schema-validator');

// The schema can be an object, a JSON string, or a Buffer — pass whatever you
// have (a file you read, or a response you fetched).
const schema = fs.readFileSync('schema/schema.json');
// const schema = await fetch('https://host/schema.json').then((r) => r.text());

// Resolves on success; throws an Error listing every problem on failure.
await validate(path.join(__dirname, 'gob'), schema, { schemaDir: 'schema' });

Validate a single file directly

const { validators } = require('@anotherdat/schema-validator');

// validators.<kind>.validate(content, schema, options)
validators.css.validate(cssSource, colorsSchema, { at: 'colors.css' });

The file-structure schema

{
  "kind": "file-structure",
  "allowExtra": true,
  "schema": {
    "images/logo.svg": "required",
    "images/hero.png": "optional",
    "styles/colors.css": { "validator": "styles/colors.css.schema" },
    "styles/custom.css": "required"
  }
}

Each entry maps a folder-relative path to a rule:

  • "required" — the file must exist.
  • "optional" — allowed, not mandatory.
  • { "required": false?, "validator": <ref> } — defaults to required; when the file is present, validator runs against its contents. Set "required": false to make it optional. (Folders aren't listed — they're implied by file paths.)

allowExtra (default true) — when false, any file in the folder not listed in schema is also an error.

How validator references are resolved

A rule's validator is either an inline spec object or a string reference. References are resolved, in order:

  1. options.resolveValidator(ref) — an (async) function returning the spec (object or JSON string). Use this for fetched/remote schemas.
  2. options.schemaDir — read path.join(schemaDir, ref) from disk.
// inline — no resolution needed
{ "styles/colors.css": { "validator": { "kind": "css", "blocks": [/* ... */] } } }

// reference resolved from disk
await validate(folder, schema, { schemaDir: 'schema' });

// reference resolved however you like (e.g. fetched)
await validate(folder, schema, {
  resolveValidator: (ref) => fetch(`https://host/${ref}`).then((r) => r.text()),
});

On failure validate throws a single Error listing every problem found (missing files, per-file validator failures, unexpected files) — a whole-folder report rather than fail-on-first.

options.at overrides the label that prefixes error messages (defaults to the folder path).

CSS validator spec shapes

Block mode — the file must contain exactly these blocks, in order (same selectors), each declaring its required custom properties:

{
  "kind": "css",
  "blocks": [
    { "name": "palette", "selector": ":root", "requiredVariables": ["--c-primary"] },
    { "name": "theme", "selector": ".dark-mode", "requiredVariables": ["--c-bg"] }
  ],
  "allowExtraVariables": false
}

allowExtraVariables is optional; set it to false to reject variables not listed in requiredVariables.

Flat mode — check required variables across the whole file, ignoring blocks:

{ "kind": "css", "requiredVariables": ["--c-primary", "--c-bg"] }

Adding a per-file validator kind

  1. Create validators/<kind>.js exporting { kind, validate(content, schema, options) }. validate parses schema (object or JSON string) and throws an Error (message prefixed with options.at) on the first problem.
  2. Register it in the validators map in index.js.
  3. Reference it from a file-structure schema via "validator", with a spec whose "kind" matches.
  4. Add a validators/<kind>.test.js alongside it.

Development

npm install
npm test