From bfb733e4a9cb840704c3d283292a5fd0df1eb153 Mon Sep 17 00:00:00 2001 From: Touch Date: Wed, 27 Sep 2023 11:26:10 +0700 Subject: [PATCH] chore: :label: create simpleobject types and assign toe validator class --- src/core/Validator.ts | 11 ++++++----- src/types.ts | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 src/types.ts diff --git a/src/core/Validator.ts b/src/core/Validator.ts index 156874ce..c2ffe05a 100644 --- a/src/core/Validator.ts +++ b/src/core/Validator.ts @@ -1,3 +1,4 @@ +import type { SimpleObject } from '../types' import { cloneDeep, get, has, omit } from 'lodash' import { is, toCamelCase, toSnakeCase } from '../util' @@ -5,7 +6,7 @@ class Validator { public successful: boolean public processing: boolean - constructor(public errors: Record = {}) { + constructor(public errors: SimpleObject = {}) { this.processing = false this.successful = false } @@ -42,7 +43,7 @@ class Validator { } } - firstBy(obj: Record, field?: string) { + firstBy(obj: SimpleObject, field?: string) { let value: string if (!field) { value = obj[Object.keys(obj)[0]] @@ -64,7 +65,7 @@ class Validator { any(field: string[] = [], returnObject?: boolean) { const fields = this.fields(field) if (returnObject) { - const errors: Record = {} + const errors: SimpleObject = {} if (!fields.length) return {} for (const f of fields) { const val = this.get(f) @@ -74,7 +75,7 @@ class Validator { return errors } if (!fields.length) return Object.keys(this.errors).length > 0 - const errors: Record = {} + const errors: SimpleObject = {} fields.forEach((key: string) => (errors[key] = this.get(key))) return Object.keys(errors).length > 0 } @@ -91,7 +92,7 @@ class Validator { return Object.keys(this.errors).length } - fill(errors: Record) { + fill(errors: SimpleObject) { this.errors = errors } diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 00000000..f8e709f4 --- /dev/null +++ b/src/types.ts @@ -0,0 +1 @@ +export type SimpleObject = Record