Schema handling utilities for validating, processing, and normalizing objects against defined schemas. Version 4.7.3 provides a framework with support for strict and shorthand schema definitions (including mongoose-style constructors), validation via schema.validate() and normalization via schema.normalize(), with type coercion. It is actively maintained, ships TypeScript definitions, and requires Node >= 16. It offers flexible schema definitions, both strict and shorthand formats, and detailed ValidationError objects with field-level error codes. Key differentiators include deep normalization with type coercion and a rich error reporting structure.
npm install common-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a schema with nested objects, arrays, and required fields, then validates and normalizes data with type coercion.
Replace 'buffer' with 'blob' in your schema definitions.
Access error.data.fieldErrors instead of error.fieldErrors.
Use `Number` or `'number'` instead of `{ type: 'number' }`.Use a clone: `const result = schema.normalize(JSON.parse(JSON.stringify(input)))`.
Use `schema.validate()` inside a try-catch if you need error details.
Use named import: `import { createSchema } from 'common-schema'`Install xerror: `npm install xerror`
Replace 'buffer' with 'blob' or a custom validator.