UNPKG

simple-body-validator

Version:

This package is inspired by Laravel validation, and aims to make body validation easier for Javascript developers

22 lines (21 loc) 559 B
'use strict'; import BaseRule from './baseRule'; class RequiredIf extends BaseRule { /** * Create a new required validation rule based on a condition. */ constructor(condition) { super(); this.condition = condition; } /** * Convert the rule to a validation string. */ toString() { if (typeof this.condition === 'function') { return this.condition() ? 'required' : ''; } return this.condition ? 'required' : ''; } } export default RequiredIf;