incompatiblewith

1.0.9 • Public • Published

InCompatibleWith

InCompatibleWith is a decorator for class-validator that checks if siblings are not exist on object.

Installation

  npm i incompatiblewith

Argument

@IncompatibleWith accepts an array of siblings name in string.

  @IncompatibleWith (siblingPropsName: string[])

Use case:

InCompatibleWith checks if other properties exist on an object or not. In this case we want to have either status or deleted on the instance of class. If both exist it will complain.

import { IncompatibleWith } from 'incompatiblewith';

class UpdateUserDTO {
  @IsString()
  @IncompatibleWith(['deleted'])
  readonly status: string;

  @IsBoolean()
  @IncompatibleWith(['status'])
  readonly deleted: boolean;

  @IsString()
  readonly name: string;
}

Invalid Object

const obj = {
  status: 'test',
  deleted: true,
  name: 'john',
};

Valid Object

const obj = {
  deleted: true,
  name: 'john',
};

Or

const obj = {
  status: 'test',
  name: 'john',
};

Package Sidebar

Install

npm i incompatiblewith

Weekly Downloads

2,036

Version

1.0.9

License

ISC

Unpacked Size

12.6 kB

Total Files

12

Last publish

Collaborators

  • sunnystatue_