ngx-dsxlibrary 1.0.8 → 1.0.9

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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Valida que el control contenga un rango de fechas válido (dos fechas no nulas y válidas).
3
+ */
4
+ function dateRangeValidator(control) {
5
+ const dates = control.value;
6
+ // Verificar si el valor es un array con exactamente dos elementos
7
+ if (Array.isArray(dates) && dates.length === 2) {
8
+ const [startDate, endDate] = dates;
9
+ // Verificar que las fechas sean válidas y no nulas
10
+ if (startDate &&
11
+ endDate &&
12
+ !isNaN(new Date(startDate).getTime()) &&
13
+ !isNaN(new Date(endDate).getTime())) {
14
+ return null; // Válido
15
+ }
16
+ else {
17
+ return {
18
+ invalidDateRange: {
19
+ message: 'Ambas fechas deben ser válidas y no nulas.',
20
+ requiredLength: 2,
21
+ },
22
+ }; // Error si alguna fecha es nula o inválida
23
+ }
24
+ }
25
+ return null; // Si el control no contiene un array válido, no hay error
26
+ }
27
+ /**
28
+ * Valida que una fecha única esté dentro de un rango mínimo y máximo.
29
+ * @param minDate Fecha mínima permitida.
30
+ * @param maxDate Fecha máxima permitida.
31
+ */
32
+ function dateMinMaxValidator(minDate, maxDate) {
33
+ return (control) => {
34
+ const date = control.value;
35
+ // Verificar si el valor es una fecha válida
36
+ if (date && !isNaN(new Date(date).getTime())) {
37
+ const currentDate = new Date(date);
38
+ // Validar si la fecha está fuera del rango permitido
39
+ if (currentDate < minDate || currentDate > maxDate) {
40
+ return {
41
+ dateNotRange: {
42
+ message: `La fecha debe estar entre ${minDate.toLocaleDateString()} y ${maxDate.toLocaleDateString()}`,
43
+ minDate: minDate.toISOString(),
44
+ maxDate: maxDate.toISOString(),
45
+ },
46
+ };
47
+ }
48
+ return null; // Fecha válida y dentro del rango
49
+ }
50
+ return null;
51
+ };
52
+ }
53
+ /**
54
+ * Valida que al menos uno de los campos especificados esté lleno.
55
+ * @param fields Los nombres de los campos a validar.
56
+ */
57
+ function atLeastOneFieldRequiredValidator(fields) {
58
+ return (formGroup) => {
59
+ // Obtener el FormGroup para poder acceder a los controles
60
+ const form = formGroup;
61
+ // Verificar si al menos uno de los campos tiene un valor
62
+ const isAnyFieldFilled = fields.some((field) => {
63
+ const control = form.get(field);
64
+ return control?.value !== null && control?.value !== '';
65
+ });
66
+ // Si al menos un campo tiene un valor, la validación es exitosa
67
+ if (isAnyFieldFilled) {
68
+ return null; // Validación pasada
69
+ }
70
+ else {
71
+ // Construir el mensaje dinámico con los campos no llenados
72
+ const emptyFields = fields.filter((field) => {
73
+ const control = form.get(field);
74
+ return control?.value === null || control?.value === '';
75
+ });
76
+ const fieldNames = emptyFields.join(', ');
77
+ const message = `Debe completar al menos uno de los siguientes campos: ${fieldNames}.`;
78
+ // Si ninguno tiene valor, devolver el mensaje con el error
79
+ return {
80
+ atLeastOneRequired: {
81
+ message: message,
82
+ },
83
+ };
84
+ }
85
+ };
86
+ }
87
+
88
+ /**
89
+ * Generated bundle index. Do not edit.
90
+ */
91
+
92
+ export { atLeastOneFieldRequiredValidator, dateMinMaxValidator, dateRangeValidator };
93
+ //# sourceMappingURL=ngx-dsxlibrary-src-lib-validations.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngx-dsxlibrary-src-lib-validations.mjs","sources":["../../../projects/ngx-dsx/src/lib/validations/addons.validators.ts","../../../projects/ngx-dsx/src/lib/validations/ngx-dsxlibrary-src-lib-validations.ts"],"sourcesContent":["import { AbstractControl, FormGroup, ValidationErrors } from '@angular/forms';\r\n\r\n/**\r\n * Valida que el control contenga un rango de fechas válido (dos fechas no nulas y válidas).\r\n */\r\nexport function dateRangeValidator(\r\n control: AbstractControl\r\n): ValidationErrors | null {\r\n const dates: Date[] = control.value;\r\n\r\n // Verificar si el valor es un array con exactamente dos elementos\r\n if (Array.isArray(dates) && dates.length === 2) {\r\n const [startDate, endDate] = dates;\r\n\r\n // Verificar que las fechas sean válidas y no nulas\r\n if (\r\n startDate &&\r\n endDate &&\r\n !isNaN(new Date(startDate).getTime()) &&\r\n !isNaN(new Date(endDate).getTime())\r\n ) {\r\n return null; // Válido\r\n } else {\r\n return {\r\n invalidDateRange: {\r\n message: 'Ambas fechas deben ser válidas y no nulas.',\r\n requiredLength: 2,\r\n },\r\n }; // Error si alguna fecha es nula o inválida\r\n }\r\n }\r\n\r\n return null; // Si el control no contiene un array válido, no hay error\r\n}\r\n\r\n/**\r\n * Valida que una fecha única esté dentro de un rango mínimo y máximo.\r\n * @param minDate Fecha mínima permitida.\r\n * @param maxDate Fecha máxima permitida.\r\n */\r\nexport function dateMinMaxValidator(minDate: Date, maxDate: Date) {\r\n return (control: AbstractControl): ValidationErrors | null => {\r\n const date: Date = control.value;\r\n\r\n // Verificar si el valor es una fecha válida\r\n if (date && !isNaN(new Date(date).getTime())) {\r\n const currentDate = new Date(date);\r\n\r\n // Validar si la fecha está fuera del rango permitido\r\n if (currentDate < minDate || currentDate > maxDate) {\r\n return {\r\n dateNotRange: {\r\n message: `La fecha debe estar entre ${minDate.toLocaleDateString()} y ${maxDate.toLocaleDateString()}`,\r\n minDate: minDate.toISOString(),\r\n maxDate: maxDate.toISOString(),\r\n },\r\n };\r\n }\r\n\r\n return null; // Fecha válida y dentro del rango\r\n }\r\n\r\n return null;\r\n };\r\n}\r\n\r\n/**\r\n * Valida que al menos uno de los campos especificados esté lleno.\r\n * @param fields Los nombres de los campos a validar.\r\n */\r\nexport function atLeastOneFieldRequiredValidator(fields: string[]) {\r\n return (formGroup: AbstractControl): ValidationErrors | null => {\r\n // Obtener el FormGroup para poder acceder a los controles\r\n const form = formGroup as FormGroup;\r\n\r\n // Verificar si al menos uno de los campos tiene un valor\r\n const isAnyFieldFilled = fields.some((field) => {\r\n const control = form.get(field);\r\n return control?.value !== null && control?.value !== '';\r\n });\r\n\r\n // Si al menos un campo tiene un valor, la validación es exitosa\r\n if (isAnyFieldFilled) {\r\n return null; // Validación pasada\r\n } else {\r\n // Construir el mensaje dinámico con los campos no llenados\r\n const emptyFields = fields.filter((field) => {\r\n const control = form.get(field);\r\n return control?.value === null || control?.value === '';\r\n });\r\n\r\n const fieldNames = emptyFields.join(', ');\r\n const message = `Debe completar al menos uno de los siguientes campos: ${fieldNames}.`;\r\n\r\n // Si ninguno tiene valor, devolver el mensaje con el error\r\n return {\r\n atLeastOneRequired: {\r\n message: message,\r\n },\r\n };\r\n }\r\n };\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAEA;;AAEG;AACG,SAAU,kBAAkB,CAChC,OAAwB,EAAA;AAExB,IAAA,MAAM,KAAK,GAAW,OAAO,CAAC,KAAK;;AAGnC,IAAA,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;AAC9C,QAAA,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,KAAK;;AAGlC,QAAA,IACE,SAAS;YACT,OAAO;YACP,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;AACrC,YAAA,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,EACnC;YACA,OAAO,IAAI,CAAC;;aACP;YACL,OAAO;AACL,gBAAA,gBAAgB,EAAE;AAChB,oBAAA,OAAO,EAAE,4CAA4C;AACrD,oBAAA,cAAc,EAAE,CAAC;AAClB,iBAAA;AACF,aAAA,CAAC;;;IAIN,OAAO,IAAI,CAAC;AACd;AAEA;;;;AAIG;AACa,SAAA,mBAAmB,CAAC,OAAa,EAAE,OAAa,EAAA;IAC9D,OAAO,CAAC,OAAwB,KAA6B;AAC3D,QAAA,MAAM,IAAI,GAAS,OAAO,CAAC,KAAK;;AAGhC,QAAA,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAA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GAAG;;YAGtF,OAAO;AACL,gBAAA,kBAAkB,EAAE;AAClB,oBAAA,OAAO,EAAE,OAAO;AACjB,iBAAA;aACF;;AAEL,KAAC;AACH;;ACtGA;;AAEG;;;;"}
@@ -1,5 +1,5 @@
1
1
  export * from './src/column.model';
