{"id":47402,"library":"directory-schema-validator","title":"directory-schema-validator","description":"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.","status":"active","version":"1.0.17","language":"javascript","source_language":"en","source_url":"https://github.com/jpoehnelt/directory-schema-validator","tags":["javascript","validation","file","typescript"],"install":[{"cmd":"npm install directory-schema-validator","lang":"bash","label":"npm"},{"cmd":"yarn add directory-schema-validator","lang":"bash","label":"yarn"},{"cmd":"pnpm add directory-schema-validator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"JSON Schema validation engine","package":"ajv","optional":false},{"reason":"File pattern matching for CLI shorthand","package":"glob","optional":true}],"imports":[{"note":"ESM-only package; CommonJS require not supported","wrong":"const Validator = require('directory-schema-validator').Validator","symbol":"Validator","correct":"import { Validator } from 'directory-schema-validator'"},{"note":"TypeScript types included","symbol":"shorthandToJSONSchema","correct":"import { shorthandToJSONSchema } from 'directory-schema-validator'"},{"note":"Named export parse; no default export","wrong":"import { parseDirectory } from 'directory-schema-validator'","symbol":"parse","correct":"import { parse } from 'directory-schema-validator'"}],"quickstart":{"code":"import { Validator, shorthandToJSONSchema } from 'directory-schema-validator';\nimport { parse } from 'directory-schema-validator';\n\n// Define schema using shorthand helper\nconst schema = shorthandToJSONSchema(['README.md', 'src/']);\n\n// Or manually create JSON Schema with custom 'contents' keyword\nconst schema2 = {\n  type: 'object',\n  properties: {\n    files: {\n      properties: {\n        'package.json': {\n          type: 'object',\n          contents: [{ pattern: '\"name\": \"my-project\"' }]\n        }\n      },\n      required: ['package.json']\n    }\n  }\n};\n\n// Parse directory to object (for inspection)\nconst parsed = parse('.');\n\n// Validate directory against schema\nconst validator = new Validator();\nconst valid = validator.validate(schema, '.');\nif (valid) {\n  console.log('Directory structure is valid');\n} else {\n  console.error('Validation errors:', validator.errors);\n}","lang":"typescript","description":"Demonstrates schema creation with shorthand, manual schema with 'contents' keyword, parsing a directory, and parsing directory structure using Validator."},"warnings":[{"fix":"Use dynamic import() or switch to an ESM-compatible project configuration (type: module in package.json).","message":"The package is ESM-only, cannot be used with require() in CommonJS environments.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you use the Validator class from this library and not a generic AJV instance.","message":"The '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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware that symlinks are not included in the parsed tree, which may cause validation to miss expected files.","message":"The parse() function does not follow symlinks; symbolic links inside the directory are skipped.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use glob patterns in CLI and exact relative paths in programmatic calls.","message":"The CLI shorthand command uses glob patterns that differ from the programmatic shorthandToJSONSchema which only accepts exact strings.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.17':21 'ajv':68 'ajv-c':67 'api':61 'cadenc':23 'cli':54,69 'command':55 'content':12,33,38 'current':18 'custom':32 'differ':62 'differenti':26 'directori':2,73 'directory-schema-valid':1 'e.g':66 'extend':15,27 'file':6,11,37,51,84 'focus':71 'general':78 'generat':48 'includ':42 'instanc':80 'irregular':24 'javascript':82 'json':16,28,79 'key':25 'keyword':34 'list':52 'notat':45 'option':10 'pars':58 'pattern':41 'programmat':60 'quick':47 'rather':76 'regex':40 'releas':22 'schema':3,17,29,49 'shorthand':44,57 'similar':64 'stabl':19 'structur':8,74 'support':53 'system':7 'tool':65 'typescript':85 'use':13 'valid':4,5,36,56,75,81,83 'version':20","created_at":"2026-06-07T16:51:20.839623+00:00","updated_at":"2026-06-07T16:51:20.839623+00:00","problems":[{"fix":"Run 'npm install directory-schema-validator' and use correct import syntax: 'directory-schema-validator'.","cause":"Package not installed or imported with wrong path.","error":"Cannot find module 'directory-schema-validator'"},{"fix":"Use ES module imports: 'import { Validator } from 'directory-schema-validator''.","cause":"Using CommonJS require() instead of ESM import.","error":"Validator is not a constructor"},{"fix":"Set 'type': 'module' in your package.json or use .mjs file extension.","cause":"Project is configured as CommonJS but package exports ESM.","error":"Unexpected token 'export'"},{"fix":"Use the Validator class from this library which registers the custom keyword.","cause":"Using a schema with 'contents' keyword outside the Validator from this library (e.g., in standalone AJV).","error":"Schema validation fails with 'keyword content is not defined'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jpoehnelt/directory-schema-validator#readme","github":"https://github.com/jpoehnelt/directory-schema-validator","docs":null,"changelog":null,"pypi":null,"npm":"directory-schema-validator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}