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

directory-validator

v1.5.4

Published

CLI Tool to validate directory structures.

Readme

directory-validator

Package Version

CLI Tool to validate directory structures. If you want to have control over what files/dirs a directory can have then this can be useful.

Installation

$ npm install directory-validator

Usage

Generate a configuration file .directoryvalidator.json to start with:

$ directory-validator --init

Run the validator on the current directory:

$ directory-validator .

The tool will evaluate the rules provided by the configuration file against the current directory and output errors if any.

Configuration File

{
  "ignoreFiles": [".gitignore"],
  "ignoreDirs": ["node_modules", ".git"],
  "commonRules": {
    "rule_indexfile": {
      "type": "file",
      "name": "index.js"
    }
  },
  "rules": [
    {
      "type": "file",
      "name": "package.json"
    },
    {
      "type": "common",
      "key": "rule_indexfile"
    },
    {
      "type": "directory",
      "name": "src",
      "isOptional": true,
      "rules": [
        {
          "type": "common",
          "key": "rule_indexfile"
        }
      ]
    }
  ]
}

In this example:

  • We ignore the file .gitignore and both .node_modules and .git directories from being analized
  • We want to have one file name package.json and one file named index.js
  • We want one directory src to have one file named index.js. Since it's optional, if the directory does not exist we ignore the rule, but if it does then it must only have one file index.js

ignoreFiles:

A string or glob pattern. For example:

[
  "package.json",
  "**/*.test.js",
  ".*" // files starting with "."
]

ignoreDirs:

A string or glob pattern. For example:

[
  "node_modules",
  "src/**/tests",
  ".*" // dirs starting with "."
]

commonRules:

Define File, Directory and Common rules that can be reused in rules

{
  // key must start with "rule_"
  // Examples:
  "rule_indexfile": {
    "type": "file",
    "name": "index.js"
  },
  "rule_anotherrule": {
    "type": "directory",
    "name": "images",
    "rules": [
      {
        "type": "file",
        "name": "logo.png"
      }
    ]
  }
}

rules:

Can contain File, Directory and Common Rules

File Rule

{
  // Required
  "type": "file",

  // Required
  // can be string or RegExp
  // if RegExp then it has to start and end with /
  // if string then it can contain one
  // special case: [camelCase], [UPPERCASE], [dash-case], [snake_case], *
  // Examples:
  "name": "package.json",
  "name": "[snake_case]",
  "name": "[camelCase].js",
  "name": ".[UPPERCASE]",
  "name": ".[dash-case].jpg",
  "name": "*.png",
  "name": "/index.(js|ts)/",

  // Optional
  // default: null
  // can be string or RegExp (do not include the dot)
  // if RegExp then it has to start and end with /
  // Examples:
  "extension": "js",
  "extension": "png",
  "extension": "/(png|jpg|gif)/",

  // Optional
  // default: false
  // Whether the file can be included
  "isOptional": false
}

Directory Rule

{
  // Required
  "type": "directory",

  // Required
  // Same options as file names
  // Examples:
  "name": "src",
  "name": "important-[dash-case]",

  // Optional
  // default: false
  // Whether the directory can be included
  "isOptional": false,

  // Optional
  // default: false
  // Whether the directory can be recursive
  // Adds the ability to check directory rules recursively
  "isRecursive": false,

  // Optional
  // An array containing file and directory rules
  // If empty or omitted then we don't validate dir content
  "rules": []
}

Common Rule

{
  // Required
  "type": "common",

  // Required
  // must match a key property inside "commonRules"
  // examples:
  "key": "rule_indexfile",
  "key": "rule_test2",
  "key": "rule_whatever",

  // Optional
  // default: false
  // Whether the directory can be included
  "isOptional": false
}

Notes

  • When you run $ directory-validator ./ it will look for a .directoryvalidator.json file in the current directory, if it doesn't find one, it will try to look for one in the upper directory and so on until the home directory is reached. If no file is found then no rules are applied.

  • Rules are inclusive, meaning that if multiple rules match the same files/dirs, they pass.

    • For example, the rules { "name": "index.js", "type": "file" } and { "name": "[camelCase].js", "type": "file" }, will match a file index.js so they both pass.