Registry / testing / faster-schema

faster-schema

JSON →
library2.1.0jsnpmunverified

FasterSchema is an isomorphic JavaScript object schema validation library (v2.1.0) designed as a faster alternative to SimpleSchema with a similar API. It validates objects, cleans data (type conversion, property removal, automatic values), and provides a customizable error message system with localization support. Compared to SimpleSchema, it is approximately 20x faster for validation and 50x faster for cleaning complex objects, but does not support MongoDB modifier validation. Active development, frequent releases, hundreds of tests.

npm install faster-schema
INSTALL
IMPORT
SIG · FASTER-SCHEMA
F
faster-schema
testingjavascriptv2.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.

FasterSchema
import FasterSchema from 'faster-schema'
const FasterSchema = require('faster-schema')
Default import is ESM-only in v2. For CommonJS, use dynamic import.
SimpleSchemaValidationError
import { SimpleSchemaValidationError } from 'faster-schema'
import SimpleSchemaValidationError from 'faster-schema'
Named export for the error class; not the default.
SchemaDefinition
import type { SchemaDefinition } from 'faster-schema'
Type import for TypeScript; requires 'import type' syntax.

Demonstrates schema definition, validation with error handling, and object cleaning with FasterSchema.

import FasterSchema from 'faster-schema'; const schema = new FasterSchema({ name: String, age: { type: Number, min: 0, max: 150 }, email: { type: String, regEx: /^[^@]+@[^@]+\.[^@]+$/ }, }); const obj = { name: 'Alice', age: 30, email: 'alice@example.com' }; // Validate and throw on error try { schema.validate(obj); console.log('Valid!'); } catch (err) { console.error(err.message); } // Clean object (auto-convert types, remove unknown keys, add defaults) const cleaned = schema.clean(obj); console.log(cleaned);
Debug
Known issues
breakingFasterSchema v2 requires ESM imports. CommonJS require() will fail.
fix
Use import syntax or switch to dynamic import: const FasterSchema = await import('faster-schema')
affects: >=2.0.0
gotchaThe regEx rule does not support passing options like 'i' or 'g'. If you need flags, create a RegExp object with flags before passing.
fix
const emailRegex = new RegExp(/^...$/, 'i'); new FasterSchema({ email: { type: String, regEx: emailRegex } })
affects: >=1.0.0
gotchaCleaning an object mutates the original by default. Use clean(obj, { mutate: false }) to return a new object.
fix
const cleaned = schema.clean(obj, { mutate: false });
affects: >=1.0.0
deprecatedThe 'required' rule is deprecated in v2. Use 'optional' instead.
fix
Replace required: true with optional: false (default). For optional fields, set optional: true.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'validate')
Schema not instantiated correctly; likely forgot 'new' keyword.
fix
const schema = new FasterSchema({ ... });
Cannot find module 'faster-schema' or its corresponding type declarations.
Package not installed or TypeScript not resolving types.
fix
npm install faster-schema && npm install @types/faster-schema (if available) or ensure tsconfig includes node_modules.
Uncaught TypeError: Invalid schema definition: Field 'email' must be an object or a type.
Using shorthand incorrectly; e.g., { email: String } is fine, but { email: { type: String, ... } } expects object.
fix
Define schema fields as objects: { email: { type: String, optional: true } }
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
faster-schema — npm install faster-schema · libregistry