Registry / testing / directory-schema-validator

directory-schema-validator

JSON →
library1.0.17jsnpmunverified

Validate file system structure and optionally file contents using an extended JSON Schema. Current stable version: 1.0.17. Release cadence: irregular. Key differentiators: extends JSON Schema with a custom 'contents' keyword to validate file content against regex patterns; includes a shorthand notation to quickly generate schemas from file lists; supports CLI commands (validate, shorthand, parse) and programmatic API. Different from similar tools (e.g., ajv-cli) by focusing on directory structure validation rather than general JSON instance validation.

npm install directory-schema-validator
INSTALL
IMPORT
SIG · DIRECTORY-SCHEMA-V
D
directory-schema-validator
testingjavascriptv1.0.17
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Validator
import { Validator } from 'directory-schema-validator'
const Validator = require('directory-schema-validator').Validator
ESM-only package; CommonJS require not supported
shorthandToJSONSchema
import { shorthandToJSONSchema } from 'directory-schema-validator'
TypeScript types included
parse
import { parse } from 'directory-schema-validator'
import { parseDirectory } from 'directory-schema-validator'
Named export parse; no default export

Demonstrates schema creation with shorthand, manual schema with 'contents' keyword, parsing a directory, and parsing directory structure using Validator.

import { Validator, shorthandToJSONSchema } from 'directory-schema-validator'; import { parse } from 'directory-schema-validator'; // Define schema using shorthand helper const schema = shorthandToJSONSchema(['README.md', 'src/']); // Or manually create JSON Schema with custom 'contents' keyword const schema2 = { type: 'object', properties: { files: { properties: { 'package.json': { type: 'object', contents: [{ pattern: '"name": "my-project"' }] } }, required: ['package.json'] } } }; // Parse directory to object (for inspection) const parsed = parse('.'); // Validate directory against schema const validator = new Validator(); const valid = validator.validate(schema, '.'); if (valid) { console.log('Directory structure is valid'); } else { console.error('Validation errors:', validator.errors); }
Debug
Known issues
gotchaThe package is ESM-only, cannot be used with require() in CommonJS environments.
fix
Use dynamic import() or switch to an ESM-compatible project configuration (type: module in package.json).
affects: >=1.0.0
gotchaThe 'contents' keyword is a custom AJV keyword added by this library; it only works inside the schema passed to Validator. Regular JSON Schema validators will reject it.
fix
Ensure you use the Validator class from this library and not a generic AJV instance.
affects: >=1.0.0
gotchaThe parse() function does not follow symlinks; symbolic links inside the directory are skipped.
fix
Be aware that symlinks are not included in the parsed tree, which may cause validation to miss expected files.
affects: >=1.0.0
deprecatedThe CLI shorthand command uses glob patterns that differ from the programmatic shorthandToJSONSchema which only accepts exact strings.
fix
Use glob patterns in CLI and exact relative paths in programmatic calls.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'directory-schema-validator'
Package not installed or imported with wrong path.
fix
Run 'npm install directory-schema-validator' and use correct import syntax: 'directory-schema-validator'.
Validator is not a constructor
Using CommonJS require() instead of ESM import.
fix
Use ES module imports: 'import { Validator } from 'directory-schema-validator''.
Unexpected token 'export'
Project is configured as CommonJS but package exports ESM.
fix
Set 'type': 'module' in your package.json or use .mjs file extension.
Schema validation fails with 'keyword content is not defined'
Using a schema with 'contents' keyword outside the Validator from this library (e.g., in standalone AJV).
fix
Use the Validator class from this library which registers the custom keyword.
Upgrade
Version history
1.0.17latest on npm
Audit
Dependencies
ajvrequiredJSON Schema validation engine
globoptionalFile pattern matching for CLI shorthand
Agent activity
9 hits · last 30 days
node
8
Bingbot
1
Resources