Registry / testing / schema-validator

schema-validator

JSON →
library3.3.1jsnpmunverified

Barebones JSON schema validation library for JavaScript, Node, and Express. Version 3.3.1 provides built-in checks for required fields, default values, type matching (via Object.prototype.toString), length constraints (min/max), and regex tests. Supports nested object schemas and Express middleware integration. Compared to libraries like Joi or Ajv, this is minimal and no longer actively developed.

npm install schema-validator
INSTALL
IMPORT
SIG · SCHEMA-VALIDATOR
S
schema-validator
testingjavascriptv3.3.1
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
const Validator = require('schema-validator');
import Validator from 'schema-validator';
Package is CJS-only; no ESM support. Use require().
new Validator(schema)
const validator = new Validator(schema);
const validator = Validator(schema);
Validator must be instantiated with new.
middleware
const validator = new Validator(schema); app.use(validator.middleware());
new Validator(schema, true)
Second constructor argument (true) enables Express middleware mode; .middleware() method also available.

Defines a schema with username and age fields, validates input, and logs result.

const Validator = require('schema-validator'); const schema = { username: { type: String, required: true, length: { min: 3, max: 36 }, test: /^[a-z0-9]+$/gi }, age: { type: Number, required: false, default: 18 } }; const validator = new Validator(schema); const result = validator.check({ username: 'john_doe' }); console.log(result); // { errors: [], passed: true, ... }
Debug
Known issues
maintenancePackage is no longer actively maintained; no updates since 2015.
fix
Consider migrating to a maintained alternative like Ajv or Joi.
affects: >=0.0.0
gotchaType checks use Object.prototype.toString, so type names must be constructors (String, Number, Boolean) not strings.
fix
Use String, Number, Boolean, etc. as type values.
affects: >=0.0.0
gotchaDefault values are applied even if the field is not required, which may be unexpected.
fix
Explicitly set required: false if you don't want defaults to be applied.
affects: >=0.0.0
gotchaNested schemas are experimental and may not work correctly in all cases.
fix
Test nested schemas thoroughly; consider flattening the schema.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Validator is not a constructor
Using import statement or calling Validator without 'new'.
fix
Use const Validator = require('schema-validator'); and new Validator(schema);
TypeError: validator.check is not a function
Validator not instantiated; calling check on the class, not instance.
fix
Create an instance: const validator = new Validator(schema); then validator.check(data);
Error: Unknown implementation: type
Using lowercase strings like 'string' instead of constructor String.
fix
Use String, Number, Boolean, etc. as type values.
Upgrade
Version history
3.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
3 hits · last 30 days
node
2
Amazon
1
Resources
schema-validator — npm install schema-validator · libregistry