JSPM

class-validator-message-formatter

0.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 58
  • Score
    100M100P100Q112539F
  • License MIT

```cli npm i class-validator-message-formatter ```

Package Exports

  • class-validator-message-formatter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (class-validator-message-formatter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Class-validator-message-formatter

If you failed validation using class-validator, you'll be received messages. But it is very difficult to read. This library modifies the message to make it easier to handle.

Installation

$ npm install --save class-validator-message-formatter

Hot to use

class User {
    @IsString()
    name: string;

    @IsString()
    address: string;

    constructor(name: string, address: string) {
        this.name = name;
        this.address = address;
    }
}

Without class-validator-message-formatter

import { validateSync } from 'class-validator';
  
const user:User = new User();
const errors = validateSync(user);
console.log(errors);
 [ ValidationError {
        target: User { name: null, address: null },
        value: null,
        property: 'name',
        children: [],
        constraints: { isString: 'name must be a string' } },
    ValidationError {
        target: User { name: null, address: null },
        value: null,
        property: 'address',
        children: [],
        constraints: { isString: 'address must be a string' } } ]

with class-validator-message-formatter

import {MessageFormatter} from 'class-validator-message-formatter';
import { validateSync } from 'class-validator';

const user:User = new User();
const errors = validateSync(user);
console.log(MessageFormatter.format(errors));
[ { field: 'name', message: 'name must be a string' },
  { field: 'address', message: 'address must be a string' } ]