Registry / testing / class-validator-message-formatter

class-validator-message-formatter

JSON →
library0.0.3jsnpmunverified

A lightweight utility for formatting class-validator validation errors into a cleaner, more readable structure. Version 0.0.3, no active release cadence. Key differentiator: transforms the complex ValidationError array from class-validator into a simple array of {field, message} objects, making it easier to display or process validation errors in applications.

npm install class-validator-message-formatter
INSTALL
IMPORT
SIG · CLASS-VALIDATOR-ME
C
class-validator-message-formatter
testingjavascriptv0.0.3
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.

MessageFormatter
✓ import { MessageFormatter } from 'class-validator-message-formatter'
ESM only; no CommonJS export.
ValidationError
✓ import { ValidationError } from 'class-validator'
✗ import { ValidationError } from 'class-validator-message-formatter'
ValidationError is from class-validator, not this package.
default import
✓ import { MessageFormatter } from 'class-validator-message-formatter'
✗ import MessageFormatter from 'class-validator-message-formatter'
Only named export exists.

Demonstrates formatting class-validator validation errors into simplified {field, message} array.

import { validateSync } from 'class-validator'; import { IsString } from 'class-validator'; import { MessageFormatter } from 'class-validator-message-formatter'; class User { @IsString() name: string; @IsString() address: string; constructor(name: string, address: string) { this.name = name; this.address = address; } } const user = new User(); const errors = validateSync(user); const formatted = MessageFormatter.format(errors); console.log(formatted); // Output: // [ { field: 'name', message: 'name must be a string' }, // { field: 'address', message: 'address must be a string' } ]
Debug
Known issues
gotchaMessageFormatter.format expects argument of type ValidationError[]; passing wrong type will cause runtime error.
fix
Ensure input is the array returned by validate or validateSync.
affects: >=0.0.1
gotchaPackage only works with class-validator, not standalone validation.
fix
This package is a helper for class-validator and does not replace it.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: MessageFormatter.format is not a function
Incorrect import: default import instead of named import.
fix
Use import { MessageFormatter } from 'class-validator-message-formatter' instead of import MessageFormatter from ...
Cannot find module 'class-validator-message-formatter'
Package not installed or typo in package name.
fix
Run npm install class-validator-message-formatter and ensure no typo.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
class-validator-message-formatter — npm install class-validator-message-formatter · libregistry