-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.js
1 lines (1 loc) · 2.4 KB
/
index.min.js
1
const _disableTrackKey = "_disableTracker", opts = { cursor: null, seperator: ".", comma: ",", equal: "=", arrayMap: "*", pipe: "|", invoke: "&" }, fmtr = {}, cursor = function (t = {}, o = opts) { return { ...o, cursor: t } }, withOptions = function (t, o) { const e = Object.assign({}, t); return o && Object.assign(e, { [_disableTrackKey]: !0 }), e }, dig = function (t, o, e = opts, s = fmtr) { if (!t || !o) return null; if ("object" == typeof o) { if (Array.isArray(o)) return o.map(o => dig(t, o, e, s)); const r = Object.keys(o), i = {}; for (const n of r) i[n] = dig(t, o[n], e, s); return i } let r = t, i = o.split(e.seperator); if (e.cursor) { const t = [...i], o = t.pop(), r = e.cursor[t.join(e.seperator)]; if (r) { const i = withOptions(e, !0), n = dig(r, o, i, s); return e.cursor[[...t, o].join(e.seperator)] = n, n } } let n = []; for (let o = 0; o < i.length; o += 1) { const p = i[o]; if (n.push(p), -1 !== p.indexOf(e.pipe)) { let t = null; const o = p.split(e.pipe), i = withOptions(e, !0); for (const e of o) if (t = dig(r, e, i, s)) break; r = t } else if (-1 !== p.indexOf(e.comma)) { const t = p.split(e.comma), o = {}, i = withOptions(e, !0); for (const e of t) o[e] = dig(r, e, i, s); r = o } else if (-1 !== p.indexOf(e.equal)) { const t = p.split(e.equal), o = t[0], s = t[1]; r = r.find(t => o ? t[o] == s : t == s) } else if (p === e.arrayMap) { o += 1; const t = withOptions(e, !0), p = i.slice(o)[0]; e.cursor && (e.cursor[n.join(e.seperator)] = r, n.push(p)), r = r.map(o => dig(o, p, t, s)) } else if (-1 !== p.indexOf(e.invoke)) { const o = p.split(e.invoke), i = withOptions(e, !0); let n = dig(r, o.shift(), i, s); for (const e of o) "function" == typeof s[e] && (n = s[e](n, t)); r = n } else r = r[p]; if (null == r || null == r) return null; e.cursor && !e._disableTracker && (e.cursor[n.join(e.seperator)] = r) } return r }, output = { dig: dig, cursor: cursor, _withOptions: withOptions, _disableTrackKey: _disableTrackKey, setFormatter: function (t) { Object.assign(fmtr, t) }, setOptions: function (t) { Object.assign(opts, t) } }; "undefined" != typeof window && Object.assign(window, output), "undefined" != typeof process && (module.exports = output), "object" == typeof exports && (exports.dig = output.dig, exports.cursor = output.cursor, exports._withOptions = withOptions, exports._disableTrackKey = _disableTrackKey, exports.setFormatter = output.setFormatter, exports.setOptions = output.setOptions);