@ea-lab/reactive-json
Version:
A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
44 lines (43 loc) • 1.22 kB
JavaScript
import { isTemplateValue as l } from "../TemplateSystem.js";
const w = (n, u = "", y = {}) => {
const r = /* @__PURE__ */ new Map();
if (!n)
return r;
if (typeof n == "string" && l(n))
return r.set("", n), r;
const p = parseInt(y.maxDepth) || 50, c = (e, t, s = /* @__PURE__ */ new Set(), f = 0) => {
if (f > p) {
console.warn(
"Reactive-JSON: Maximum depth reached in dataOverride references analysis (traverseObject). Stopped the analysis."
);
return;
}
if (s.has(e)) {
console.warn(
"Reactive-JSON: Infinite recursion detected in dataOverride references analysis (traverseObject). Stopped the analysis."
);
return;
}
if (s.add(e), typeof e == "string" && l(e)) {
r.set(t, e);
return;
}
if (!(!e || typeof e != "object")) {
if (Array.isArray(e)) {
e.forEach((i, a) => {
const o = t ? `${t}.${a}` : a.toString();
c(i, o, s, f + 1);
});
return;
}
Object.entries(e).forEach(([i, a]) => {
const o = t ? `${t}.${i}` : i;
c(a, o, s, f + 1);
});
}
};
return c(n, u), r;
};
export {
w as analyzeDataOverrideReferences
};