Registry / testing / form-schema-validation

form-schema-validation

JSON →
library2.0.1jsnpmunverified

A schema-based object validation library for JavaScript, currently at version 2.0.1. It provides synchronous and asynchronous (Promise-based) validation, supports custom types, one-of type validation, custom validators, and nested schema definitions. Features include validating required/optional fields, object structure, keys, and custom error messages. It is commonly used for form validation but can validate any object. The library offers a simple API with a Schema class and validate method, and allows control over key validation via the validateKeys flag. It is maintained intermittently with low release cadence.

npm install form-schema-validation
INSTALL
IMPORT
SIG · FORM-SCHEMA-VALIDA
F
form-schema-validation
testingjavascriptv2.0.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.

Schema
✓ import Schema from 'form-schema-validation'
✗ const Schema = require('form-schema-validation')
Default export. Works with ES modules and CommonJS via bundlers.
CustomValidator type
✓ import type { CustomValidator } from 'form-schema-validation'
✗ import { CustomValidator } from 'form-schema-validation'
CustomValidator is a TypeScript type, not a runtime value. Use import type for TypeScript.
SchemaOptions type (if available)
✓ import type { SchemaOptions } from 'form-schema-validation'
Check documentation for exported types; not all types may be exported.

Shows basic synchronous validation: define schema with type and required constraints, validate an object, and check for errors.

import Schema from 'form-schema-validation'; const schema = new Schema({ name: { type: String, required: true }, age: { type: Number, required: true, min: 0 }, }); const model = { name: 'Alice', age: 30 }; const errors = schema.validate(model); if (Object.keys(errors).length === 0) { console.log('Valid!'); } else { console.log('Errors:', errors); }
Debug
Known issues
gotchaIf the model object is null or undefined, validate() may throw an error.
fix
Ensure the model argument is an object before calling validate().
affects: >=1.0.0
gotchaWhen using async validators, validate() returns a Promise. Use then/catch or async/await.
fix
const errors = await schema.validate(model);
affects: >=2.0.0
gotchaThe validateKeys option (set in constructor) determines whether keys not in schema cause errors. Default is true, meaning extra keys will produce errors.
fix
Set { validateKeys: false } in constructor options to allow extra keys.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read property 'type' of undefined
Passing an undefined or null field in schema definition that is accessed during validation.
fix
Ensure all schema fields are defined or use optional chaining.
Unhandled promise rejection: ValidationError: async test error
An async validator threw an error or returned a rejected promise.
fix
Handle the promise returned by validate() and catch errors.
Expected string but got number
Type mismatch: field type in schema is String but model value is a number.
fix
Coerce or convert the model value to match the schema type.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
form-schema-validation — npm install form-schema-validation · libregistry