@@ -3,13 +3,7 @@ import { castArray, cloneDeep, get, has, omit, replace } from 'lodash'
33import { is , toCamelCase , toSnakeCase } from '../util'
44
55class Validator {
6- public successful : boolean
7- public processing : boolean
8-
9- constructor ( public errors : SimpleObject < any > = { } ) {
10- this . processing = false
11- this . successful = false
12- }
6+ constructor ( public errors : SimpleObject < any > = { } , public processing = false , public successful = false ) { }
137
148 add ( field : string , message : string , forceUpdate ?: boolean ) {
159 if ( forceUpdate || this . missed ( field ) ) {
@@ -24,16 +18,15 @@ class Validator {
2418 return is ( Object . keys ( this . errors ) , fields )
2519 }
2620
27- first ( field : string | string [ ] ) : string | undefined {
21+ first ( field : string | string [ ] ) {
2822 const fields = this . fields ( castArray ( field ) )
2923 const foundField = fields . find ( ( f ) => has ( this . errors , f ) ) ?? ''
3024 const value = this . get ( foundField )
3125 return Array . isArray ( value ) ? value [ 0 ] : value
3226 }
3327
3428 firstBy ( obj : SimpleObject < any > , field : string = Object . keys ( obj ) [ 0 ] ) : string {
35- const value : string = obj [ field ]
36- return Array . isArray ( value ) ? value [ 0 ] : value
29+ return castArray ( obj [ field ] ) [ 0 ]
3730 }
3831
3932 missed ( field : string | string [ ] ) {
0 commit comments