@juantroconisf/lib 1.9.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +13 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +5 -4
- package/dist/index.mjs +5 -4
- package/package.json +2 -1
- package/lang/en.json +0 -1
- package/lang/es.json +0 -1
- package/types/errors.ts +0 -91
- package/types/types.ts +0 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ChangeEvent } from 'react';
|
|
3
|
+
import { InputProps } from '@nextui-org/react';
|
|
3
4
|
|
|
4
5
|
type ValidatorFunction<T, U> = (val: T, ...args: U[]) => boolean;
|
|
5
6
|
interface Validator<T, U = any> {
|
|
@@ -25,17 +26,23 @@ type ValidatorErrorMessage = {
|
|
|
25
26
|
[K in keyof ValidatorTypes]: string;
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
interface ValidationProps {
|
|
30
|
+
isInvalid: InputProps["isInvalid"];
|
|
31
|
+
errorMessage: InputProps["errorMessage"];
|
|
32
|
+
}
|
|
33
|
+
interface RegisterInputProps extends ValidationProps {
|
|
34
|
+
id: InputProps["id"];
|
|
35
|
+
onChange: InputProps["onChange"];
|
|
36
|
+
onBlur: InputProps["onBlur"];
|
|
37
|
+
value: InputProps["value"];
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
declare function useFormChange<InitialObj extends object>(initialObj: InitialObj): {
|
|
29
41
|
onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
|
|
30
42
|
onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
|
|
31
43
|
state: InitialObj;
|
|
32
44
|
setState: react.Dispatch<react.SetStateAction<InitialObj>>;
|
|
33
|
-
register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) =>
|
|
34
|
-
id: K;
|
|
35
|
-
onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
|
|
36
|
-
onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
|
|
37
|
-
value: any;
|
|
38
|
-
};
|
|
45
|
+
register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) => RegisterInputProps;
|
|
39
46
|
hasInvalidValues: () => boolean;
|
|
40
47
|
touched: InitialObj;
|
|
41
48
|
resetForm: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ChangeEvent } from 'react';
|
|
3
|
+
import { InputProps } from '@nextui-org/react';
|
|
3
4
|
|
|
4
5
|
type ValidatorFunction<T, U> = (val: T, ...args: U[]) => boolean;
|
|
5
6
|
interface Validator<T, U = any> {
|
|
@@ -25,17 +26,23 @@ type ValidatorErrorMessage = {
|
|
|
25
26
|
[K in keyof ValidatorTypes]: string;
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
interface ValidationProps {
|
|
30
|
+
isInvalid: InputProps["isInvalid"];
|
|
31
|
+
errorMessage: InputProps["errorMessage"];
|
|
32
|
+
}
|
|
33
|
+
interface RegisterInputProps extends ValidationProps {
|
|
34
|
+
id: InputProps["id"];
|
|
35
|
+
onChange: InputProps["onChange"];
|
|
36
|
+
onBlur: InputProps["onBlur"];
|
|
37
|
+
value: InputProps["value"];
|
|
38
|
+
}
|
|
39
|
+
|
|
28
40
|
declare function useFormChange<InitialObj extends object>(initialObj: InitialObj): {
|
|
29
41
|
onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
|
|
30
42
|
onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
|
|
31
43
|
state: InitialObj;
|
|
32
44
|
setState: react.Dispatch<react.SetStateAction<InitialObj>>;
|
|
33
|
-
register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) =>
|
|
34
|
-
id: K;
|
|
35
|
-
onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
|
|
36
|
-
onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
|
|
37
|
-
value: any;
|
|
38
|
-
};
|
|
45
|
+
register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) => RegisterInputProps;
|
|
39
46
|
hasInvalidValues: () => boolean;
|
|
40
47
|
touched: InitialObj;
|
|
41
48
|
resetForm: () => void;
|
package/dist/index.js
CHANGED
|
@@ -178,18 +178,19 @@ function useFormChange(initialObj) {
|
|
|
178
178
|
function register(id, validations, errorMessages) {
|
|
179
179
|
const [value, isTouched] = [state, touched].map(
|
|
180
180
|
(obj) => getNestedValueByKey(obj, id)
|
|
181
|
-
), hasValidations = validations !== void 0,
|
|
181
|
+
), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
182
182
|
errors2 = handleNestedChange({
|
|
183
183
|
state: errors2,
|
|
184
184
|
id,
|
|
185
|
-
value: hasValidations ? !isValid : false
|
|
185
|
+
value: hasValidations ? !inputValidations.isValid : false
|
|
186
186
|
});
|
|
187
187
|
return {
|
|
188
188
|
id,
|
|
189
189
|
onChange,
|
|
190
|
-
onBlur,
|
|
190
|
+
onBlur: (e) => onBlur(e),
|
|
191
191
|
value,
|
|
192
|
-
|
|
192
|
+
isInvalid: hasValidations ? !inputValidations.isValid : false,
|
|
193
|
+
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
193
194
|
};
|
|
194
195
|
}
|
|
195
196
|
const hasInvalidValues = () => {
|
package/dist/index.mjs
CHANGED
|
@@ -160,18 +160,19 @@ function useFormChange(initialObj) {
|
|
|
160
160
|
function register(id, validations, errorMessages) {
|
|
161
161
|
const [value, isTouched] = [state, touched].map(
|
|
162
162
|
(obj) => getNestedValueByKey(obj, id)
|
|
163
|
-
), hasValidations = validations !== void 0,
|
|
163
|
+
), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
|
|
164
164
|
errors2 = handleNestedChange({
|
|
165
165
|
state: errors2,
|
|
166
166
|
id,
|
|
167
|
-
value: hasValidations ? !isValid : false
|
|
167
|
+
value: hasValidations ? !inputValidations.isValid : false
|
|
168
168
|
});
|
|
169
169
|
return {
|
|
170
170
|
id,
|
|
171
171
|
onChange,
|
|
172
|
-
onBlur,
|
|
172
|
+
onBlur: (e) => onBlur(e),
|
|
173
173
|
value,
|
|
174
|
-
|
|
174
|
+
isInvalid: hasValidations ? !inputValidations.isValid : false,
|
|
175
|
+
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
175
176
|
};
|
|
176
177
|
}
|
|
177
178
|
const hasInvalidValues = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juantroconisf/lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"typescript": "^5.5.4"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@nextui-org/react": "^2.4.8",
|
|
26
27
|
"react": "^18.3.1"
|
|
27
28
|
}
|
|
28
29
|
}
|
package/lang/en.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"BIRTH_DATE":"Birth date","DAY":"Day","DAY_PLACEHOLDER":"Choose a day","MONTH":"Month","MONTH_PLACEHOLDER":"Choose a month","YEAR":"Year","YEAR_PLACEHOLDER":"Choose a year","PRICING":"Pricing","PRICING_TABLE":"Pricing table","OUR_PRICING_PLAN":"Our pricing plan","PRICING_DESCRIPTION":"Level up your experience. Discover the plan that unlocks the features you need.","VALUE_STORAGE":"{{value}} storage","GOOGLE_CALENDAR_SYNC":"Google Calendar Sync","INTERNAL_REMINDERS":"Internal reminders","WHATSAPP_AUTOMATED_REMINDERS":"WhatsApp Automated Reminders","PROFESSIONAL":"Professional","PROFESSIONAL_PLAN_DESCRIPTION":"For single doctors looking to level up their practice","DIGITAL_PRESCRIPTIONS":"Digital prescriptions","DICOM_VIEWER":"DICOM Viewer","VERIFIED_MEDICAL_CREDENTIALS":"Verified medical credentials","PATIENT_SELF_MANAGEMENT":"Patient self management","BUY_NOW":"Buy now","ORGANIZATION":"Organization","ORGANIZATION_PLAN_DESCRIPTION":"For organizations with multiple users looking to share information","UP_TO_VALUE_STORAGE":"Up to {{value}} storage","CONFIGURABLE_USER_PERMISSIONS":"Configurable user permissions","CALCULATE_PRICING":"Calculate pricing","DOCTORS":"Doctors","ASSISTANTS":"Assistants","BASIC":"Basic","BASIC_PLAN_DESCRIPTION":"For starters in the medical industry","USER":"User","TYPE_A_VALUE":"Type a value","STORAGE":"Storage","PASSWORD":"Password","PASSWORD_PLACEHOLDER":"Enter your password","REQUIRED":"Required","TOO_SHORT":"Too short","TOO_LONG":"Too long","VALUE_LOW":"Value is too low","VALUE_HIGH":"Value is too high","PATTERN_INVALID":"Pattern is not valid","INVALID_EMAIL":"Invalid email","SHOW_PASSWORD":"Show password","HIDE_PASSWORD":"Hide password","GROUP_PRICING_CALCULATOR":"Group Pricing Calculator","VERIFIED_ACCOUNT":"Verified account","VERIFIED_ACCOUNT_TEXT":"This account has been verified by Clinikos, as well as its affiliations with the following institutions","PHONE_NUMBER":"Phone number","PHONE_NUMBER_PLACEHOLDER":"Enter your phone number","SEND_MESSAGE":"Send message","BOOK_MEETING":"Book meeting","SIGN_UP":"Sign up","INVALID_PASSWORD":"Your password doesn't meet the security criteria.","NOT_EQUAL":"Values are not equal","GENDER":"Gender","FEMALE":"Female","MALE":"Male","CLOSE":"Close","MANDATORY_FIELDS_WARNING":"","INVALID_FIELDS_WARNING":"","COUNTRY":"Country","COUNTRY_PLACEHOLDER":"Select a country","STATE":"State","STATE_PLACEHOLDER":"Select a state","CITY":"City","CITY_PLACEHOLDER":"Select a city","TIMEZONE":"Timezone","TIMEZONE_PLACEHOLDER":"Selecte a timezone","NAME":"Name","OK":"Ok","PAGE_NOT_FOUND":"Page not found","PAGE_NOT_FOUND_DESCRIPTION":"The link you clicked may be broken or the page may have been removed or renamed","TODAY":"Today","WEEK":"Week","CALENDAR":"Calendar","EVENT":"Event","NO_INFORMATION":"No information","SYNC_GOOGLE_CALENDAR":"Sync Google Calendar","NO_RESULTS":"No results were found","GOOGLE_MEET":"Google Meet","LONG_TIME_AGO":"Long time ago","TOMORROW":"Tomorrow","CHOOSE_PLAN":"Choose a plan","CHOOSE_PLAN_DESCRIPTION":"Choose a plan that fits your needs!","PRIVACY_POLICY":"","OPTIONAL":"Optional","RESULTS":"Results","LOCATION":"Location","ADDRESS":"Address","ADDRESS_PLACEHOLDER":"Enter your address","COPY_TO_CLIPBOARD":"Copy to clipboard","ACTIONS":"Actions","MIN":"Minimum","MAX":"Maximum","DUE_DATE":"Due date","QUICK_SEARCH":"Quick search","MONTHLY":"Monthly","WEEKLY":"Weekly","GOOGLE_MAPS_LINK":"Google maps link","MINUTE":"Minute","MINUTES":"Minutes","HOUR":"Hour","HOURS":"Hours","VE_ID":"Identity card","ACCOUNT_VERIFIED_BY_CLINIKOS":"This account has been verified by Clinikos, as well as its affiliations with the following institutions","INBOX":"Inbox","ACCEPTED":"Accepted","DECLINED":"Declined","NEEDS_ACTION":"Needs action","OVERDUE":"Overdue","FILTER_BY":"Filter by","REFRESH":"Refresh","LOADING":"Loading","MINUTE_LEFT":"One minute left","VALUE_MINUTES_LEFT":"{{value}} minutes left","PLAY":"Play","PAUSE":"Pause","STOP":"Stop","LOAD_MORE":"Load more","BILLING":"Billing","DOCTOR":"Doctor","ASSISTANT":"Assistant","NUMBER_OF_DOCTORS":"Number of Doctors","NUMBER_OF_ASSISTANTS":"Number of Assistants","EACH_DOCTOR":"Each doctor","EACH_ASSISTANT":"Each assistant","ROLE":"Role","PAYMENT_METHODS":"Payment methods","UPGRADE":"Upgrade","TOTAL":"Total","BUY":"Buy","TYPE":"Type","RECURRENT":"Recurrent","ACCEPT":"Accept","DECLINE":"Decline","PREFERENCES":"Preferences","BOOKING":"Booking","PATTERN_NOT_VALID":"Pattern is not valid"}
|
package/lang/es.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"BIRTH_DATE":"Fecha de nacimiento","DAY":"Día","DAY_PLACEHOLDER":"Elige un día","MONTH":"Mes","MONTH_PLACEHOLDER":"Elige un mes","YEAR":"Año","YEAR_PLACEHOLDER":"Elige un año","PRICING":"Precio","PRICING_TABLE":"Tabla de precios","OUR_PRICING_PLAN":"Nuestros precios","PRICING_DESCRIPTION":"Mejora tu experiencia. Descubre el plan que desbloquea las funciones que necesitas.","VALUE_STORAGE":"{{value}} almacenamiento","GOOGLE_CALENDAR_SYNC":"Google Calenar Sync","INTERNAL_REMINDERS":"Recordatorios internos","WHATSAPP_AUTOMATED_REMINDERS":"Recordatorios automatizados de WhatsApp","PROFESSIONAL":"Profesional","PROFESSIONAL_PLAN_DESCRIPTION":"Para doctores individuales que buscan elevar sus prácticas","DIGITAL_PRESCRIPTIONS":"Recipes digitales","DICOM_VIEWER":"Visualizador DICOM","VERIFIED_MEDICAL_CREDENTIALS":"Credenciales médicas verificadas","PATIENT_SELF_MANAGEMENT":"Auto gestión para pacientes","BUY_NOW":"Comprar ahora","ORGANIZATION":"Organización","ORGANIZATION_PLAN_DESCRIPTION":"Para organizaciones con múltiples usuarios que buscan compartir información","UP_TO_VALUE_STORAGE":"Hasta {{value}} de almacenamiento","CONFIGURABLE_USER_PERMISSIONS":"Permisología configurable para usuarios","CALCULATE_PRICING":"Calcular precio","DOCTORS":"Doctores","ASSISTANTS":"Asistentes","BASIC":"Básico","BASIC_PLAN_DESCRIPTION":"Para iniciar en la industria médica","USER":"Usuario","TYPE_A_VALUE":"Ingresa un valor","STORAGE":"Almacenamiento","PASSWORD":"Contraseña","PASSWORD_PLACEHOLDER":"Ingresa tu contraseña","REQUIRED":"Requerido","TOO_SHORT":"Demasiado corto","TOO_LONG":"Demasiado largo","VALUE_LOW":"El valor es muy bajo","VALUE_HIGH":"El valor es muy alto","PATTERN_INVALID":"El patrón no es válido","INVALID_EMAIL":"Correo inválido","SHOW_PASSWORD":"Mostrar contraseña","HIDE_PASSWORD":"Esconder contraseña","GROUP_PRICING_CALCULATOR":"Calculadora de precios grupal","VERIFIED_ACCOUNT":"Cuenta verificada","VERIFIED_ACCOUNT_TEXT":"Esta cuenta ha sido verificada por Clinikos, así como sus afiliaciones con las siguientes instituciones","PHONE_NUMBER":"Número de teléfono","PHONE_NUMBER_PLACEHOLDER":"Ingrese su número de teléfono","SEND_MESSAGE":"Enviar mensaje","BOOK_MEETING":"Agendar cita","SIGN_UP":"Regístrate","INVALID_PASSWORD":"Tu contraseña no cumple con los requisitos de seguridad.","NOT_EQUAL":"Los valores no son iguales","GENDER":"Género","FEMALE":"Femenino","MALE":"Masculino","CLOSE":"Cerrar","MANDATORY_FIELDS_WARNING":"","INVALID_FIELDS_WARNING":"","COUNTRY":"País","COUNTRY_PLACEHOLDER":"Selecciona un país","STATE":"Estado","STATE_PLACEHOLDER":"Selecciona un estado","CITY":"Ciudad","CITY_PLACEHOLDER":"Selecciona una ciudad","TIMEZONE":"Zona horaria","TIMEZONE_PLACEHOLDER":"Selecciona una zora horaria","NAME":"Nombre","OK":"Ok","PAGE_NOT_FOUND":"Página no encontrada","PAGE_NOT_FOUND_DESCRIPTION":"El enlace en el que hiciste click puede que esté roto o la página puede haber sido eliminada o renombrada","TODAY":"Hoy","WEEK":"Semana","CALENDAR":"Calendario","EVENT":"Evento","NO_INFORMATION":"Sin información","SYNC_GOOGLE_CALENDAR":"Vincular Calendario de Google","NO_RESULTS":"No se encontraron resultados","GOOGLE_MEET":"Google Meet","LONG_TIME_AGO":"Hace mucho tiempo","TOMORROW":"Mañana","CHOOSE_PLAN":"Elige un plan","CHOOSE_PLAN_DESCRIPTION":"¡Elige el plan que se ajuste a tus necesidades!","PRIVACY_POLICY":"","OPTIONAL":"Opcional","RESULTS":"Resultados","LOCATION":"Ubicación","ADDRESS":"Dirección","ADDRESS_PLACEHOLDER":"Ingresa tu dirección","COPY_TO_CLIPBOARD":"Copiar al portapapeles","ACTIONS":"Acciones","MIN":"Mínimo","MAX":"Máximo","DUE_DATE":"Fecha límite","QUICK_SEARCH":"Búsqueda rápida","MONTHLY":"Mensual","WEEKLY":"Semanal","GOOGLE_MAPS_LINK":"Link de Google Maps","MINUTE":"Minuto","MINUTES":"Minutos","HOUR":"Hora","HOURS":"Horas","VE_ID":"Cédula de Identidad","ACCOUNT_VERIFIED_BY_CLINIKOS":"Esta cuenta ha sido verificada por Clinikos, así como sus afiliaciones con las siguientes instituciones","INBOX":"Bandeja de entrada","ACCEPTED":"Aceptado","DECLINED":"Declinado","NEEDS_ACTION":"Necesita acción","OVERDUE":"Atrasado","FILTER_BY":"Filtrar por","REFRESH":"Refrescar","LOADING":"Cargando","MINUTE_LEFT":"Un minuto restante","VALUE_MINUTES_LEFT":"{{value}} minutos restantes","PLAY":"Reproducir","PAUSE":"Pausar","STOP":"Detener","LOAD_MORE":"Cargar más","BILLING":"Facturación","DOCTOR":"Doctor","ASSISTANT":"Asistente","NUMBER_OF_DOCTORS":"Número de Doctores","NUMBER_OF_ASSISTANTS":"Número de Asistentes","EACH_DOCTOR":"Cada doctor","EACH_ASSISTANT":"Cada asistente","ROLE":"Rol","PAYMENT_METHODS":"Métodos de pago","UPGRADE":"Mejorar","TOTAL":"Total","BUY":"Comprar","TYPE":"Tipo","RECURRENT":"Recurrente","ACCEPT":"Aceptar","DECLINE":"Declinar","PREFERENCES":"Preferencias","BOOKING":"Agendar cita","PATTERN_NOT_VALID":"El patrón no es válido"}
|
package/types/errors.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
type ValidatorFunction<T, U> = (val: T, ...args: U[]) => boolean;
|
|
2
|
-
|
|
3
|
-
interface Validator<T, U = any> {
|
|
4
|
-
validate: ValidatorFunction<T, U>;
|
|
5
|
-
msg: string;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface ValidatorTypes {
|
|
9
|
-
required: Validator<string | number, boolean>;
|
|
10
|
-
min: Validator<number, number>;
|
|
11
|
-
max: Validator<number, number>;
|
|
12
|
-
minLength: Validator<string, number>;
|
|
13
|
-
maxLength: Validator<string, number>;
|
|
14
|
-
pattern: Validator<string, RegExp>;
|
|
15
|
-
equal: Validator<string, string>;
|
|
16
|
-
numberIsEqual: Validator<number, number>;
|
|
17
|
-
email: Validator<string, boolean>;
|
|
18
|
-
password: Validator<string, boolean>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type ValidatorParams = {
|
|
22
|
-
[K in keyof ValidatorTypes]: ValidatorTypes[K] extends Validator<any, infer U>
|
|
23
|
-
? U
|
|
24
|
-
: never;
|
|
25
|
-
};
|
|
26
|
-
export type ValidatorErrorMessage = {
|
|
27
|
-
[K in keyof ValidatorTypes]: string;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const regex = {
|
|
31
|
-
email:
|
|
32
|
-
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
33
|
-
password:
|
|
34
|
-
/^(?!.*\s)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[~`!@#$%^&*()--+={}[\]|:;"'<>,.?/_₹]).{8,24}$/,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const errors: ValidatorTypes = {
|
|
38
|
-
required: {
|
|
39
|
-
validate: (val) => Boolean(val),
|
|
40
|
-
msg: "REQUIRED",
|
|
41
|
-
},
|
|
42
|
-
min: {
|
|
43
|
-
validate: (val, min) => val >= min,
|
|
44
|
-
msg: "VALUE_LOW",
|
|
45
|
-
},
|
|
46
|
-
max: {
|
|
47
|
-
validate: (val, max) => val <= max,
|
|
48
|
-
msg: "VALUE_HIGH",
|
|
49
|
-
},
|
|
50
|
-
minLength: {
|
|
51
|
-
validate: (val = "", min) => val.length >= min,
|
|
52
|
-
msg: "TOO_SHORT",
|
|
53
|
-
},
|
|
54
|
-
maxLength: {
|
|
55
|
-
validate: (val = "", max) => val.length <= max,
|
|
56
|
-
msg: "TOO_LONG",
|
|
57
|
-
},
|
|
58
|
-
pattern: {
|
|
59
|
-
validate: (val, pattern) => new RegExp(pattern).test(val),
|
|
60
|
-
msg: "PATTERN_INVALID",
|
|
61
|
-
},
|
|
62
|
-
equal: {
|
|
63
|
-
validate: (val, comparison) => val === comparison,
|
|
64
|
-
msg: "NOT_EQUAL",
|
|
65
|
-
},
|
|
66
|
-
numberIsEqual: {
|
|
67
|
-
validate: (val, comparison) => val === comparison,
|
|
68
|
-
msg: "NOT_EQUAL",
|
|
69
|
-
},
|
|
70
|
-
email: {
|
|
71
|
-
validate: (val) => new RegExp(regex.email).test(val),
|
|
72
|
-
msg: "INVALID_EMAIL",
|
|
73
|
-
},
|
|
74
|
-
password: {
|
|
75
|
-
validate: (val) => new RegExp(regex.password).test(val),
|
|
76
|
-
msg: "INVALID_PASSWORD",
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
class NextUIError {
|
|
81
|
-
isInvalid: boolean;
|
|
82
|
-
errorMessage: string;
|
|
83
|
-
|
|
84
|
-
constructor(bool: boolean = false, msg: string = "") {
|
|
85
|
-
this.isInvalid = bool;
|
|
86
|
-
this.errorMessage = bool ? msg : "";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const nxError = (bool?: boolean, msg?: string) =>
|
|
91
|
-
new NextUIError(bool, msg);
|