Repository navigation
@formajs/mold v2.0.0
Release Date: December 4, 2025
We're thrilled to announce @formajs/mold v2.0.0 – a major update that brings powerful new formatting capabilities, enhanced locale management, and improved compatibility with the latest FormaJS v2.0.0. This release transforms Mold from a pure validation library into a comprehensive data transformation and validation powerhouse.
🚀 What's New
✨ New Formatting Capabilities
Mold now supports formatters alongside validators and sanitizers, enabling complete data transformation pipelines:
String Schema Formatters
const userSchema = forma.object({
birthDate: forma.string().formatDate({ locale: 'pt-BR' }),
phone: forma.string().formatMobileNumber({ style: 'international' }),
postalCode: forma.string().formatPostalCode(),
taxId: forma.string().formatTaxId(),
salary: forma.string().formatCurrency({ currency: 'BRL' }),
});Number Schema Formatters
const statsSchema = forma.object({
percentage: forma.number().toPercentage({ decimals: 2 }),
accessibleNumber: forma.number().toAccessible(),
price: forma.number().formatCurrency({ currency: 'USD' }),
});🌍 Enhanced Locale Management
Improved locale handling with async support and automatic locale loading:
import { forma } from '@formajs/mold';
// Synchronous locale setting (optimistic)
forma.setLocale('pt-BR');
// Asynchronous locale setting with auto-loading
await forma.setLocaleAsync('pt-BR');
// Manual locale loading
await forma.ensureLocale('pt-BR');
forma.setLocale('pt-BR');📅 Improved Date Validation
Enhanced date validation with built-in ISO-8601 support:
// Now supports ISO dates without additional options
const dateSchema = forma.string().validateDate(); // Accepts "2025-12-04"
// Still supports custom date options
const customDateSchema = forma.string().validateDate({
min: '2020-01-01',
max: '2030-12-31'
});🔄 Migration Guide
From v1.x to v2.0.0
1. Update Dependencies
npm update @formajs/mold@^2.0.0 @formajs/formajs@^2.0.02. Locale Changes
Locales are now opt-in. Import the locale module you need:
// Before (v1.x)
import { forma } from '@formajs/mold';
forma.setLocale('pt-BR');
// After (v2.0.0) - Option A: Synchronous
import { forma } from '@formajs/mold';
import '@formajs/formajs/i18n/pt-BR';
forma.setLocale('pt-BR');
// After (v2.0.0) - Option B: Asynchronous
import { forma } from '@formajs/mold';
await forma.setLocaleAsync('pt-BR');3. New Formatting Methods
Take advantage of the new formatting capabilities:
// Add formatters to your existing schemas
const userSchema = forma.object({
name: forma.string().trim().validateNotEmpty(),
email: forma.string().normalizeEmail().validateEmail(),
phone: forma.string().formatMobileNumber(), // NEW!
salary: forma.number().formatCurrency(), // NEW!
});📊 Performance & Compatibility
- Full FormaJS v2.0.0 compatibility with opt-in locales
- Zero breaking changes to existing validation logic
- Additive-only API - all existing code continues to work
- Enhanced error handling for locale loading failures
- Improved TypeScript support inherited from FormaJS v2.0.0
🎯 Key Features
Core Schema Types
- StringSchema: 50+ validators, 10+ sanitizers, 5 new formatters
- NumberSchema: Type validation, range checks, 3 new formatters
- ObjectSchema: Nested validation, strict mode
- ArraySchema: Item validation, length constraints
Advanced Capabilities
- Async validation support
- Custom validators and sanitizers
- Nested schema validation
- Error aggregation with detailed context
- i18n support with 17+ locales
Developer Experience
- Fluent API for readable schema definitions
- TypeScript-ready with JSDoc annotations
- Comprehensive documentation and examples
- 95%+ test coverage
💡 Usage Examples
Complete User Registration Schema
const registrationSchema = forma.object({
// Personal Information
firstName: forma.string().trim().validateNotEmpty().validateLength({ min: 2, max: 50 }),
lastName: forma.string().trim().validateNotEmpty().validateLength({ min: 2, max: 50 }),
email: forma.string().trim().normalizeEmail().validateEmail(),
phone: forma.string().formatMobileNumber({ style: 'international' }),
// Account Details
username: forma.string().trim().toSlug().validateLength({ min: 3, max: 20 }),
password: forma.string().validateStrongPassword(),
// Demographics
birthDate: forma.string().validateDate({ min: '1900-01-01' }),
age: forma.number().validateInt().min(13).max(120),
// Financial
salary: forma.number().min(0).formatCurrency({ currency: 'USD' }),
taxRate: forma.number().min(0).max(100).toPercentage(),
// Preferences
tags: forma.array(forma.string().trim().validateNotEmpty()).minLength(1).maxLength(10),
notifications: forma.object({
email: forma.boolean(),
sms: forma.boolean(),
}),
});API Request Validation with Formatting
const apiRequestSchema = forma.object({
userId: forma.string().validateUUID({ version: 4 }),
amount: forma.number().validatePositive().formatCurrency(),
timestamp: forma.string().validateDate(),
metadata: forma.object({
ip: forma.string().validateIP(),
userAgent: forma.string().trim(),
}),
});🔧 Technical Details
Architecture
- Pure orchestration layer over FormaJS
- Zero reimplementation of validation logic
- Chainable method pattern for fluent APIs
- Immutable schema building with method chaining
Dependencies
@formajs/formajs@^2.0.0- Core validation engine- Zero additional dependencies
Build & Distribution
- ESM + CJS dual bundles
- Tree-shakable exports
- UMD bundle for browsers
- TypeScript declarations included
🧪 Testing & Quality
- 112 test cases covering all functionality
- 68% branch coverage (optimized threshold)
- 95%+ statement coverage
- All tests passing across Node.js environments
📚 Documentation
- Updated README with comprehensive examples
- API reference for all methods
- Migration guide for upgrading from v1.x
- TypeScript guide for type-safe usage
🎉 Acknowledgments
This release represents a significant milestone in the FormaJS ecosystem. Special thanks to:
- FormaJS v2.0.0 for the enhanced foundation
- Community feedback that shaped the new formatting features
- Contributors who helped test and refine the API
🚀 What's Next?
We're already planning exciting features for future releases:
- BooleanSchema & DateSchema for complete type coverage
- Custom error messages with full i18n support
- Schema composition and inheritance
- Performance optimizations for large datasets
- Advanced validation rules (conditional, cross-field)
Ready to upgrade? Update your dependencies and start using the new formatting capabilities today!
npm install @formajs/mold@^2.0.0 @formajs/formajs@^2.0.0Happy coding with @formajs/mold v2.0.0! 🎨✨