@jvsoft/utils 0.0.13-alpha.4 → 0.0.13-alpha.6

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.
Files changed (119) hide show
  1. package/classes/data-model.d.ts +25 -0
  2. package/fesm2022/jvsoft-utils-src-functions.mjs +1450 -0
  3. package/fesm2022/jvsoft-utils-src-functions.mjs.map +1 -0
  4. package/fesm2022/jvsoft-utils-src-interfaces.mjs +6 -0
  5. package/fesm2022/jvsoft-utils-src-interfaces.mjs.map +1 -0
  6. package/fesm2022/jvsoft-utils-src-pipes.mjs +290 -0
  7. package/fesm2022/jvsoft-utils-src-pipes.mjs.map +1 -0
  8. package/fesm2022/jvsoft-utils.mjs +1867 -0
  9. package/fesm2022/jvsoft-utils.mjs.map +1 -0
  10. package/functions/base64.d.ts +26 -0
  11. package/functions/browser.d.ts +1 -0
  12. package/functions/crypto-js.d.ts +2 -0
  13. package/functions/date.d.ts +3 -0
  14. package/functions/email.d.ts +2 -0
  15. package/functions/file.d.ts +10 -0
  16. package/functions/forms.d.ts +23 -0
  17. package/functions/http-client.d.ts +2 -0
  18. package/functions/index.d.ts +1 -0
  19. package/functions/local-storage.d.ts +29 -0
  20. package/functions/mat-form-controls/autocomplete.d.ts +51 -0
  21. package/functions/mat-form-controls/index.d.ts +2 -0
  22. package/functions/number.d.ts +2 -0
  23. package/functions/object-transformation.d.ts +2 -0
  24. package/functions/objects-arrays.d.ts +147 -0
  25. package/functions/public-api.d.ts +16 -0
  26. package/functions/string.d.ts +23 -0
  27. package/functions/sweetalert.d.ts +5 -0
  28. package/functions/utiles.d.ts +1 -0
  29. package/index.d.ts +5 -0
  30. package/{src/interfaces/datos.ts → interfaces/datos.d.ts} +1 -2
  31. package/interfaces/index.d.ts +1 -0
  32. package/interfaces/public-api.d.ts +1 -0
  33. package/package.json +28 -12
  34. package/pipes/data-en-lista.pipe.d.ts +8 -0
  35. package/pipes/date-diff-string.pipe.d.ts +17 -0
  36. package/pipes/filtro.pipe.d.ts +18 -0
  37. package/pipes/form-control-is-required.pipe.d.ts +9 -0
  38. package/pipes/index.d.ts +1 -0
  39. package/pipes/json-parse.pipe.d.ts +7 -0
  40. package/pipes/no-sanitize.pipe.d.ts +10 -0
  41. package/pipes/public-api.d.ts +8 -0
  42. package/pipes/tipo-valor-funcion.pipe.d.ts +9 -0
  43. package/pipes/zero-fill.pipe.d.ts +8 -0
  44. package/public-api.d.ts +4 -0
  45. package/src/functions/base64.d.ts +26 -0
  46. package/src/functions/browser.d.ts +1 -0
  47. package/src/functions/crypto-js.d.ts +2 -0
  48. package/src/functions/date.d.ts +3 -0
  49. package/src/functions/email.d.ts +2 -0
  50. package/src/functions/file.d.ts +10 -0
  51. package/src/functions/forms.d.ts +23 -0
  52. package/src/functions/http-client.d.ts +2 -0
  53. package/src/functions/index.d.ts +5 -0
  54. package/src/functions/local-storage.d.ts +29 -0
  55. package/src/functions/mat-form-controls/autocomplete.d.ts +51 -0
  56. package/src/functions/mat-form-controls/index.d.ts +2 -0
  57. package/src/functions/number.d.ts +2 -0
  58. package/src/functions/object-transformation.d.ts +2 -0
  59. package/src/functions/objects-arrays.d.ts +147 -0
  60. package/src/functions/public-api.d.ts +16 -0
  61. package/src/functions/string.d.ts +23 -0
  62. package/src/functions/sweetalert.d.ts +5 -0
  63. package/src/functions/utiles.d.ts +1 -0
  64. package/src/interfaces/datos.d.ts +4 -0
  65. package/src/interfaces/index.d.ts +5 -0
  66. package/src/interfaces/public-api.d.ts +1 -0
  67. package/src/pipes/data-en-lista.pipe.d.ts +8 -0
  68. package/src/pipes/date-diff-string.pipe.d.ts +17 -0
  69. package/src/pipes/filtro.pipe.d.ts +18 -0
  70. package/src/pipes/form-control-is-required.pipe.d.ts +9 -0
  71. package/src/pipes/index.d.ts +5 -0
  72. package/src/pipes/json-parse.pipe.d.ts +7 -0
  73. package/src/pipes/no-sanitize.pipe.d.ts +10 -0
  74. package/src/pipes/public-api.d.ts +8 -0
  75. package/src/pipes/tipo-valor-funcion.pipe.d.ts +9 -0
  76. package/src/pipes/zero-fill.pipe.d.ts +8 -0
  77. package/CHANGELOG.md +0 -25
  78. package/ng-package.json +0 -7
  79. package/src/classes/data-model.ts +0 -150
  80. package/src/functions/base64.ts +0 -8
  81. package/src/functions/browser.ts +0 -20
  82. package/src/functions/crypto-js.ts +0 -29
  83. package/src/functions/date.ts +0 -23
  84. package/src/functions/email.ts +0 -17
  85. package/src/functions/file.ts +0 -138
  86. package/src/functions/forms.ts +0 -251
  87. package/src/functions/http-client.ts +0 -110
  88. package/src/functions/index.ts +0 -1
  89. package/src/functions/local-storage.ts +0 -102
  90. package/src/functions/mat-form-controls/autocomplete.ts +0 -205
  91. package/src/functions/mat-form-controls/index.ts +0 -6
  92. package/src/functions/ng-package.json +0 -5
  93. package/src/functions/number.ts +0 -85
  94. package/src/functions/object-transformation.ts +0 -37
  95. package/src/functions/objects-arrays.ts +0 -321
  96. package/src/functions/public-api.ts +0 -19
  97. package/src/functions/string.ts +0 -68
  98. package/src/functions/sweetalert.ts +0 -95
  99. package/src/functions/utiles.ts +0 -20
  100. package/src/interfaces/index.ts +0 -1
  101. package/src/interfaces/ng-package.json +0 -5
  102. package/src/interfaces/otros.ts +0 -0
  103. package/src/interfaces/public-api.ts +0 -3
  104. package/src/interfaces/routes.ts +0 -42
  105. package/src/pipes/data-en-lista.pipe.ts +0 -40
  106. package/src/pipes/date-diff-string.pipe.ts +0 -117
  107. package/src/pipes/filtro.pipe.ts +0 -64
  108. package/src/pipes/form-control-is-required.pipe.ts +0 -17
  109. package/src/pipes/index.ts +0 -1
  110. package/src/pipes/json-parse.pipe.ts +0 -18
  111. package/src/pipes/ng-package.json +0 -5
  112. package/src/pipes/no-sanitize.pipe.ts +0 -12
  113. package/src/pipes/public-api.ts +0 -10
  114. package/src/pipes/tipo-valor-funcion.pipe.ts +0 -23
  115. package/src/pipes/zero-fill.pipe.ts +0 -19
  116. package/src/public-api.ts +0 -12
  117. package/tsconfig.lib.json +0 -18
  118. package/tsconfig.lib.prod.json +0 -11
  119. package/tsconfig.spec.json +0 -15
