dmencu 3.2.13 → 3.2.14

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.
@@ -110,14 +110,36 @@ registrarCargarMotor(async function cargarEstructuraYDatosEnMemoria() {
110
110
 
111
111
  const DELAY_SCROLL_3 = 50;
112
112
 
113
- function obtenerPorPath<T = unknown>(objeto: Record<string, any>, path: string): T | null {
114
- if (!objeto || typeof path !== 'string') return null;
113
+ export type ResultadoPath<T = unknown> = {
114
+ encontrado: boolean;
115
+ valor: T | null;
116
+ };
117
+
118
+ function obtenerPorPath<T = unknown>(objeto: Record<string, any>, path: string): ResultadoPath<T> {
119
+ const noEncontrado: ResultadoPath<T> = { encontrado: false, valor: null };
120
+
121
+ if (!objeto || typeof path !== 'string' || path.trim() === '') {
122
+ return noEncontrado;
123
+ }
124
+
125
+ const claves = path.split('.');
126
+ let actual: any = objeto;
115
127
 
116
- const resultado = path.split('.').reduce<any>((acc, clave) => {
117
- return acc !== null && acc !== undefined ? acc[clave] : null;
118
- }, objeto);
128
+ for (let i = 0; i < claves.length; i++) {
129
+ const clave = claves[i];
119
130
 
120
- return (resultado ?? null) as T | null;
131
+ // Si el nivel actual no es un objeto/array o la clave NO existe en él
132
+ if (actual === null || typeof actual !== 'object' || !(clave in actual)) {
133
+ return noEncontrado;
134
+ }
135
+
136
+ actual = actual[clave];
137
+ }
138
+
139
+ return {
140
+ encontrado: true,
141
+ valor: (actual ?? null) as T | null,
142
+ };
121
143
  }
122
144
 
123
145
  function breakeableText(text: string | null): string | null;
@@ -277,11 +299,11 @@ export const BreakeableText = React.memo(function BreakeableText(props: {
277
299
  if (matchTem) {
278
300
  const infoHdr = getDatosByPass().informacionHdr;
279
301
  const estructura = getEstructura();
280
- const idEnc = forPk?.[estructura.pkAgregadaUaPpal];
302
+ const idEnc = forPk![estructura.pkAgregadaUaPpal];
281
303
  const path = matchTem[1];
282
- const valor = idEnc ? obtenerPorPath(infoHdr[idEnc], path) : null;
304
+ const {encontrado, valor} = obtenerPorPath(infoHdr[idEnc], path)
283
305
 
284
- return valor ?? (
306
+ return encontrado ? String(valor): (
285
307
  <span key={index} style={{ color: 'red' }}>
286
308
  {`No se encontró ${parte}`}
287
309
  </span>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dmencu",
3
3
  "description": "DM Encu - Encuestas en dispositivo móvil",
4
- "version": "3.2.13",
4
+ "version": "3.2.14",
5
5
  "author": "Codenautas <codenautas@googlegroups.com>",
6
6
  "license": "MIT",
7
7
  "repository": "codenautas/dmencu",