Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit a060e80

Browse files
committed
fix(types): fix ts warnings
1 parent d38c29a commit a060e80

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

src/core/models.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@ export type InputType =
2525
| UrlInput
2626
| CustomInput;
2727

28-
type ValidationError = {
29-
text: string;
28+
export type ValidationErrors = {
3029
// eslint-disable-next-line
31-
value: any;
32-
};
33-
34-
type ValidationErrors = {
35-
[key: string]: ValidationError;
30+
[key: string]: any;
3631
};
3732

3833
interface ValidatorFn {

src/core/utils/validators.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
/* eslint-disable */
1+
import { FormControl, InputType, ValidationErrors } from '../models';
22

3-
import { FormControl, InputType } from '../models';
4-
5-
export const isEmptyInputValue = (value: any) =>
6-
value == null || value === '' || value.length === 0;
3+
export const isEmptyInputValue = (value: string | number | boolean): boolean =>
4+
value == null || value === '';
75

86
const EMAIL_REGEXP = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
97
const URL_REGEXP = /^((?:(https?):\/\/)?((?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]|[0-9])\.(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]|[0-9])\.)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]|[0-9])\.)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]|[0-9]))|(?:(?:(?:\w+\.){1,2}[\w]{2,3})))(?::(\d+))?((?:\/[\w]+)*)(?:\/|(\/[\w]+\.[\w]{3,4})|(\?(?:([\w]+=[\w]+)&)*([\w]+=[\w]+))?|\?(?:(wsdl|wadl))))$/;
108

11-
export const required = (control: FormControl<InputType>) =>
9+
export const required = (
10+
control: FormControl<InputType>,
11+
): ValidationErrors | null =>
1212
isEmptyInputValue(control.value) ? { required: true } : null;
1313

14-
export const min = (min: number) => (control: FormControl<InputType>) => {
14+
export const min = (min: number) => (
15+
control: FormControl<InputType>,
16+
): ValidationErrors | null => {
1517
if (isEmptyInputValue(control.value) || isEmptyInputValue(min)) {
1618
return null; // don't validate empty values to allow optional controls
1719
}
@@ -22,7 +24,9 @@ export const min = (min: number) => (control: FormControl<InputType>) => {
2224
: null;
2325
};
2426

25-
export const max = (max: number) => (control: FormControl<InputType>) => {
27+
export const max = (max: number) => (
28+
control: FormControl<InputType>,
29+
): ValidationErrors | null => {
2630
if (isEmptyInputValue(control.value) || isEmptyInputValue(max)) {
2731
return null; // don't validate empty values to allow optional controls
2832
}
@@ -34,14 +38,18 @@ export const max = (max: number) => (control: FormControl<InputType>) => {
3438
: null;
3539
};
3640

37-
export const email = (control: FormControl<InputType>) => {
41+
export const email = (
42+
control: FormControl<InputType>,
43+
): ValidationErrors | null => {
3844
if (isEmptyInputValue(control.value)) {
3945
return null; // don't validate empty values to allow optional controls
4046
}
4147
return EMAIL_REGEXP.test(`${control.value}`) ? null : { email: true };
4248
};
4349

44-
export const url = (control: FormControl<InputType>) => {
50+
export const url = (
51+
control: FormControl<InputType>,
52+
): ValidationErrors | null => {
4553
if (isEmptyInputValue(control.value)) {
4654
return null; // don't validate empty values to allow optional controls
4755
}
@@ -50,7 +58,7 @@ export const url = (control: FormControl<InputType>) => {
5058

5159
export const minLength = (minLength: number) => (
5260
control: FormControl<InputType>,
53-
) => {
61+
): ValidationErrors | null => {
5462
if (isEmptyInputValue(control.value)) {
5563
return null; // don't validate empty values to allow optional controls
5664
}
@@ -62,14 +70,14 @@ export const minLength = (minLength: number) => (
6270

6371
export const maxLength = (maxLength: number) => (
6472
control: FormControl<InputType>,
65-
) => {
73+
): ValidationErrors | null => {
6674
const length = control.value ? `${control.value}`.length : 0;
6775
return length > maxLength
6876
? { maxlength: { requiredLength: maxLength, actualLength: length } }
6977
: null;
7078
};
7179

72-
export const pattern = (pattern: string) => {
80+
export const pattern = (pattern: string): ValidationErrors | null => {
7381
if (!pattern) return null;
7482
let regex: RegExp;
7583
let regexStr: string | RegExp;

vue.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module.exports = {
1313
pages: {
1414
index: {
1515
title: 'Vue Dynamic Forms',
16-
entry: 'dev/typescript/main.ts',
16+
// entry: 'dev/typescript/main.ts', // Typescript Demo
17+
entry: 'dev/vue/main.js',
1718
template: 'public/index.html',
1819
filename: 'index.html',
1920
},

0 commit comments

Comments
 (0)