@@ -0,0 +1,1867 @@
1
+ import { Validators, FormGroup, FormControl, FormArray } from '@angular/forms';
2
+ import { untilDestroyed } from '@ngneat/until-destroy';
3
+ import { startWith, debounceTime, tap, isObservable, switchMap, of, finalize } from 'rxjs';
4
+ import { map } from 'rxjs/operators';
5
+ import { Buffer } from 'buffer';
6
+ import CryptoJS from 'crypto-js';
7
+ import { formatDate } from '@angular/common';
8
+ import { saveAs } from 'file-saver';
9
+ import { ReactiveFormConfig } from '@rxweb/reactive-form-validators';
10
+ import moment from 'moment';
11
+ import swal from 'sweetalert2';
12
+ import { jwtDecode } from 'jwt-decode';
13
+ import * as i0 from '@angular/core';
14
+ import { Pipe } from '@angular/core';
15
+ import * as i1 from '@angular/platform-browser';
16
+
17
+ /**
18
+ * Realiza una fusión profunda entre dos objetos, sin modificar el original.
19
+ * Si el valor en target no es un objeto, lo reemplaza directamente.
20
+ *
21
+ * @param source - Objeto fuente que se clonará y fusionará.
22
+ * @param target - Objeto destino cuyos valores se fusionarán.
23
+ * @returns Un nuevo objeto con la fusión profunda.
24
+ */
25
+ function deepMerge(source, target) {
26
+ // Crea un clon profundo sin usar JSON.parse(JSON.stringify)
27
+ let cloneSource = deepClone(source);
28
+ if (typeof target !== 'object' || target === null) {
29
+ return target;
30
+ }
31
+ if (typeof cloneSource !== 'object' || cloneSource === null) {
32
+ cloneSource = Array.isArray(target) ? [] : {};
33
+ }
34
+ for (const key of Object.keys(target)) {
35
+ const targetValue = target[key];
36
+ const sourceValue = cloneSource[key];
37
+ if (typeof targetValue === 'object' && targetValue !== null && !Array.isArray(targetValue)) {
38
+ cloneSource[key] = deepMerge(sourceValue, targetValue);
39
+ }
40
+ else {
41
+ cloneSource[key] = targetValue;
42
+ }
43
+ }
44
+ return cloneSource; // Retorna el clon y no modifica el original
45
+ }
46
+ /**
47
+ * Realiza una clonación profunda de un objeto, manejando funciones, fechas y arrays.
48
+ *
49
+ * @param obj - Objeto a clonar.
50
+ * @returns Una copia profunda del objeto.
51
+ */
52
+ function deepClone(obj) {
53
+ if (obj === null || typeof obj !== 'object') {
54
+ return obj; // Devuelve el valor si no es un objeto
55
+ }
56
+ // Manejar instancias de Date
57
+ if (obj instanceof Date) {
58
+ return new Date(obj.getTime());
59
+ }
60
+ // Manejar funciones devolviendo una copia directa
61
+ if (typeof obj === 'function') {
62
+ return obj.bind({}); // Devuelve una copia de la función enlazada a un contexto vacío
63
+ }
64
+ // Crear un nuevo objeto o array
65
+ const clonedObj = Array.isArray(obj) ? [] : {};
66
+ // Clonar recursivamente las propiedades del objeto
67
+ for (const key in obj) {
68
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
69
+ clonedObj[key] = deepClone(obj[key]);
70
+ }
71
+ }
72
+ return clonedObj;
73
+ }
74
+ /**
75
+ * Busca un elemento en un array o jerarquía de objetos según un campo y valor especificado.
76
+ *
77
+ * @param datosFn - Objeto con los parámetros de búsqueda: items, campo, valor y opcionalmente campoHijo.
78
+ * @returns El elemento encontrado o undefined si no existe.
79
+ */
80
+ function buscarPorCampo(datosFn) {
81
+ for (const item of datosFn.items) {
82
+ // Verifica si el campo coincide con el valor
83
+ if (item[datosFn.campo] === datosFn.valor) {
84
+ return item;
85
+ }
86
+ // Verifica si hay un campo hijo y si es un array
87
+ if (datosFn.campoHijo && item[datosFn.campoHijo] && Array.isArray(item[datosFn.campoHijo])) {
88
+ // Realiza la búsqueda recursiva en el campo hijo
89
+ const encontrado = buscarPorCampo({
90
+ items: item[datosFn.campoHijo], // Asegura el tipo correcto
91
+ campo: datosFn.campo,
92
+ valor: datosFn.valor,
93
+ campoHijo: datosFn.campoHijo,
94
+ });
95
+ // Si se encuentra el valor en el campo hijo, retorna el resultado
96
+ if (encontrado) {
97
+ return encontrado;
98
+ }
99
+ }
100
+ }
101
+ // Si no se encuentra nada, retorna undefined
102
+ return undefined;
103
+ }
104
+ /**
105
+ * Suma los valores de las propiedades especificadas de un objeto.
106
+ *
107
+ * @param item - Objeto con las propiedades a sumar.
108
+ * @param campos - Array de nombres de las propiedades a sumar.
109
+ * @returns La suma de los valores de las propiedades.
110
+ */
111
+ function sumarPropiedades(item, campos) {
112
+ const datosSumar = campos.map(campo => (item[campo] * 1));
113
+ return datosSumar.reduce((a, b) => a + b, 0);
114
+ }
115
+ /**
116
+ * Verifica si el valor proporcionado es un número válido.
117
+ *
118
+ * @param value - Valor a verificar.
119
+ * @returns true si es un número, false en caso contrario.
120
+ */
121
+ function esNumero(value) {
122
+ return !isNaN(Number(value));
123
+ }
124
+ /**
125
+ * Suma los valores de las propiedades especificadas en un array de objetos.
126
+ *
127
+ * @param arrayObjetos - Array de objetos a procesar.
128
+ * @param campos - Array de nombres de las propiedades a sumar.
129
+ * @returns Objeto con la suma de cada propiedad.
130
+ */
131
+ function sumarObjetos(arrayObjetos, campos) {
132
+ return arrayObjetos.reduce((accumulator, item) => {
133
+ campos.forEach(campo => {
134
+ const valor = Number(item[campo]);
135
+ if (!isNaN(valor)) {
136
+ accumulator[campo] = (accumulator[campo] ?? 0) + valor;
137
+ }
138
+ });
139
+ return accumulator;
140
+ }, {});
141
+ }
142
+ /**
143
+ * Obtiene los valores únicos de un array.
144
+ *
145
+ * @param array - Array de valores.
146
+ * @returns Array con los valores únicos.
147
+ */
148
+ function getUniqueValues(array) {
149
+ return array.filter((currentValue, index, arr) => (arr.indexOf(currentValue) === index));
150
+ }
151
+ /**
152
+ * Obtiene los objetos únicos de un array según una propiedad específica.
153
+ *
154
+ * @param objetos - Array de objetos.
155
+ * @param campo - Nombre de la propiedad para determinar unicidad.
156
+ * @returns Array de objetos únicos por la propiedad.
157
+ */
158
+ function getUniqueValuesByProperty(objetos, campo) {
159
+ const objetosUnicos = {};
160
+ objetos.forEach(objeto => {
161
+ // Verificar si el objeto tiene el campo especificado
162
+ // @ts-ignore
163
+ if (objeto.hasOwnProperty(campo)) {
164
+ // @ts-ignore
165
+ const valorCampo = objeto[campo];
166
+ // Utilizar el valor del campo como clave en un objeto para asegurar que no haya duplicados
167
+ objetosUnicos[valorCampo] = objeto;
168
+ }
169
+ });
170
+ // Convertir el objeto de claves únicas de vuelta a una lista de objetos
171
+ return Object.values(objetosUnicos);
172
+ }
173
+ /**
174
+ * Ordena un array de valores numéricos o alfabéticos.
175
+ *
176
+ * @param array - Array a ordenar.
177
+ * @param numeros - Si es true, ordena como números.
178
+ * @param sentido - 'ASC' para ascendente, 'DESC' para descendente.
179
+ * @returns Array ordenado.
180
+ */
181
+ function ordenarArray(array, numeros = false, sentido = 'ASC') {
182
+ if (numeros) {
183
+ if (sentido != 'ASC') {
184
+ return array.sort((a, b) => b - a);
185
+ }
186
+ return array.sort((a, b) => a - b);
187
+ }
188
+ return array.sort((a, b) => (a > b) ? 1 : ((b > a) ? -1 : 0));
189
+ }
190
+ /**
191
+ * Ordena un array de objetos por una propiedad específica.
192
+ *
193
+ * @param objData - Array de objetos a ordenar.
194
+ * @param propiedad - Propiedad por la que se ordena.
195
+ * @param numeros - (Obsoleto) Si es true, ordena como números.
196
+ * @returns Array ordenado.
197
+ */
198
+ function ordenarPorPropiedad(objData, propiedad, /**@deprecated*/ numeros = false) {
199
+ return ordenarPorPropiedades(objData, { propiedades: [propiedad], direcciones: ['asc'] });
200
+ }
201
+ /**
202
+ * Ordena un array de objetos por varias propiedades y direcciones.
203
+ *
204
+ * @param arr - Array de objetos a ordenar.
205
+ * @param options - Opciones con propiedades y direcciones de orden.
206
+ * @returns Array ordenado.
207
+ */
208
+ function ordenarPorPropiedades(arr, options) {
209
+ const { propiedades, direcciones = [] } = options;
210
+ const orden = direcciones.map(d => d === 'desc' ? -1 : 1);
211
+ return [...arr].sort((a, b) => {
212
+ return propiedades.reduce((acc, propiedad, index) => {
213
+ if (acc !== 0)
214
+ return acc; // Si ya hay diferencia, no seguir comparando
215
+ const aValue = a[propiedad];
216
+ const bValue = b[propiedad];
217
+ if (typeof aValue === 'string' && typeof bValue === 'string') {
218
+ return aValue.localeCompare(bValue) * orden[index]; // 🔹 Comparación alfabética
219
+ }
220
+ if (typeof aValue === 'number' && typeof bValue === 'number') {
221
+ return (aValue - bValue) * orden[index]; // 🔹 Comparación numérica
222
+ }
223
+ return 0; // En caso de valores no comparables
224
+ }, 0);
225
+ });
226
+ }
227
+ /**
228
+ * Agrupa los elementos de un array según una clave o función de clave.
229
+ *
230
+ * @param array - Array de objetos a agrupar.
231
+ * @param key - Propiedad o función para agrupar.
232
+ * @returns Objeto con los grupos por clave.
233
+ */
234
+ function groupBy(array, key) {
235
+ const keyFn = key instanceof Function ? key : (obj) => obj[key];
236
+ return array.reduce((objectsByKeyValue, obj) => {
237
+ const value = keyFn(obj);
238
+ objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
239
+ return objectsByKeyValue;
240
+ }, {});
241
+ }
242
+ /**
243
+ * Agrupa y anida los elementos de un array según una lista de propiedades.
244
+ *
245
+ * @param arr - Array de objetos a agrupar.
246
+ * @param properties - Propiedades para agrupar de forma anidada.
247
+ * @returns Objeto anidado por los grupos de propiedades.
248
+ */
249
+ function nestGroupsBy(arr, properties) {
250
+ const fnGroupBy = (conversions, property2) => {
251
+ return conversions.reduce((acc, obj) => {
252
+ const key = obj[property2];
253
+ if (!acc[key]) {
254
+ acc[key] = [];
255
+ }
256
+ acc[key].push(obj);
257
+ return acc;
258
+ }, {});
259
+ };
260
+ properties = Array.from(properties);
261
+ if (properties.length === 1) {
262
+ return fnGroupBy(arr, properties[0]);
263
+ }
264
+ const property = properties.shift();
265
+ const grouped = fnGroupBy(arr, property);
266
+ Object.keys(grouped).forEach(key => {
267
+ grouped[key] = nestGroupsBy(grouped[key], Array.from(properties));
268
+ });
269
+ return grouped;
270
+ }
271
+ /**
272
+ * Obtiene un valor de un objeto usando una ruta de propiedad anidada.
273
+ *
274
+ * @param obj - Objeto de entrada.
275
+ * @param path - Ruta en formato punto (ej: "cliente.orden").
276
+ * @returns El valor encontrado o undefined si no existe.
277
+ */
278
+ function getValueByPath(obj, path) {
279
+ return path.split('.').reduce((acc, key) => acc?.[key], obj);
280
+ }
281
+ /**
282
+ * Retorna el valor máximo del campo especificado (incluso anidado) en un arreglo de objetos.
283
+ *
284
+ * @param data - Lista de objetos a procesar.
285
+ * @param campo - Nombre del campo a evaluar, puede ser anidado (ej. "campo.orden").
286
+ * @param incrementar - Si es true, retorna el valor máximo + 1. Por defecto es true.
287
+ * @returns El valor máximo encontrado, posiblemente incrementado.
288
+ */
289
+ function obtenerUltimoOrden(data, campo, incrementar = true) {
290
+ const max = data.reduce((mayor, item) => {
291
+ const valor = Number(getValueByPath(item, campo)) || 0;
292
+ return valor > mayor ? valor : mayor;
293
+ }, 0);
294
+ return incrementar ? max + 1 : max;
295
+ }
296
+ /**
297
+ * Elimina una o varias columnas específicas (por índice) de una tabla representada como array de arrays.
298
+ *
299
+ * @param data - Array de filas (cada fila debe ser un array).
300
+ * @param columnIndex - Índice o lista de índices de las columnas a eliminar.
301
+ * @returns Nuevo array con las columnas eliminadas.
302
+ */
303
+ function eliminarColumnaPorIndex(data, columnIndex) {
304
+ if (!Array.isArray(data))
305
+ return [];
306
+ // Normalizar a array único y ordenado (descendente para evitar reindexación al splicing)
307
+ const indices = Array.isArray(columnIndex)
308
+ ? [...new Set(columnIndex)].filter((i) => (typeof i === 'number' && i >= 0)).sort((a, b) => b - a)
309
+ : [columnIndex];
310
+ return data.map((row) => {
311
+ if (!Array.isArray(row))
312
+ return row;
313
+ const newRow = [...row];
314
+ for (const index of indices) {
315
+ if (index >= 0 && index < newRow.length) {
316
+ newRow.splice(index, 1);
317
+ }
318
+ }
319
+ return newRow;
320
+ });
321
+ }
322
+ /**
323
+ * Elimina elementos duplicados de un array de objetos según claves específicas.
324
+ *
325
+ * @param array - Array de objetos.
326
+ * @param claves - Claves para determinar unicidad. Si no se especifica, compara todo el objeto.
327
+ * @returns Array sin duplicados.
328
+ */
329
+ function eliminarDuplicados(array, claves) {
330
+ const unicos = new Map();
331
+ for (const item of array) {
332
+ const claveUnica = claves && claves.length > 0
333
+ ? claves.map(k => item[k]).join('|')
334
+ : JSON.stringify(item);
335
+ if (!unicos.has(claveUnica)) {
336
+ unicos.set(claveUnica, item);
337
+ }
338
+ }
339
+ return Array.from(unicos.values());
340
+ }
341
+ /**
342
+ * Elimina elementos de un array origen que estén presentes en otro array, según claves específicas.
343
+ *
344
+ * @param origen - Array original.
345
+ * @param elementosAEliminar - Elementos a eliminar del array origen.
346
+ * @param claves - Claves para comparar los objetos. Si no se especifica, compara todo el objeto.
347
+ * @returns Array filtrado sin los elementos eliminados.
348
+ */
349
+ function eliminarElementos(origen, elementosAEliminar, claves) {
350
+ const clavesSet = new Set();
351
+ for (const item of elementosAEliminar) {
352
+ const key = claves && claves.length > 0
353
+ ? claves.map(k => item[k]).join('|')
354
+ : JSON.stringify(item);
355
+ clavesSet.add(key);
356
+ }
357
+ return origen.filter(item => {
358
+ const key = claves && claves.length > 0
359
+ ? claves.map(k => item[k]).join('|')
360
+ : JSON.stringify(item);
361
+ return !clavesSet.has(key);
362
+ });
363
+ }
364
+
365
+ /**
366
+ * Devuelve un valor de visualización para un elemento buscado.
367
+ * Compatible con listas simples, objetos y campos múltiples.
368
+ */
369
+ function mostrarValorEnBusqueda(campos, idxSel) {
370
+ const buscarEnLista = (lista) => {
371
+ if (!lista)
372
+ return null;
373
+ if (campos.campoId === '*object*' || campos.campoId === '*objeto*') {
374
+ return lista.find((x) => JSON.stringify(x).trim() === JSON.stringify(idxSel).trim());
375
+ }
376
+ return lista.find((x) => x[campos.campoId] === idxSel);
377
+ };
378
+ const impDataMostrar = () => {
379
+ let vD = buscarEnLista(campos.lista) || (campos.opcExtra && buscarEnLista(campos.opcExtra));
380
+ if (!vD)
381
+ return '';
382
+ if (Array.isArray(campos.campoValue)) {
383
+ return campos.campoValue.map((vCampo) => vD[vCampo] ?? '').join(' - ').trim();
384
+ }
385
+ return (vD[campos.campoValue] ?? '').trim();
386
+ };
387
+ if (esNumero(idxSel)) {
388
+ if ((idxSel > 0 && campos.lista?.length) || (idxSel && typeof idxSel === 'object')) {
389
+ return impDataMostrar();
390
+ }
391
+ }
392
+ else if (campos.lista?.length) {
393
+ return impDataMostrar();
394
+ }
395
+ return '';
396
+ }
397
+ /**
398
+ * Filtra datos locales de un array basado en un valor de búsqueda.
399
+ */
400
+ function filtrarDatosLocal(data, value, campoBuscar) {
401
+ if (!value)
402
+ return data;
403
+ const normalizar = (val) => val?.toString()?.toLowerCase() ?? '';
404
+ const esNum = !isNaN(Number(value));
405
+ return data.filter(item => {
406
+ const campos = Array.isArray(campoBuscar) ? campoBuscar : [campoBuscar];
407
+ return campos.some(campo => {
408
+ const campoVal = item[campo];
409
+ if (campoVal == null)
410
+ return false;
411
+ return esNum
412
+ ? campoVal.toString().includes(value.toString())
413
+ : normalizar(campoVal).includes(normalizar(value));
414
+ });
415
+ });
416
+ }
417
+ /**
418
+ * Vincula un FormControl a datos locales para autocompletado.
419
+ */
420
+ function changeSelectData(objThis, { formControl, data, campoBuscar, variableResultado }) {
421
+ objThis.filtrados[variableResultado] = formControl.valueChanges.pipe(untilDestroyed(objThis)).pipe(startWith(''), map(value => data ? filtrarDatosLocal(data, value, campoBuscar) : []));
422
+ }
423
+ /**
424
+ * Vincula un FormControl a datos locales obtenidos de dataServidor o dataServidorSuscripcion.
425
+ */
426
+ function changeSelect(control, formControl, tipo, campoBuscar, campoFiltro = null) {
427
+ const filtro = campoFiltro ?? tipo;
428
+ control.filtrados[filtro] = formControl.valueChanges.pipe(untilDestroyed(control)).pipe(startWith(''), map(value => {
429
+ const partes = tipo.split('.');
430
+ const varN = control.dataServidor?.[partes[0]]?.[partes[1]] ??
431
+ control.dataServidor?.[tipo] ??
432
+ control.dataServidorSuscripcion?.[tipo]?.getValue();
433
+ return varN ? filtrarDatosLocal(varN, value, campoBuscar) : [];
434
+ }));
435
+ }
436
+ /**
437
+ * Función genérica para vincular un FormControl con datos desde API o Promise.
438
+ * Preparada para migrar a signals en el futuro.
439
+ */
440
+ function changeSelectReformateado(config) {
441
+ const { objThis, tipoReq, formControl, queryService, campoId, minLength = 3, dataExtra = {}, dataExtraVariable = [], anonimo = false, variableResultado = tipoReq, } = config;
442
+ formControl.valueChanges.pipe(debounceTime(500), tap(() => {
443
+ objThis.filtrados[variableResultado + 'tmp'] = isObservable(objThis.filtrados[variableResultado])
444
+ ? []
445
+ : objThis.filtrados[variableResultado] || [];
446
+ if (objThis.filtrados[variableResultado] !== objThis.filtrados[variableResultado + 'tmp']) {
447
+ objThis.filtrados[variableResultado] = [];
448
+ }
449
+ objThis.isLoading = true;
450
+ }), switchMap(value => {
451
+ if (campoId) {
452
+ const existe = objThis.filtrados[variableResultado + 'tmp']
453
+ .findIndex((item) => item[campoId] === value);
454
+ if (existe >= 0) {
455
+ return of({ [tipoReq]: objThis.filtrados[variableResultado + 'tmp'] });
456
+ }
457
+ }
458
+ if (!value || value.length < minLength) {
459
+ objThis.isLoading = false;
460
+ return of({ [tipoReq]: [] });
461
+ }
462
+ const extraVars = Object.fromEntries(dataExtraVariable.map(v => [v.campo, v.ctrlValue.value]));
463
+ const query = queryService.getDataMethod('GET', tipoReq, { ...dataExtra, ...extraVars, txtBuscar: value }, anonimo);
464
+ if (esPromise(query)) {
465
+ return query.then((data) => ({ [tipoReq]: data[tipoReq] ?? [] }))
466
+ .finally(() => { objThis.isLoading = false; });
467
+ }
468
+ return query.pipe(finalize(() => { objThis.isLoading = false; }));
469
+ })).subscribe((data) => {
470
+ objThis.filtrados[variableResultado] = data[tipoReq] ?? [];
471
+ });
472
+ }
473
+ /**
474
+ * Alias para compatibilidad.
475
+ */
476
+ function changeSelectDataApi(objThis, dataFiltro) {
477
+ return changeSelectReformateado({
478
+ objThis,
479
+ tipoReq: dataFiltro.tipoReq,
480
+ formControl: dataFiltro.formControl,
481
+ queryService: dataFiltro.queryService,
482
+ campoId: dataFiltro.campoId,
483
+ minLength: dataFiltro.minLength,
484
+ dataExtra: dataFiltro.dataExtra,
485
+ dataExtraVariable: dataFiltro.dataExtraVariable,
486
+ anonimo: dataFiltro.anonimo,
487
+ variableResultado: dataFiltro.variableResultado,
488
+ });
489
+ }
490
+ /**
491
+ * Alias para compatibilidad.
492
+ */
493
+ function changeSelectApi(control, queryService, formControl, tipo, dataExtra = {}, dataExtraVariable = null, minLength = 1, anonimo = false) {
494
+ return changeSelectReformateado({
495
+ objThis: control,
496
+ tipoReq: tipo,
497
+ formControl,
498
+ queryService,
499
+ minLength,
500
+ dataExtra,
501
+ dataExtraVariable: dataExtraVariable ?? [],
502
+ anonimo,
503
+ });
504
+ }
505
+ /**
506
+ * Comprueba si un valor es una Promesa.
507
+ */
508
+ function esPromise(valor) {
509
+ return !!valor && typeof valor.then === 'function';
510
+ }
511
+
512
+ function seleccionarTextoInput(event) {
513
+ event.target.select();
514
+ }
515
+
516
+ function b64Encode(val) {
517
+ return Buffer.from(val, 'binary').toString('base64');
518
+ }
519
+ function b64Decode(val) {
520
+ return Buffer.from(val, 'base64').toString('binary');
521
+ }
522
+ /**
523
+ * Codificar string a Base64 (UTF-8 seguro)
524
+ */
525
+ function encodeBase64String(str) {
526
+ const encoder = new TextEncoder();
527
+ const bytes = encoder.encode(str);
528
+ let binary = '';
529
+ bytes.forEach(b => binary += String.fromCharCode(b));
530
+ return btoa(binary);
531
+ }
532
+ /**
533
+ * Decodificar Base64 a string (UTF-8 seguro)
534
+ */
535
+ function decodeBase64String(b64) {
536
+ const binary = atob(b64);
537
+ const bytes = new Uint8Array(binary.length);
538
+ for (let i = 0; i < binary.length; i++) {
539
+ bytes[i] = binary.charCodeAt(i);
540
+ }
541
+ const decoder = new TextDecoder();
542
+ return decoder.decode(bytes);
543
+ }
544
+ /**
545
+ * Codificar un objeto a base64 (UTF-8 seguro)
546
+ */
547
+ function encodeBase64Object(obj) {
548
+ return encodeBase64String(JSON.stringify(obj));
549
+ }
550
+ /**
551
+ * Decodificar un base64 y obtener el objeto original
552
+ */
553
+ function decodeBase64Object(b64) {
554
+ return JSON.parse(decodeBase64String(b64));
555
+ }
556
+ /**
557
+ * Codificar archivo a Base64 (retorna solo el contenido, sin "data:...")
558
+ */
559
+ function encodeBase64File(file) {
560
+ return new Promise((resolve, reject) => {
561
+ const reader = new FileReader();
562
+ reader.onload = () => {
563
+ const result = reader.result;
564
+ resolve(result.split(',')[1]); // quita el prefijo "data:...;base64,"
565
+ };
566
+ reader.onerror = reject;
567
+ reader.readAsDataURL(file);
568
+ });
569
+ }
570
+ /**
571
+ * Decodificar Base64 a Blob (para reconstruir archivos en Angular)
572
+ */
573
+ function decodeBase64ToBlob(b64, mimeType = 'application/octet-stream') {
574
+ const byteChars = atob(b64);
575
+ const byteNumbers = new Array(byteChars.length);
576
+ for (let i = 0; i < byteChars.length; i++) {
577
+ byteNumbers[i] = byteChars.charCodeAt(i);
578
+ }
579
+ return new Blob([new Uint8Array(byteNumbers)], { type: mimeType });
580
+ }
581
+
582
+ function getBrowserName() {
583
+ const agent = window.navigator.userAgent.toLowerCase();
584
+ switch (true) {
585
+ case agent.indexOf('edge') > -1:
586
+ return 'edge';
587
+ case agent.indexOf('opr') > -1 && !!window.opr:
588
+ return 'opera';
589
+ case agent.indexOf('chrome') > -1 && !!window.chrome:
590
+ return 'chrome';
591
+ case agent.indexOf('trident') > -1:
592
+ return 'ie';
593
+ case agent.indexOf('firefox') > -1:
594
+ return 'firefox';
595
+ case agent.indexOf('safari') > -1:
596
+ return 'safari';
597
+ default:
598
+ return 'other';
599
+ }
600
+ }
601
+
602
+ // import * as CryptoJS from 'crypto-js';
603
+ // var CryptoJS = require("crypto-js");
604
+ // Clave secreta (debe ser de 16, 24 o 32 caracteres)
605
+ const secretKey = CryptoJS.enc.Utf8.parse('JVSoftSecret@20615178350');
606
+ const iv = CryptoJS.enc.Utf8.parse('AnSalHuaJVSoft07'); // Debe ser de 16 bytes
607
+ // Función para encriptar texto
608
+ function encriptar(text) {
609
+ const encrypted = CryptoJS.AES.encrypt(text, secretKey, {
610
+ iv: iv,
611
+ mode: CryptoJS.mode.CBC,
612
+ padding: CryptoJS.pad.Pkcs7,
613
+ });
614
+ return encrypted.toString(); // Texto cifrado en Base64
615
+ }
616
+ // Función para desencriptar texto
617
+ function desencriptar(ciphertext) {
618
+ const decrypted = CryptoJS.AES.decrypt(ciphertext, secretKey, {
619
+ iv: iv,
620
+ mode: CryptoJS.mode.CBC,
621
+ padding: CryptoJS.pad.Pkcs7,
622
+ });
623
+ return decrypted.toString(CryptoJS.enc.Utf8);
624
+ }
625
+
626
+ function formatearFechaFormato(val, format = 'dd/MM/yyyy') {
627
+ return val ? formatDate(val, format, 'es-PE') : '';
628
+ }
629
+ function formatearFecha(val, hora = '00:00:00') {
630
+ if (val) {
631
+ if (val.length <= 10) {
632
+ val = val + ' ' + hora;
633
+ }
634
+ return new Date(val);
635
+ }
636
+ return val;
637
+ }
638
+ function formatearFechaCadena(fecha) {
639
+ const year = parseInt(fecha.substring(0, 4), 10);
640
+ const month = parseInt(fecha.substring(4, 6), 10) - 1;
641
+ const day = parseInt(fecha.substring(6, 8), 10);
642
+ return new Date(year, month, day);
643
+ }
644
+
645
+ function maskEmail(email) {
646
+ const [user, domain] = email.split("@");
647
+ if (user.length <= 2) {
648
+ return `${user[0]}***@${domain}`; // 🔹 Si el usuario es muy corto, no se oculta nada
649
+ }
650
+ if (user.length <= 4) {
651
+ return `${user[0]}***${user.slice(-1)}@${domain}`; // 🔹 Muestra 1 al inicio y 1 al final
652
+ }
653
+ return `${user.slice(0, 2)}***${user.slice(-2)}@${domain}`; // 🔹 Muestra 2 al inicio y 2 al final
654
+ }
655
+ function isEmail(email) {
656
+ return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
657
+ }
658
+
659
+ const mimeTypes = {
660
+ // Imágenes
661
+ 'jpg': 'image/jpeg',
662
+ 'jpeg': 'image/jpeg',
663
+ 'png': 'image/png',
664
+ 'gif': 'image/gif',
665
+ 'webp': 'image/webp',
666
+ 'svg': 'image/svg+xml',
667
+ 'ico': 'image/x-icon',
668
+ 'bmp': 'image/bmp',
669
+ // Documentos
670
+ 'pdf': 'application/pdf',
671
+ 'doc': 'application/msword',
672
+ 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
673
+ 'xls': 'application/vnd.ms-excel',
674
+ 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
675
+ 'ppt': 'application/vnd.ms-powerpoint',
676
+ 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
677
+ 'txt': 'text/plain',
678
+ 'csv': 'text/csv',
679
+ 'json': 'application/json',
680
+ 'xml': 'application/xml',
681
+ 'html': 'text/html',
682
+ // Audio
683
+ 'mp3': 'audio/mpeg',
684
+ 'wav': 'audio/wav',
685
+ 'ogg': 'audio/ogg',
686
+ 'm4a': 'audio/mp4',
687
+ // Video
688
+ 'mp4': 'video/mp4',
689
+ 'avi': 'video/x-msvideo',
690
+ 'mov': 'video/quicktime',
691
+ 'wmv': 'video/x-ms-wmv',
692
+ 'flv': 'video/x-flv',
693
+ 'webm': 'video/webm',
694
+ 'mkv': 'video/x-matroska',
695
+ // Archivos comprimidos
696
+ 'zip': 'application/zip',
697
+ 'rar': 'application/vnd.rar',
698
+ '7z': 'application/x-7z-compressed',
699
+ 'tar': 'application/x-tar',
700
+ 'gz': 'application/gzip',
701
+ 'bz2': 'application/x-bzip2',
702
+ // Otros formatos
703
+ 'js': 'application/javascript',
704
+ 'css': 'text/css',
705
+ 'ts': 'application/typescript',
706
+ 'md': 'text/markdown',
707
+ 'exe': 'application/octet-stream',
708
+ 'eot': 'application/vnd.ms-fontobject',
709
+ 'woff': 'font/woff',
710
+ 'woff2': 'font/woff2',
711
+ 'ttf': 'font/ttf',
712
+ 'otf': 'font/otf',
713
+ };
714
+ function obtenerMimeType(nombreArchivo) {
715
+ const extension = nombreArchivo.split('.').pop()?.toLowerCase();
716
+ return extension ? mimeTypes[extension] || 'application/octet-stream' : null;
717
+ }
718
+ function sanitizarNombreArchivo(nombre, reemplazo = '_') {
719
+ // 1. Quitar caracteres no válidos para nombres de archivo
720
+ const nombreSanitizado = nombre.replace(/[\/\\:*?"<>|]/g, reemplazo);
721
+ // 2. Reemplazar espacios múltiples o al inicio/final
722
+ const nombreLimpio = nombreSanitizado.trim().replace(/\s+/g, reemplazo);
723
+ // 3. Asegurar longitud máxima (opcional, aquí 255 caracteres)
724
+ return nombreLimpio.substring(0, 255);
725
+ }
726
+ function getDataArchivoFromPath(value, conTimeStamp = false) {
727
+ const partesPath = value.split('/');
728
+ const nombreCompleto = partesPath[partesPath.length - 1];
729
+ let timeStamp = 1;
730
+ let nombreSinTimeStamp = nombreCompleto;
731
+ const partesNombre = nombreCompleto.split('-');
732
+ if (partesNombre.length > 1) {
733
+ timeStamp = partesNombre[0] * 1;
734
+ partesNombre.shift();
735
+ nombreSinTimeStamp = partesNombre.join('-');
736
+ }
737
+ if (conTimeStamp) {
738
+ return {
739
+ nombre: nombreCompleto,
740
+ extension: nombreCompleto.split('.').pop(),
741
+ d: timeStamp,
742
+ fechaSubida: timeStamp ? new Date(timeStamp * 1000) : '',
743
+ };
744
+ }
745
+ return {
746
+ nombre: nombreSinTimeStamp,
747
+ extension: nombreSinTimeStamp.split('.').pop(),
748
+ d: timeStamp,
749
+ fechaSubida: timeStamp ? new Date(timeStamp * 1000) : '',
750
+ };
751
+ }
752
+ function convertirBytes(valor, unidadSalida = null, incluirUnidad = true) {
753
+ const unidades = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
754
+ const indiceEntrada = unidadSalida ? unidades.indexOf(unidadSalida) : 0;
755
+ if (indiceEntrada === -1) {
756
+ // Unidad de entrada no válida
757
+ return null;
758
+ }
759
+ let indiceActual = indiceEntrada;
760
+ let resultado = valor;
761
+ let cont = 0;
762
+ while (cont < 6 && (indiceActual < unidades.length - 1) && (resultado >= 1024)) {
763
+ resultado /= 1024;
764
+ indiceActual++;
765
+ }
766
+ if (incluirUnidad) {
767
+ return `${resultado.toFixed(2)} ${unidades[indiceActual]}`;
768
+ }
769
+ return resultado;
770
+ }
771
+ function downLoadFileStream(data, type, nombreArchivo) {
772
+ const blob = new Blob([data], { type });
773
+ saveAs(blob, nombreArchivo);
774
+ }
775
+
776
+ function establecerQuitarRequired(formulario, establecer = [], quitar = [], camposDisabled = []) {
777
+ establecer.forEach((control) => {
778
+ if (!formulario.get(control)?.hasValidator(Validators.required)) {
779
+ formulario.get(control)?.addValidators([Validators.required]);
780
+ formulario.get(control)?.enable();
781
+ formulario.get(control)?.updateValueAndValidity();
782
+ }
783
+ });
784
+ const deshabilitar = (strControl) => {
785
+ if (camposDisabled == 'todos') {
786
+ formulario.get(strControl)?.disable();
787
+ console.log(strControl);
788
+ }
789
+ else {
790
+ if (camposDisabled.includes(strControl)) {
791
+ formulario.get(strControl)?.disable();
792
+ }
793
+ }
794
+ };
795
+ quitar.forEach(control => {
796
+ if (formulario.get(control)?.hasValidator(Validators.required)) {
797
+ formulario.get(control)?.removeValidators([Validators.required]);
798
+ formulario.get(control)?.updateValueAndValidity();
799
+ }
800
+ deshabilitar(control);
801
+ });
802
+ }
803
+ function getFormValidationErrors(form) {
804
+ const result = [];
805
+ Object.keys(form.controls).forEach(key => {
806
+ const formProperty = form.get(key);
807
+ if (formProperty instanceof FormGroup) {
808
+ result.push(...getFormValidationErrors(formProperty));
809
+ }
810
+ const controlErrors = formProperty?.errors;
811
+ if (controlErrors) {
812
+ Object.keys(controlErrors).forEach(keyError => {
813
+ result.push({
814
+ control: key,
815
+ error: keyError,
816
+ value: controlErrors[keyError]
817
+ });
818
+ });
819
+ }
820
+ });
821
+ return result;
822
+ }
823
+ function mensajesErrorFormControl(control) {
824
+ if (!control || !control.errors || !control.touched)
825
+ return '';
826
+ ReactiveFormConfig.set({
827
+ // RxwebValidators
828
+ validationMessage: {
829
+ required: 'Es requerido',
830
+ numeric: 'Debe ser numérico valido',
831
+ // minLength: 'minimum length is {{1}}',
832
+ // maxLength: 'allowed max length is {{1}}',
833
+ },
834
+ });
835
+ const errorMessages = {
836
+ required: 'Es requerido',
837
+ numeric: 'Debe ser numérico válido',
838
+ min: `Valor mínimo permitido: ${control.errors['min']?.min}`,
839
+ minValue: 'Debe ser positivo',
840
+ minlength: `Mínimo ${control.errors['minlength']?.requiredLength} caracteres.`,
841
+ maxlength: `Caracteres ${control.errors['maxlength']?.actualLength}/${control.errors['maxlength']?.requiredLength}`,
842
+ email: 'No se cumple con el formato de Correo Electrónico',
843
+ isNumeric: 'Debe seleccionar una opción',
844
+ hasNumber: 'Se requiere al menos un número',
845
+ hasCapitalCase: 'Se requiere al menos una mayúscula',
846
+ hasSmallCase: 'Se requiere al menos una minúscula',
847
+ hasSpecialCharacters: 'Se requiere al menos un carácter especial',
848
+ NoPassswordMatch: 'La contraseña no coincide',
849
+ itemSelected: 'Debe seleccionar una opción de la lista',
850
+ inputMask: 'El formato ingresado no es válido',
851
+ };
852
+ // Devuelve el primer mensaje de error encontrado
853
+ for (const errorKey of Object.keys(control.errors)) {
854
+ if (errorMessages[errorKey]) {
855
+ return errorMessages[errorKey];
856
+ }
857
+ }
858
+ // Si el error tiene un mensaje personalizado, usarlo
859
+ return control.errors[Object.keys(control.errors)[0]]?.message || '';
860
+ }
861
+ function toFormData(formValue) {
862
+ const formData = new FormData();
863
+ Object.keys(formValue).forEach((key) => {
864
+ const value = formValue[key];
865
+ if (value === null || value === undefined) {
866
+ return; // Ignorar valores nulos o indefinidos
867
+ }
868
+ if (Array.isArray(value)) {
869
+ value.forEach((item, index) => {
870
+ if (typeof item === 'object' && item !== null) {
871
+ if ('file' in item) {
872
+ formData.append(`${key}[${index}]`, item.file);
873
+ }
874
+ else {
875
+ formData.append(`${key}[${index}]`, JSON.stringify(item));
876
+ }
877
+ }
878
+ else {
879
+ formData.append(`${key}[${index}]`, item.toString());
880
+ }
881
+ });
882
+ }
883
+ else if (typeof value === 'object') {
884
+ // Si es un objeto (pero no un array), convertirlo a JSON
885
+ formData.append(key, JSON.stringify(value));
886
+ }
887
+ else {
888
+ // Para valores primitivos (string, number, boolean)
889
+ formData.append(key, value.toString());
890
+ }
891
+ });
892
+ return formData;
893
+ }
894
+ function markAsTouchedWithoutEmitEvent(control) {
895
+ if (control instanceof FormControl) {
896
+ control.markAsTouched({ onlySelf: true });
897
+ control.updateValueAndValidity({ emitEvent: false });
898
+ }
899
+ else if (control instanceof FormGroup || control instanceof FormArray) {
900
+ Object.values(control.controls).forEach(childControl => {
901
+ markAsTouchedWithoutEmitEvent(childControl);
902
+ });
903
+ control.updateValueAndValidity({ emitEvent: false });
904
+ }
905
+ }
906
+ function setControlDesdeLista(config) {
907
+ const lista = config.lista$?.getValue() ?? [];
908
+ if (!lista.length)
909
+ return;
910
+ let seleccionado;
911
+ if (config.idProp && config.idValor !== undefined) {
912
+ seleccionado = lista.find((item) => item[config.idProp] === config.idValor);
913
+ }
914
+ else if (config.usarPrimeraOpcion) {
915
+ seleccionado = lista[0];
916
+ }
917
+ console.log(seleccionado);
918
+ if (!seleccionado)
919
+ return;
920
+ let valor;
921
+ if (config.selector) {
922
+ valor = config.selector(seleccionado);
923
+ }
924
+ else if (config.idProp) {
925
+ valor = seleccionado[config.idProp];
926
+ }
927
+ else {
928
+ valor = seleccionado;
929
+ }
930
+ if (config.formControl) {
931
+ config.formControl.setValue(valor);
932
+ }
933
+ else if (config.formGroup && config.controlName) {
934
+ const control = config.formGroup.get(config.controlName);
935
+ if (control instanceof FormControl) {
936
+ control.setValue(valor);
937
+ }
938
+ }
939
+ }
940
+ function transformarFechasPorNombreDeCampo(formValue) {
941
+ const retData = {};
942
+ Object.entries(formValue).forEach(([key, value]) => {
943
+ // ✅ No procesar Blob o File
944
+ if (value instanceof Blob || value instanceof File) {
945
+ retData[key] = value;
946
+ return;
947
+ }
948
+ if (value instanceof Date) {
949
+ if (/^d[A-Za-z]+/.test(key)) {
950
+ retData[key] = moment(value).format('YYYY-MM-DD');
951
+ }
952
+ else {
953
+ retData[key] = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate(), value.getHours(), value.getMinutes(), value.getSeconds()));
954
+ }
955
+ }
956
+ else if (/^dt[A-Za-z]+/.test(key) && typeof value === 'string') {
957
+ if (/\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d{3}/.test(value)) {
958
+ retData[key] = new Date(value + 'Z');
959
+ }
960
+ else if (/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(value) || /\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}/.test(value)) {
961
+ retData[key] = new Date(value + ':00.000Z');
962
+ }
963
+ else {
964
+ console.warn('FECHA INVALIDA AL ENVIAR (FormInter):', key, value);
965
+ retData[key] = value;
966
+ }
967
+ }
968
+ else if (Array.isArray(value)) {
969
+ if (value.every(v => v instanceof File || v instanceof Blob)) {
970
+ retData[key] = value;
971
+ }
972
+ else {
973
+ retData[key] = value.map(item => typeof item === 'object' && item !== null
974
+ ? transformarFechasPorNombreDeCampo(item)
975
+ : item);
976
+ }
977
+ }
978
+ else if (typeof value === 'object' && value !== null) {
979
+ retData[key] = transformarFechasPorNombreDeCampo(value);
980
+ }
981
+ else {
982
+ retData[key] = value;
983
+ }
984
+ });
985
+ return retData;
986
+ }
987
+
988
+ function mensajeAlerta(tipo, titulo, mensaje, opciones) {
989
+ opciones = {
990
+ ...{
991
+ heightAuto: false,
992
+ title: titulo,
993
+ html: mensaje,
994
+ icon: tipo,
995
+ confirmButtonText: 'Aceptar',
996
+ // customClass: {
997
+ // confirmButton: 'btn btn-lg btn-outline-success mx-2',
998
+ // cancelButton: 'btn btn-lg btn-outline-dark mx-2'
999
+ // },
1000
+ // buttonsStyling: false
1001
+ },
1002
+ ...opciones
1003
+ };
1004
+ return swal.fire(opciones);
1005
+ }
1006
+ function mensajeTimer(tipo, titulo, mensaje, milisegundos = 3000, showLoading = true, opciones) {
1007
+ let timerInterval;
1008
+ opciones = {
1009
+ ...{
1010
+ heightAuto: false,
1011
+ title: titulo,
1012
+ html: mensaje + '<br> Se cerrará en <strong> X </strong> segundos.',
1013
+ icon: tipo,
1014
+ timer: milisegundos,
1015
+ showCancelButton: false,
1016
+ showConfirmButton: false,
1017
+ willOpen: () => {
1018
+ if (showLoading) {
1019
+ swal.showLoading();
1020
+ }
1021
+ timerInterval = setInterval(() => {
1022
+ const impr = Math.ceil(((swal.getTimerLeft() ?? 1) / 1000));
1023
+ if (swal.getHtmlContainer()) {
1024
+ // @ts-ignore
1025
+ swal.getHtmlContainer().querySelector('strong').textContent = String(impr);
1026
+ }
1027
+ }, 100);
1028
+ },
1029
+ willClose: () => {
1030
+ clearInterval(timerInterval);
1031
+ }
1032
+ },
1033
+ ...opciones
1034
+ };
1035
+ return swal.fire(opciones);
1036
+ }
1037
+ // @ts-ignore
1038
+ function mensajeConfirmacion(tipo, titulo, mensaje, opciones) {
1039
+ opciones = {
1040
+ ...{
1041
+ heightAuto: false,
1042
+ title: titulo,
1043
+ html: mensaje,
1044
+ icon: tipo,
1045
+ showCancelButton: true,
1046
+ // confirmButtonColor: '#3f51b5',
1047
+ // cancelButtonColor: '#ffffff',
1048
+ confirmButtonText: 'Confirmar',
1049
+ cancelButtonText: 'Cancelar',
1050
+ reverseButtons: true,
1051
+ // customClass: {
1052
+ // confirmButton: 'btn btn-lg btn-outline-success mx-2',
1053
+ // cancelButton: 'btn btn-lg btn-outline-dark mx-2'
1054
+ // },
1055
+ // buttonsStyling: false
1056
+ },
1057
+ ...opciones
1058
+ };
1059
+ return swal.fire(opciones);
1060
+ }
1061
+ function mensajeToast(tipo, titulo, mensaje, opciones) {
1062
+ opciones = {
1063
+ ...{
1064
+ heightAuto: false,
1065
+ title: titulo,
1066
+ html: mensaje,
1067
+ icon: tipo,
1068
+ confirmButtonText: 'Aceptar',
1069
+ toast: true,
1070
+ position: 'top-end',
1071
+ showConfirmButton: false,
1072
+ timer: 3000,
1073
+ timerProgressBar: true,
1074
+ },
1075
+ ...opciones
1076
+ };
1077
+ return swal.fire(opciones);
1078
+ }
1079
+
1080
+ function mensajesDeError(error, toast = false) {
1081
+ let msg;
1082
+ if (error.error && error.error instanceof ArrayBuffer) {
1083
+ const msgArrayBuffer = (arrayBuffer) => {
1084
+ try {
1085
+ const mensajeError = JSON.parse(new TextDecoder("utf-8").decode(arrayBuffer));
1086
+ return mensajeError.message || 'Error desconocido';
1087
+ }
1088
+ catch (parseError) {
1089
+ console.error('Error al analizar la respuesta JSON:', parseError);
1090
+ return 'Error al analizar la respuesta JSON';
1091
+ }
1092
+ };
1093
+ msg = msgArrayBuffer(error.error);
1094
+ }
1095
+ else {
1096
+ switch (error.status) {
1097
+ case 0:
1098
+ // msg = error.message;
1099
+ msg = 'El servidor no responde, verifica tu conexion a la red';
1100
+ console.log(error);
1101
+ break;
1102
+ case 401:
1103
+ if (error.error && typeof error.error == 'object') {
1104
+ if (error.error.message) {
1105
+ msg = error.error.message;
1106
+ }
1107
+ else if (error.error.error) {
1108
+ msg = error.error.error;
1109
+ }
1110
+ else {
1111
+ msg = JSON.stringify(error.error);
1112
+ console.log(error);
1113
+ }
1114
+ }
1115
+ else if (error.error && typeof error.error == 'string') {
1116
+ msg = error.error;
1117
+ }
1118
+ else {
1119
+ msg = 'Acceso no autorizado';
1120
+ console.log(error);
1121
+ }
1122
+ break;
1123
+ case 422:
1124
+ let strEr = '';
1125
+ console.log(typeof error.error.errors);
1126
+ console.log(error.error.errors);
1127
+ if (error.error.errors) {
1128
+ Object.keys(error.error.errors).forEach(o => {
1129
+ strEr += '<li>' + error.error.errors[o][0] + '</li>';
1130
+ });
1131
+ msg = (error.error.message ?? '') + '<ul>' + strEr + '</ul>';
1132
+ }
1133
+ else if (error.error.error) {
1134
+ msg = error.error.msg;
1135
+ }
1136
+ break;
1137
+ case 429:
1138
+ case 400:
1139
+ case 500:
1140
+ case 503:
1141
+ msg = error.error.message;
1142
+ break;
1143
+ case 504:
1144
+ msg = 'No se puede conectar al servidor. Comprueba tu conexion a la red - ' + error.statusText;
1145
+ break;
1146
+ default:
1147
+ msg = error?.error?.message ?? 'Error de Sistema';
1148
+ console.log(error);
1149
+ break;
1150
+ }
1151
+ }
1152
+ if (!msg) {
1153
+ msg = error.statusText ?? 'Error inesperado o datos inexistentes.';
1154
+ }
1155
+ let tituloFinal = 'Error!';
1156
+ let mensajeFinal;
1157
+ if (msg.includes('Hmac::doVerify')) {
1158
+ console.log(error, msg);
1159
+ return;
1160
+ }
1161
+ else if (msg == 'Server Error') {
1162
+ console.log(error, msg);
1163
+ return;
1164
+ }
1165
+ else if (msg.includes('[IMSSP]')) {
1166
+ mensajeFinal = 'Error en consulta de registros.';
1167
+ }
1168
+ else if (msg.includes('Tiempo de espera de la')) {
1169
+ mensajeFinal = 'Hubo un error en la solicitud de datos, por favor actualice (SHIFT + F5)';
1170
+ }
1171
+ else {
1172
+ mensajeFinal = msg;
1173
+ }
1174
+ if (toast) {
1175
+ mensajeToast('error', tituloFinal, mensajeFinal);
1176
+ }
1177
+ else {
1178
+ mensajeAlerta('error', tituloFinal, mensajeFinal);
1179
+ }
1180
+ throw new Error(mensajeFinal);
1181
+ }
1182
+
1183
+ let dataSessionStorageKey = {
1184
+ tokenStringKey: 'JVSoftTkn',
1185
+ changePasswordKey: 'chPwd',
1186
+ logoUrl: 'logo_url',
1187
+ logoLogin: 'login-logo',
1188
+ backgroundLogin: 'login-background',
1189
+ favicon: 'favicon',
1190
+ darkMode: 'darkMode',
1191
+ serverTimestamp: 'srvtmstp',
1192
+ apiDataKey: 'reqDt',
1193
+ };
1194
+ let localStorageKeys = dataSessionStorageKey;
1195
+ function inicializarVariablesSessionStorage(datSesion) {
1196
+ dataSessionStorageKey = datSesion;
1197
+ }
1198
+ function setJwtTokenData(data) {
1199
+ localStorage.setItem(dataSessionStorageKey.tokenStringKey, data);
1200
+ }
1201
+ function jwtTokenData(key = dataSessionStorageKey.tokenStringKey) {
1202
+ const tokenObj = localStorage.getItem(key);
1203
+ try {
1204
+ return JSON.parse(tokenObj);
1205
+ }
1206
+ catch (error) {
1207
+ return null;
1208
+ }
1209
+ }
1210
+ function jwtToken(key = dataSessionStorageKey.tokenStringKey) {
1211
+ const varJwtTokenData = jwtTokenData(key);
1212
+ if (varJwtTokenData) {
1213
+ return varJwtTokenData.access_token;
1214
+ }
1215
+ return '';
1216
+ }
1217
+ function jwtTokenExpiracion(key = dataSessionStorageKey.tokenStringKey) {
1218
+ const jwtStr = jwtToken(key);
1219
+ if (!jwtStr)
1220
+ return null;
1221
+ try {
1222
+ const decodedToken = jwtDecode(jwtStr);
1223
+ return decodedToken.exp ? decodedToken.exp * 1000 : null; // Convertir a milisegundos
1224
+ }
1225
+ catch (e) {
1226
+ return null;
1227
+ }
1228
+ }
1229
+ function jwtTokenExpiracionFaltante() {
1230
+ return Math.abs(moment().diff(jwtTokenExpiracion(), 'seconds'));
1231
+ }
1232
+ function setCambiarPwd(accion = true) {
1233
+ localStorage.setItem(dataSessionStorageKey.changePasswordKey, (accion ? 1 : 0).toString());
1234
+ }
1235
+ function getCambiarPwd() {
1236
+ const frmCambioPwd = localStorage.getItem(dataSessionStorageKey.changePasswordKey);
1237
+ if (!frmCambioPwd) {
1238
+ return null;
1239
+ }
1240
+ return frmCambioPwd == '1';
1241
+ }
1242
+ function delLocalStorage(keyElim = [
1243
+ dataSessionStorageKey.tokenStringKey,
1244
+ dataSessionStorageKey.changePasswordKey,
1245
+ dataSessionStorageKey.apiDataKey,
1246
+ ]) {
1247
+ keyElim.forEach(key => {
1248
+ localStorage.removeItem(key);
1249
+ });
1250
+ }
1251
+ function getLocalStorage(key) {
1252
+ return localStorage.getItem(key);
1253
+ }
1254
+ function setLocalStorage(key, value = '') {
1255
+ localStorage.setItem(key, value.toString());
1256
+ }
1257
+
1258
+ function roundToDecimal(number, decimal) {
1259
+ return parseFloat(number.toFixed(decimal));
1260
+ }
1261
+ function numberToWords(num) {
1262
+ if (num === 0)
1263
+ return 'cero';
1264
+ if (num < 0)
1265
+ return 'menos ' + numberToWords(Math.abs(num));
1266
+ if (num > 999999999999)
1267
+ return 'número demasiado grande';
1268
+ const ones = ['', 'un', 'dos', 'tres', 'cuatro', 'cinco', 'seis', 'siete', 'ocho', 'nueve'];
1269
+ const onesFinal = ['', 'uno', 'dos', 'tres', 'cuatro', 'cinco', 'seis', 'siete', 'ocho', 'nueve'];
1270
+ const tens = ['', 'diez', 'veinte', 'treinta', 'cuarenta', 'cincuenta', 'sesenta', 'setenta', 'ochenta', 'noventa'];
1271
+ const teens = ['diez', 'once', 'doce', 'trece', 'catorce', 'quince', 'dieciséis', 'diecisiete', 'dieciocho', 'diecinueve'];
1272
+ const hundreds = ['', 'ciento', 'doscientos', 'trescientos', 'cuatrocientos', 'quinientos', 'seiscientos', 'setecientos', 'ochocientos', 'novecientos'];
1273
+ // Función auxiliar para "un"/"uno"
1274
+ const getOneForm = (n, isFinal) => n === 1 ? (isFinal ? 'uno' : 'un') : onesFinal[n];
1275
+ let words = '';
1276
+ // Miles de millones (ahora sí se ejecuta)
1277
+ if (num >= 1000000000) {
1278
+ const billions = Math.floor(num / 1000000000);
1279
+ words += (billions === 1 ? 'mil' : numberToWords(billions) + ' mil') + ' millones ';
1280
+ num %= 1000000000;
1281
+ }
1282
+ // Millones
1283
+ if (num >= 1000000) {
1284
+ const millions = Math.floor(num / 1000000);
1285
+ words += millions === 1 ? 'un millón ' : numberToWords(millions) + ' millones ';
1286
+ num %= 1000000;
1287
+ }
1288
+ // Miles
1289
+ if (num >= 1000) {
1290
+ const thousands = Math.floor(num / 1000);
1291
+ words += thousands === 1 ? 'mil ' : numberToWords(thousands) + ' mil ';
1292
+ num %= 1000;
1293
+ }
1294
+ // Centenas (con tratamiento especial para "ciento uno")
1295
+ if (num >= 100) {
1296
+ if (num === 100) {
1297
+ words += 'cien';
1298
+ num = 0;
1299
+ }
1300
+ else {
1301
+ words += hundreds[Math.floor(num / 100)];
1302
+ num %= 100;
1303
+ if (num > 0) {
1304
+ words += ' ' + getOneForm(num, true); // Siempre "uno" después de ciento
1305
+ num = 0;
1306
+ }
1307
+ }
1308
+ }
1309
+ // Decenas y unidades
1310
+ if (num > 0) {
1311
+ const isFinalWord = words === '';
1312
+ if (num < 10) {
1313
+ words += getOneForm(num, isFinalWord);
1314
+ }
1315
+ else if (num < 20) {
1316
+ words += teens[num - 10];
1317
+ }
1318
+ else if (num < 30) {
1319
+ if (num === 21)
1320
+ words += 'veintiuno';
1321
+ else if (num === 22)
1322
+ words += 'veintidós';
1323
+ else if (num === 23)
1324
+ words += 'veintitrés';
1325
+ else if (num === 26)
1326
+ words += 'veintiséis';
1327
+ else
1328
+ words += `veinti${onesFinal[num % 10]}`;
1329
+ }
1330
+ else {
1331
+ words += tens[Math.floor(num / 10)];
1332
+ if (num % 10 > 0) {
1333
+ words += ' y ' + getOneForm(num % 10, isFinalWord);
1334
+ }
1335
+ }
1336
+ }
1337
+ return words.trim().replace(/\s+/g, ' ');
1338
+ }
1339
+
1340
+ function objectPropertiesToType(formFields) {
1341
+ Object.keys(formFields).filter(control => !!formFields[control]).forEach(control => {
1342
+ if (/^dt[a-zA-Z]+/.test(control)) {
1343
+ formFields[control] = formatDate(formFields[control], 'yyyy-MM-dd HH:mm', 'es-PE');
1344
+ }
1345
+ else if (control.startsWith('d')) {
1346
+ formFields[control] = formatearFecha(formFields[control]);
1347
+ }
1348
+ else if (control.startsWith('n')) {
1349
+ formFields[control] = Number(formFields[control]);
1350
+ }
1351
+ });
1352
+ return formFields;
1353
+ }
1354
+ function objectPropertiesBoolean(formFields, retorno = 'boolean') {
1355
+ Object.keys(formFields).forEach(control => {
1356
+ const valRetorno = (ctrl) => {
1357
+ switch (retorno) {
1358
+ case 'boolean':
1359
+ formFields[ctrl] = formFields[ctrl] == 1;
1360
+ break;
1361
+ case 'bit':
1362
+ formFields[ctrl] = formFields[ctrl] ? 1 : 0;
1363
+ break;
1364
+ }
1365
+ };
1366
+ if (control.charAt(0) == 'b' || (control.charAt(0) == 'i' && control.indexOf('Estado') !== -1)) {
1367
+ valRetorno(control);
1368
+ }
1369
+ });
1370
+ return formFields;
1371
+ }
1372
+
1373
+ function generateRandomString(length) {
1374
+ let result = '';
1375
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
1376
+ const charactersLength = characters.length;
1377
+ for (let i = 0; i < length; i++) {
1378
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
1379
+ }
1380
+ return result;
1381
+ }
1382
+ /**
1383
+ * Obtiene el host (hostname) de una URL o cadena host[:port].
1384
+ * Opcionalmente puede devolver también el puerto si está presente.
1385
+ *
1386
+ * - Acepta inputs como:
1387
+ * 'https://example.com/path', 'example.com:3000', 'localhost', 'http://[::1]:4200'
1388
+ * - Usa la API URL cuando es posible (más robusta) y cae a un regex de respaldo.
1389
+ *
1390
+ * @param url Cadena que representa una URL o host
1391
+ * @param options
1392
+ * @param options.includePort Si es true, incluye":puerto" cuando exista (por defecto false)
1393
+ * @param options.includeProtocol Incluye "http://" o "https://" según corresponda (por defecto false)
1394
+ */
1395
+ function obtenerHostDesdeUrl(url, options) {
1396
+ if (!url)
1397
+ return null;
1398
+ const includePort = !!options?.includePort;
1399
+ const includeProtocol = !!options?.includeProtocol;
1400
+ // Intentar con API URL
1401
+ try {
1402
+ const candidate = url.includes('://') ? url : `http://${url}`;
1403
+ const parsed = new URL(candidate);
1404
+ const protocol = includeProtocol ? `${parsed.protocol}//` : '';
1405
+ const hostname = parsed.hostname;
1406
+ const port = parsed.port;
1407
+ if (!hostname)
1408
+ return null;
1409
+ return `${protocol}${hostname}${includePort && port ? `:${port}` : ''}`;
1410
+ }
1411
+ catch {
1412
+ // Regex fallback
1413
+ const regex = /^(?:(?<protocol>[a-z]+):\/\/)?(?:www\.)?(?<host>\[[^\]]+\]|[A-Za-z0-9.-]+)(?::(?<port>\d{1,5}))?/;
1414
+ const match = String(url).match(regex);
1415
+ if (!match?.groups)
1416
+ return null;
1417
+ let host = match.groups['host'];
1418
+ if (host.startsWith('[') && host.endsWith(']')) {
1419
+ host = host.slice(1, -1);
1420
+ }
1421
+ const port = match.groups['port'];
1422
+ const protocol = includeProtocol ? `${match.groups['protocol'] ?? 'http'}://` : '';
1423
+ return `${protocol}${host}${includePort && port ? `:${port}` : ''}`;
1424
+ }
1425
+ }
1426
+ /** @deprecated Alias compatible (deprecated) — preferir usar `obtenerHostDesdeUrl`. */
1427
+ const extraerDominio = (url, options) => obtenerHostDesdeUrl(url, options);
1428
+
1429
+ function verificarRUC(ruc) {
1430
+ const f = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
1431
+ const rucArray = ruc.split('');
1432
+ const nArray = f.map((item, idx) => {
1433
+ return item * parseFloat(rucArray[idx]);
1434
+ });
1435
+ const suma = nArray.reduce((a, b) => a + b, 0);
1436
+ const residuo = suma % 11;
1437
+ const residuo2 = 11 - residuo;
1438
+ // @residuo=CONVERT(Integer,Right(CONVERT(VarChar,@residuo),1))
1439
+ const residuo3 = residuo2.toString().charAt(residuo2.toString().length - 1);
1440
+ const ultimoCaracter = ruc.toString().charAt(ruc.toString().length - 1);
1441
+ if (residuo3 == ultimoCaracter) {
1442
+ return true;
1443
+ }
1444
+ mensajeAlerta('error', 'Datos No válidos', ' El número de RUC no es válido');
1445
+ return false;
1446
+ }
1447
+
1448
+ class DataModel {
1449
+ modelosChk = {}; // Usar any para valores dinámicos
1450
+ checkbox;
1451
+ constructor() {
1452
+ this.checkbox = new ForCheckboxModel(this);
1453
+ }
1454
+ generarId(row, campoValor, separador = '') {
1455
+ if (typeof campoValor == 'string') {
1456
+ campoValor = [campoValor];
1457
+ }
1458
+ return campoValor.map(data => row[data]).join(separador);
1459
+ }
1460
+ // Agrega controles al objeto modelosChk
1461
+ agregarControles(lista, idLista, limpiar = true, campoValor = null, campoValorSeparador = '') {
1462
+ if (limpiar) {
1463
+ this.modelosChk = {};
1464
+ }
1465
+ const asignarValor = (dat, idLista, campoValor, key) => {
1466
+ if (!key) {
1467
+ key = dat[idLista] + (campoValor.includes('.') ? '' : `.${campoValor}`);
1468
+ }
1469
+ const mat = campoValor.match(/^([in])[A-Z][a-zA-Z]+/);
1470
+ if (mat) {
1471
+ this.modelosChk[key] = dat[campoValor] * 1;
1472
+ }
1473
+ else {
1474
+ this.modelosChk[key] = dat[campoValor];
1475
+ }
1476
+ };
1477
+ lista.forEach(dat => {
1478
+ if (campoValor === null) {
1479
+ // Caso 1: Sin campoValor, se asigna false
1480
+ this.modelosChk[dat[idLista]] = false;
1481
+ }
1482
+ else if (typeof campoValor === 'string') {
1483
+ // Caso 2: campoValor es un string
1484
+ asignarValor(dat, idLista, campoValor, dat[idLista]);
1485
+ }
1486
+ else if (campoValorSeparador) {
1487
+ const idStr = this.generarId(dat, campoValor, campoValorSeparador);
1488
+ // Caso 2: campoValor es un string
1489
+ asignarValor(dat, idLista, '.', idStr);
1490
+ }
1491
+ else {
1492
+ // Caso 3: campoValor es un array de strings
1493
+ campoValor.forEach(data => asignarValor(dat, idLista, data));
1494
+ }
1495
+ });
1496
+ }
1497
+ // Establece el estado de un índice
1498
+ setState(idx, state) {
1499
+ this.modelosChk[idx] = state;
1500
+ }
1501
+ // Obtiene el estado de un índice
1502
+ getState(idx) {
1503
+ return this.modelosChk[idx];
1504
+ }
1505
+ getDataMultiple(idx) {
1506
+ const camposMod = Object.keys(this.modelosChk).filter(key => key.split('.')[0] == idx);
1507
+ const vRet = {};
1508
+ camposMod.forEach(key => {
1509
+ vRet[key.split('.')[1]] = this.modelosChk[key];
1510
+ });
1511
+ return vRet;
1512
+ }
1513
+ // Genera una lista basada en el estado de los índices
1514
+ generarLista(tipoRetorno = null, esCampoNumerico = false) {
1515
+ const strLista = [];
1516
+ const objLista = {};
1517
+ Object.keys(this.modelosChk).forEach(key => {
1518
+ if ((esCampoNumerico && esNumero(this.modelosChk[key])) ||
1519
+ (this.modelosChk[key])) {
1520
+ strLista.push(key);
1521
+ objLista[key] = this.modelosChk[key];
1522
+ }
1523
+ });
1524
+ if (tipoRetorno === 'array') {
1525
+ return strLista;
1526
+ }
1527
+ if (tipoRetorno === 'object') {
1528
+ return objLista;
1529
+ }
1530
+ return strLista.join(',');
1531
+ }
1532
+ generarFormGroupFromModelosChk(tipo) {
1533
+ const formGroupObj = {};
1534
+ let validadores = [];
1535
+ if (tipo == 'number') {
1536
+ validadores = [
1537
+ Validators.required,
1538
+ Validators.min(1)
1539
+ ];
1540
+ }
1541
+ Object.keys(this.modelosChk).forEach(key => {
1542
+ formGroupObj[key] = new FormControl(this.modelosChk[key], validadores);
1543
+ });
1544
+ return new FormGroup(formGroupObj);
1545
+ // return this.formBuilder.group(formGroupObj);
1546
+ }
1547
+ }
1548
+ class ForCheckboxModel {
1549
+ modeloCheck;
1550
+ constructor(modeloCheck) {
1551
+ this.modeloCheck = modeloCheck;
1552
+ }
1553
+ get cantidadActivos() {
1554
+ return Object.values(this.modeloCheck.modelosChk).filter(Boolean).length;
1555
+ }
1556
+ get existenActivados() {
1557
+ return this.cantidadActivos > 0;
1558
+ }
1559
+ get todosActivos() {
1560
+ const total = Object.keys(this.modeloCheck.modelosChk).length;
1561
+ const activos = this.cantidadActivos;
1562
+ return activos > 0 && total === activos;
1563
+ }
1564
+ get algunosActivos() {
1565
+ const total = Object.keys(this.modeloCheck.modelosChk).length;
1566
+ const activos = this.cantidadActivos;
1567
+ return activos > 0 && total !== activos;
1568
+ }
1569
+ establecerTodos(activo) {
1570
+ Object.keys(this.modeloCheck.modelosChk).forEach(idx => this.modeloCheck.modelosChk[idx] = activo);
1571
+ }
1572
+ }
1573
+
1574
+ class DataEnListaPipe {
1575
+ transform(coleccion, idBuscar, dato) {
1576
+ if (coleccion) {
1577
+ if (Array.isArray(idBuscar)) {
1578
+ return coleccion.find(item => {
1579
+ const arrCoincide = [];
1580
+ idBuscar.forEach((campo, idx) => {
1581
+ // @ts-ignore
1582
+ arrCoincide.push((item[campo] == dato[idx]));
1583
+ });
1584
+ return arrCoincide.every(e => e === true);
1585
+ });
1586
+ }
1587
+ // @ts-ignore
1588
+ return coleccion.find(item => item[idBuscar] == dato);
1589
+ }
1590
+ return null;
1591
+ }
1592
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DataEnListaPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1593
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: DataEnListaPipe, isStandalone: true, name: "dataEnLista" });
1594
+ }
1595
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DataEnListaPipe, decorators: [{
1596
+ type: Pipe,
1597
+ args: [{
1598
+ name: 'dataEnLista',
1599
+ }]
1600
+ }] });
1601
+ function dataEnLista(coleccion, idBuscar, dato) {
1602
+ return new DataEnListaPipe().transform(coleccion, idBuscar, dato);
1603
+ }
1604
+
1605
+ class DateDiffStringPipe {
1606
+ transform(startingDate, endingDate) {
1607
+ let startDate = new Date(startingDate);
1608
+ // user not pass endingDate then set current date as end date.
1609
+ if (!endingDate) {
1610
+ endingDate = new Date();
1611
+ }
1612
+ let endDate = new Date(endingDate);
1613
+ // chack start date and end date and base on condication alter date.
1614
+ if (startDate > endDate) {
1615
+ const swap = startDate;
1616
+ startDate = endDate;
1617
+ endDate = swap;
1618
+ }
1619
+ const disgregado = this.separarMilisegundos(endDate.getTime() - startDate.getTime());
1620
+ // console.log(disgregado);
1621
+ const formatearATexto = (arrayToFill, campo, texto, textoPlural = 's') => {
1622
+ if (campo > 0) {
1623
+ arrayToFill.push(campo + ' ' + texto + (campo > 1 ? textoPlural : ''));
1624
+ }
1625
+ return arrayToFill;
1626
+ };
1627
+ let arrDFinal = [];
1628
+ arrDFinal = formatearATexto(arrDFinal, disgregado.years, 'año');
1629
+ arrDFinal = formatearATexto(arrDFinal, disgregado.months, 'mes', 'es');
1630
+ arrDFinal = formatearATexto(arrDFinal, disgregado.weeks, 'semana');
1631
+ arrDFinal = formatearATexto(arrDFinal, disgregado.days, 'día');
1632
+ arrDFinal = formatearATexto(arrDFinal, disgregado.hours, 'hora');
1633
+ arrDFinal = formatearATexto(arrDFinal, disgregado.minutes, 'minuto');
1634
+ arrDFinal = formatearATexto(arrDFinal, disgregado.seconds, 'segundo');
1635
+ if (arrDFinal.length > 3) {
1636
+ arrDFinal.splice(3);
1637
+ arrDFinal.splice(-1, 0, 'y');
1638
+ }
1639
+ else {
1640
+ if (arrDFinal.length > 1) {
1641
+ arrDFinal.splice(-1, 0, 'y');
1642
+ }
1643
+ }
1644
+ return arrDFinal.join(' ');
1645
+ }
1646
+ separarMilisegundos(milisegundos) {
1647
+ const todoEnSegundos = milisegundos / 1000;
1648
+ let secsUsed = 0;
1649
+ const years = Math.floor(todoEnSegundos / 31536000);
1650
+ if (years > 0) {
1651
+ secsUsed += (years * 31536000);
1652
+ }
1653
+ const months = Math.floor((todoEnSegundos - secsUsed) / 2628288);
1654
+ if (months > 0) {
1655
+ secsUsed += (months * 2628288);
1656
+ }
1657
+ const weeks = Math.floor((todoEnSegundos - secsUsed) / 604800);
1658
+ if (weeks > 0) {
1659
+ secsUsed += (weeks * 604800);
1660
+ }
1661
+ const days = Math.floor((todoEnSegundos - secsUsed) / 86400);
1662
+ if (days > 0) {
1663
+ secsUsed += (days * 86400);
1664
+ }
1665
+ const hours = Math.floor((todoEnSegundos - secsUsed) / 3600);
1666
+ if (hours > 0) {
1667
+ secsUsed += (hours * 3600);
1668
+ }
1669
+ const minutes = Math.floor((todoEnSegundos - secsUsed) / 60);
1670
+ if (minutes > 0) {
1671
+ secsUsed += (minutes * 60);
1672
+ }
1673
+ const seconds = Math.round(todoEnSegundos - secsUsed);
1674
+ return {
1675
+ years,
1676
+ months,
1677
+ weeks,
1678
+ days,
1679
+ hours,
1680
+ minutes,
1681
+ seconds,
1682
+ };
1683
+ }
1684
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DateDiffStringPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1685
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: DateDiffStringPipe, isStandalone: true, name: "dateDiffString" });
1686
+ }
1687
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: DateDiffStringPipe, decorators: [{
1688
+ type: Pipe,
1689
+ args: [{
1690
+ name: 'dateDiffString',
1691
+ pure: true
1692
+ }]
1693
+ }] });
1694
+ function dateDiffString(startingDate, endingDate) {
1695
+ return new DateDiffStringPipe().transform(startingDate, endingDate);
1696
+ }
1697
+
1698
+ class FiltroPipe {
1699
+ transform(items, opcionesBusqueda) {
1700
+ if (!items || !Array.isArray(items))
1701
+ return [];
1702
+ if (!opcionesBusqueda.texto || opcionesBusqueda.texto.length < (opcionesBusqueda.longitudMinima ?? 1))
1703
+ return items;
1704
+ const normalize = (() => {
1705
+ const from = 'ÃÀÁÄÂÈÉËÊÌÍÏÎÒÓÖÔÙÚÜÛãàáäâèéëêìíïîòóöôùúüûÑñÇç';
1706
+ const to = 'AAAAAEEEEIIIIOOOOUUUUaaaaaeeeeiiiioooouuuunncc';
1707
+ const mapping = {};
1708
+ for (let i = 0; i < from.length; i++) {
1709
+ mapping[from[i]] = to[i];
1710
+ }
1711
+ return (str) => {
1712
+ return str.split('').map(c => mapping[c] || c).join('');
1713
+ };
1714
+ })();
1715
+ const textoNormalizado = normalize(opcionesBusqueda.texto.toLowerCase());
1716
+ return items.filter(item => {
1717
+ // 🔹 Manejo de `mostrarObligado`
1718
+ if (opcionesBusqueda.mostrarObligado) {
1719
+ const { campo, items: obligados } = opcionesBusqueda.mostrarObligado;
1720
+ if (obligados.includes(item[campo]))
1721
+ return true;
1722
+ }
1723
+ // 🔹 Manejo de `campo`
1724
+ if (opcionesBusqueda.campo) {
1725
+ if (Array.isArray(opcionesBusqueda.campo)) {
1726
+ return opcionesBusqueda.campo.some(campo => {
1727
+ const valor = item[campo];
1728
+ return valor ? normalize(valor.toLowerCase()).includes(textoNormalizado) : false;
1729
+ });
1730
+ }
1731
+ else {
1732
+ const valor = item[opcionesBusqueda.campo];
1733
+ return valor ? normalize(valor.toLowerCase()).includes(textoNormalizado) : false;
1734
+ }
1735
+ }
1736
+ return false;
1737
+ });
1738
+ }
1739
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FiltroPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1740
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: FiltroPipe, isStandalone: true, name: "filtro" });
1741
+ }
1742
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FiltroPipe, decorators: [{
1743
+ type: Pipe,
1744
+ args: [{
1745
+ name: 'filtro'
1746
+ }]
1747
+ }] });
1748
+
1749
+ class FormControlIsRequiredPipe {
1750
+ transform(formControl, ...args) {
1751
+ if (!formControl) {
1752
+ return false;
1753
+ }
1754
+ return formControl.hasValidator(Validators.required);
1755
+ }
1756
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormControlIsRequiredPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1757
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: FormControlIsRequiredPipe, isStandalone: true, name: "formControlIsRequired" });
1758
+ }
1759
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: FormControlIsRequiredPipe, decorators: [{
1760
+ type: Pipe,
1761
+ args: [{
1762
+ name: 'formControlIsRequired'
1763
+ }]
1764
+ }] });
1765
+ function formControlIsRequired(formControl) {
1766
+ return new FormControlIsRequiredPipe().transform(formControl);
1767
+ }
1768
+
1769
+ class JsonParsePipe {
1770
+ transform(value, ...args) {
1771
+ if (!value) {
1772
+ return [];
1773
+ }
1774
+ try {
1775
+ return JSON.parse(value);
1776
+ }
1777
+ catch (e) {
1778
+ console.warn('La cadena "' + value + '" no es JSON');
1779
+ return [];
1780
+ }
1781
+ }
1782
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: JsonParsePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1783
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: JsonParsePipe, isStandalone: true, name: "jsonParse" });
1784
+ }
1785
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: JsonParsePipe, decorators: [{
1786
+ type: Pipe,
1787
+ args: [{
1788
+ name: 'jsonParse'
1789
+ }]
1790
+ }] });
1791
+
1792
+ class NoSanitizePipe {
1793
+ domSanitizer;
1794
+ constructor(domSanitizer) {
1795
+ this.domSanitizer = domSanitizer;
1796
+ }
1797
+ transform(html) {
1798
+ return this.domSanitizer.bypassSecurityTrustHtml(html);
1799
+ }
1800
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: NoSanitizePipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe });
1801
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: NoSanitizePipe, isStandalone: true, name: "noSanitize" });
1802
+ }
1803
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: NoSanitizePipe, decorators: [{
1804
+ type: Pipe,
1805
+ args: [{ name: 'noSanitize' }]
1806
+ }], ctorParameters: () => [{ type: i1.DomSanitizer }] });
1807
+
1808
+ class TipoValorFuncionPipe {
1809
+ transform(datoParam, defaultValue, ...param) {
1810
+ if (datoParam === undefined || datoParam === null) {
1811
+ return defaultValue;
1812
+ }
1813
+ if (typeof datoParam === 'function') {
1814
+ return datoParam(...param);
1815
+ }
1816
+ return datoParam;
1817
+ }
1818
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: TipoValorFuncionPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1819
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: TipoValorFuncionPipe, isStandalone: true, name: "tipoValorFuncion" });
1820
+ }
1821
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: TipoValorFuncionPipe, decorators: [{
1822
+ type: Pipe,
1823
+ args: [{
1824
+ name: 'tipoValorFuncion',
1825
+ standalone: true, // Para usarlo en standalone components
1826
+ }]
1827
+ }] });
1828
+ function tipoValorFuncion(datoParam, defaultValue, ...param) {
1829
+ return new TipoValorFuncionPipe().transform(datoParam, defaultValue, ...param);
1830
+ }
1831
+
1832
+ class ZeroFillPipe {
1833
+ transform(value, digitos, ...args) {
1834
+ let s = value + '';
1835
+ while (s.length < digitos) {
1836
+ s = '0' + s;
1837
+ }
1838
+ return s;
1839
+ }
1840
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ZeroFillPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1841
+ static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.14", ngImport: i0, type: ZeroFillPipe, isStandalone: true, name: "zeroFill" });
1842
+ }
1843
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.14", ngImport: i0, type: ZeroFillPipe, decorators: [{
1844
+ type: Pipe,
1845
+ args: [{
1846
+ name: 'zeroFill',
1847
+ }]
1848
+ }] });
1849
+ function zeroFill(value, digitos, ...args) {
1850
+ return new ZeroFillPipe().transform(value, digitos, args);
1851
+ }
1852
+
1853
+ // export * from './otros';
1854
+
1855
+ /*
1856
+ * Public API Surface of utils
1857
+ */
1858
+ // export * from './functions/common.function';
1859
+ // export * from './lib/utils.component';
1860
+ // export * from './lib/utils.service';
1861
+
1862
+ /**
1863
+ * Generated bundle index. Do not edit.
1864
+ */
1865
+
1866
+ export { DataEnListaPipe, DataModel, DateDiffStringPipe, FiltroPipe, FormControlIsRequiredPipe, JsonParsePipe, NoSanitizePipe, TipoValorFuncionPipe, ZeroFillPipe, b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, changeSelectReformateado, convertirBytes, dataEnLista, dateDiffString, decodeBase64Object, decodeBase64String, decodeBase64ToBlob, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, eliminarColumnaPorIndex, eliminarDuplicados, eliminarElementos, encodeBase64File, encodeBase64Object, encodeBase64String, encriptar, esNumero, establecerQuitarRequired, extraerDominio, formControlIsRequired, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, groupBy, inicializarVariablesSessionStorage, isEmail, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, maskEmail, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, nestGroupsBy, numberToWords, objectPropertiesBoolean, objectPropertiesToType, obtenerHostDesdeUrl, obtenerMimeType, obtenerUltimoOrden, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, seleccionarTextoInput, setCambiarPwd, setControlDesdeLista, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, tipoValorFuncion, toFormData, transformarFechasPorNombreDeCampo, verificarRUC, zeroFill };
1867
+ //# sourceMappingURL=jvsoft-utils.mjs.map