Registry / security / schema-inspector

schema-inspector

JSON →
library2.1.0jsnpmunverified

Schema-Inspector is a JavaScript library for sanitizing and validating JS objects, supporting both synchronous and asynchronous operations. The current stable version is 2.1.0, released with security fixes for email validation regex in 2.0.0 and 2.0.3. It is designed for client-side and server-side use, offering a simple schema definition format distinct from JSON Schema, with built-in sanitization rules like trimming and case conversion. It is maintained with an active GitHub repository and CI workflows.

npm install schema-inspector
INSTALL
IMPORT
SIG · SCHEMA-INSPECTOR
S
schema-inspector
securityjavascriptv2.1.0
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.

sanitize
import { sanitize } from 'schema-inspector'
const sanitize = require('schema-inspector').sanitize
Library supports both ESM and CJS, but named exports are available.
validate
import { validate } from 'schema-inspector'
import schemaInspector from 'schema-inspector'; schemaInspector.validate(...)
Default export is an object containing both methods; named exports are available since v2.
SchemaInspector
import SchemaInspector from 'schema-inspector'
const SchemaInspector = require('schema-inspector').default
Default import gives the main inspector object with sanitize and validate methods.

Shows how to sanitize (trim, title-case, lowercase) and validate data using schema-inspector.

import { sanitize, validate } from 'schema-inspector'; const data = { name: ' John Doe ', email: 'invalid' }; // Sanitization schema const sanitization = { type: 'object', properties: { name: { type: 'string', rules: ['trim', 'title'] }, email: { type: 'string', rules: ['trim', 'lower'] }, }, }; sanitize(sanitization, data); console.log('Sanitized:', data); // => { name: 'John Doe', email: 'invalid' } // Validation schema const validation = { type: 'object', properties: { name: { type: 'string', minLength: 1 }, email: { type: 'string', pattern: 'email' }, }, }; const result = validate(validation, data); if (!result.valid) { console.log(result.format()); } // => Property @.email: must match [email], but is equal to "invalid"
Debug
Known issues
breakingVersion 2.0.0 changed the email regex, potentially rejecting previously accepted emails. Test your data.
fix
Use custom validation function for email if you need the old behavior.
affects: >=2.0.0
gotchaSanitization mutates the data object in place; pass a copy to preserve original.
fix
Clone the data before sanitizing: const sanitizedData = JSON.parse(JSON.stringify(originalData));
affects: >=1.0.0
deprecatedBower support is deprecated and will be removed in 3.0.0. Use npm or CDN instead.
fix
Switch to npm or import via script tag from CDN.
affects: >=2.0.0
gotchaThe library is not compatible with JSON Schema. Use a different library if you need JSON Schema.
fix
Use ajv, joi, or zod if you need JSON Schema compatibility.
affects: >=1.0.0
breakingVersion 2.0.3 changed the email regex again; validation behavior may differ from 2.0.0-2.0.2.
fix
Test email validation thoroughly and consider using custom pattern if needed.
affects: >=2.0.3
Errors
Common errors & fixes
TypeError: Cannot read property 'type' of undefined
Schema definition is missing or malformed.
fix
Ensure sanitization/validation schema has proper structure with 'type' and 'properties'.
Error: Unknown rule 'trim'
Typo in rule name or using a rule not available in the library.
fix
Check documentation for supported rules: 'trim', 'title', 'lower', 'upper', etc.
Error: Invalid pattern 'email'
Using 'email' as pattern without specifying custom regex.
fix
Use pattern: 'email' or provide a custom regex string.
Error: Cannot find module 'schema-inspector'
Missing npm install or wrong import path.
fix
Run 'npm install schema-inspector' and use correct import: 'schema-inspector' (not 'schema/Inspector' or similar).
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
Resources
schema-inspector — npm install schema-inspector · libregistry