Skip to content

Commit bfb733e

Browse files
committed
chore: 🏷️ create simpleobject types and assign toe validator class
1 parent 5fdfe01 commit bfb733e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/core/Validator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import type { SimpleObject } from '../types'
12
import { cloneDeep, get, has, omit } from 'lodash'
23
import { is, toCamelCase, toSnakeCase } from '../util'
34

45
class Validator {
56
public successful: boolean
67
public processing: boolean
78

8-
constructor(public errors: Record<string, any> = {}) {
9+
constructor(public errors: SimpleObject<any> = {}) {
910
this.processing = false
1011
this.successful = false
1112
}
@@ -42,7 +43,7 @@ class Validator {
4243
}
4344
}
4445

45-
firstBy(obj: Record<string, any>, field?: string) {
46+
firstBy(obj: SimpleObject<any>, field?: string) {
4647
let value: string
4748
if (!field) {
4849
value = obj[Object.keys(obj)[0]]
@@ -64,7 +65,7 @@ class Validator {
6465
any(field: string[] = [], returnObject?: boolean) {
6566
const fields = this.fields(field)
6667
if (returnObject) {
67-
const errors: Record<string, any> = {}
68+
const errors: SimpleObject<any> = {}
6869
if (!fields.length) return {}
6970
for (const f of fields) {
7071
const val = this.get(f)
@@ -74,7 +75,7 @@ class Validator {
7475
return errors
7576
}
7677
if (!fields.length) return Object.keys(this.errors).length > 0
77-
const errors: Record<string, any> = {}
78+
const errors: SimpleObject<any> = {}
7879
fields.forEach((key: string) => (errors[key] = this.get(key)))
7980
return Object.keys(errors).length > 0
8081
}
@@ -91,7 +92,7 @@ class Validator {
9192
return Object.keys(this.errors).length
9293
}
9394

94-
fill(errors: Record<string, any>) {
95+
fill(errors: SimpleObject<any>) {
9596
this.errors = errors
9697
}
9798

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type SimpleObject<V> = Record<string, V>

0 commit comments

Comments
 (0)