1
+ import type { SimpleObject } from '../types'
1
2
import { cloneDeep , get , has , omit } from 'lodash'
2
3
import { is , toCamelCase , toSnakeCase } from '../util'
3
4
4
5
class Validator {
5
6
public successful : boolean
6
7
public processing : boolean
7
8
8
- constructor ( public errors : Record < string , any > = { } ) {
9
+ constructor ( public errors : SimpleObject < any > = { } ) {
9
10
this . processing = false
10
11
this . successful = false
11
12
}
@@ -24,7 +25,7 @@ class Validator {
24
25
return is ( Object . keys ( this . errors ) , fields )
25
26
}
26
27
27
- first ( field : string | string [ ] ) : string | Record < string , any > | undefined {
28
+ first ( field : string | string [ ] ) : string | undefined {
28
29
if ( Array . isArray ( field ) ) {
29
30
const fields = this . fields ( field )
30
31
let fd = ''
@@ -42,7 +43,7 @@ class Validator {
42
43
}
43
44
}
44
45
45
- firstBy ( obj : Record < string , any > , field ?: string ) {
46
+ firstBy ( obj : SimpleObject < any > , field ?: string ) {
46
47
let value : string
47
48
if ( ! field ) {
48
49
value = obj [ Object . keys ( obj ) [ 0 ] ]
@@ -64,7 +65,7 @@ class Validator {
64
65
any ( field : string [ ] = [ ] , returnObject ?: boolean ) {
65
66
const fields = this . fields ( field )
66
67
if ( returnObject ) {
67
- const errors : Record < string , any > = { }
68
+ const errors : SimpleObject < any > = { }
68
69
if ( ! fields . length ) return { }
69
70
for ( const f of fields ) {
70
71
const val = this . get ( f )
@@ -74,7 +75,7 @@ class Validator {
74
75
return errors
75
76
}
76
77
if ( ! fields . length ) return Object . keys ( this . errors ) . length > 0
77
- const errors : Record < string , any > = { }
78
+ const errors : SimpleObject < any > = { }
78
79
fields . forEach ( ( key : string ) => ( errors [ key ] = this . get ( key ) ) )
79
80
return Object . keys ( errors ) . length > 0
80
81
}
@@ -91,7 +92,7 @@ class Validator {
91
92
return Object . keys ( this . errors ) . length
92
93
}
93
94
94
- fill ( errors : Record < string , any > ) {
95
+ fill ( errors : SimpleObject < any > ) {
95
96
this . errors = errors
96
97
}
97
98
0 commit comments