# class-validator-flat-formatter

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

Latest version **6.0.0** (published 2025-06-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install class-validator-flat-formatter
pnpm add class-validator-flat-formatter
yarn add class-validator-flat-formatter
bun add class-validator-flat-formatter
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2025-06-08 |
| First published | 2020-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | iamthes |
| Keywords | class-validator |

## Links

- npm: https://www.npmjs.com/package/class-validator-flat-formatter
- Repository: https://github.com/unlight/class-validator-flat-formatter
- Homepage: https://github.com/unlight/class-validator-flat-formatter#readme
- Issues: https://github.com/unlight/class-validator-flat-formatter/issues
- npm.io page: https://npm.io/package/class-validator-flat-formatter

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 6.0.0 (latest) — 2025-06-08
- 5.0.1 — 2024-10-06
- 5.0.0 — 2024-10-05
- 4.1.0 — 2024-09-14
- 4.0.2 — 2024-05-08
- 4.0.1 — 2024-05-08
- 4.0.0 — 2024-05-08
- 3.0.1 — 2022-04-23
- 3.0.0 — 2022-04-23
- 2.0.0 — 2021-04-30
- 1.0.1 — 2021-01-16
- 1.0.0 — 2020-04-11

## README

# class-validator-flat-formatter

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

## Install

```sh
npm install class-validator-flat-formatter
```

## Usage

#### As string

```ts
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

```ts
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

```ts
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)'
}
*/
```

#### validationErrorsByProperty

Group validation errors by property

```ts
function validationErrorsByProperty(
  errors: ValidationError[] | ValidationError,
  template: string = '{constraintMessage} ({constraintRule})',
  delimiter: string = '\n',
)
/**
age: should not be null or undefined (isDefined), must not be less than 18 (min)
email.value: should not be empty (isNotEmpty), must be an email (isEmail)
```

## License

[MIT License](https://opensource.org/licenses/MIT) (c) 2025

---
_Source: https://npm.io/package/class-validator-flat-formatter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