2
+ export * from './src/extensions.model';
2
3
  export * from './src/field-config.model';
3
4
  export * from './src/response-http.model';
4
- export * from './src/datevalidate.model';
5
5
  export * from './src/securityParameter.model';
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ngx-dsxlibrary",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Libreria para control de código automatizado.",
5
5
  "author": "DevSoftXela <cfuentes1985@hotmail.com>",
6
6
  "peerDependencies": {
@@ -29,6 +29,10 @@
29
29
  "types": "./src/lib/injections/index.d.ts",
30
30
  "default": "./fesm2022/ngx-dsxlibrary-src-lib-injections.mjs"
31
31
  },
32
+ "./src/lib/models": {
33
+ "types": "./src/lib/models/index.d.ts",
34
+ "default": "./fesm2022/ngx-dsxlibrary-src-lib-models.mjs"
35
+ },
32
36
  "./src/lib/interceptors": {
33
37
  "types": "./src/lib/interceptors/index.d.ts",
34
38
  "default": "./fesm2022/ngx-dsxlibrary-src-lib-interceptors.mjs"
@@ -41,9 +45,9 @@
41
45
  "types": "./src/lib/services/index.d.ts",
42
46
  "default": "./fesm2022/ngx-dsxlibrary-src-lib-services.mjs"
43
47
  },
