UNPKG

@ea-lab/reactive-json

Version:

A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.

61 lines (60 loc) 1.74 kB
import { jsx as u, Fragment as s } from "react/jsx-runtime"; import { useContext as f } from "react"; import { ActionDependant as d } from "../../../engine/Actions.js"; import { GlobalDataContext as p } from "../../../engine/GlobalDataContext.js"; import { TemplateContext as v } from "../../../engine/TemplateContext.js"; import { evaluateTemplateValue as c } from "../../../engine/TemplateSystem.js"; const h = ({ props: t }) => { const r = f(p), l = f(v); let o = !1, e, a; if (t.content !== void 0 && (e = c({ valueToEvaluate: t.content, globalDataContext: r, templateContext: l })), e == null || e === "") return null; switch (t.format !== void 0 && (a = c({ valueToEvaluate: t.format, globalDataContext: r, templateContext: l })), a) { case "roman-upper": o = m(e); break; case "roman-lower": o = m(e, !0); break; case "latin-upper": o = n(e); break; case "latin-lower": o = n(e, !0); break; default: o = e; break; } return /* @__PURE__ */ u(d, { ...t, children: /* @__PURE__ */ u(s, { children: o !== !1 && o }) }); }; function n(t, r = !1) { if (t < 1) return !1; let l = t % 26, o = t / 26 | 0, e = l ? String.fromCharCode(64 + l) : (--o, "Z"); const a = o ? n(o) + e : e; return r ? a.toLowerCase() : a; } function m(t, r = !1) { if (t < 1) return !1; const o = [ ["M", 1e3], ["CM", 900], ["D", 500], ["CD", 400], ["C", 100], ["XC", 90], ["L", 50], ["XL", 40], ["X", 10], ["IX", 9], ["V", 5], ["IV", 4], ["I", 1] ].reduce((e, [a, i]) => (e += a.repeat(Math.floor(t / i)), t = t % i, e), ""); return r ? o.toLowerCase() : o; } export { h as FormatNumeral };