UNPKG

blow-data

Version:
36 lines (35 loc) 901 B
'use strict'; class ValidationResult { constructor(errors) { this._errors = errors; } get isValid() { return !this._errors.length; } get errors() { return this._errors; } getInvalidProperties() { return this._errors.reduce((properties, error) => { if (properties.indexOf(error.property) === -1) { properties.push(error.property); } return properties; }, []); } getPropertyErrors(propertyName) { return this._errors.reduce((errors, error) => { if (error && error.property === propertyName) { errors.push(error); } return errors; }, []); } toJSON() { return { isValid: this.isValid, errors: this.errors }; } } exports.ValidationResult = ValidationResult;