44
- "./src/lib/models": {
45
- "types": "./src/lib/models/index.d.ts",
46
- "default": "./fesm2022/ngx-dsxlibrary-src-lib-models.mjs"
48
+ "./src/lib/validations": {
49
+ "types": "./src/lib/validations/index.d.ts",
50
+ "default": "./fesm2022/ngx-dsxlibrary-src-lib-validations.mjs"
47
51
  }
48
52
  }
49
53
  }
@@ -1,5 +1,5 @@
1
1
  export * from './src/column.model';
2
+ export * from './src/extensions.model';
2
3
  export * from './src/field-config.model';
3
4
  export * from './src/response-http.model';
4
- export * from './src/datevalidate.model';
5
5
  export * from './src/securityParameter.model';
@@ -0,0 +1,16 @@
1
+ import { AbstractControl, ValidationErrors } from '@angular/forms';
2
+ /**
3
+ * Valida que el control contenga un rango de fechas válido (dos fechas no nulas y válidas).
4
+ */
5
+ export declare function dateRangeValidator(control: AbstractControl): ValidationErrors | null;
6
+ /**
7
+ * Valida que una fecha única esté dentro de un rango mínimo y máximo.
8
+ * @param minDate Fecha mínima permitida.
9
+ * @param maxDate Fecha máxima permitida.
10
+ */
11
+ export declare function dateMinMaxValidator(minDate: Date, maxDate: Date): (control: AbstractControl) => ValidationErrors | null;
12
+ /**
13
+ * Valida que al menos uno de los campos especificados esté lleno.
14
+ * @param fields Los nombres de los campos a validar.
15
+ */
16
+ export declare function atLeastOneFieldRequiredValidator(fields: string[]): (formGroup: AbstractControl) => ValidationErrors | null;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="ngx-dsxlibrary/src/lib/validations" />
5
+ export * from './public-api';
@@ -0,0 +1 @@
1
+ export * from './addons.validators';
Binary file