Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

class-validator-flat-formatter

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-validator-flat-formatter

Convert array of ValidationError objects from class-validator to multiline string

  • 5.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59
increased by63.89%
Maintainers
0
Weekly downloads
 
Created
Source

class-validator-flat-formatter

Convert array of ValidationError objects from class-validator to multiline string

Install

npm install class-validator-flat-formatter

Usage

As string
import { validationError } from 'class-validator-flat-formatter';

const errors = await validate(user);

const message = validationError(errors, options);
// message => name: should not be empty (isNotEmpty), email: must be an email (isEmail)
Options
export interface ValidationErrorOptions {
  /**
   * Custom template, tokens:
   * {propertyPath} - Full dotted property path (e.g user.email)
   * {property} - Last piece of {propertyPath} (e.g. email)
   * {constraintRule} - Constraint rule id (e.g. isEmail)
   * {constraintMessage} - Constraint message (e.g. must be an email)
   */
  template?: string;
  /**
   * Delimiter of joined several validation messages.
   * Default: Comma and space (CS)
   */
  delimiter?: Delimiter | string;
  /**
   * Period at the end of string.
   * Default: false
   */
  period?: boolean;
}
As array
import { validationErrorsAsArray } from 'class-validator-flat-formatter';

const errors = await validate(user);
const messages = validationErrorsAsArray(errors);
/** 
messages => Array<string> {
    'name: should not be empty (isNotEmpty)',
    'email: must be an email (isEmail)'
}
*/

License

MIT License (c) 2024

Keywords

FAQs

Package last updated on 06 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc