Skip to content

Commit

Permalink
wip: to object
Browse files Browse the repository at this point in the history
  • Loading branch information
lukascivil committed Jul 22, 2023
1 parent 03a8caa commit 8835b1d
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 42 deletions.
318 changes: 289 additions & 29 deletions dist.browser/json-difference.mjs
Original file line number Diff line number Diff line change
@@ -1,38 +1,298 @@
const c = (e, i) => {
const o = [];
for (const n in e)
if (i.hasOwnProperty(n)) {
if (typeof e[n] == "object" && typeof i[n] == "object" && JSON.stringify(e[n]) === JSON.stringify(i[n]))
const M = (t, e) => {
const n = [];
for (const r in t)
if (e.hasOwnProperty(r)) {
if (typeof t[r] == "object" && typeof e[r] == "object" && JSON.stringify(t[r]) === JSON.stringify(e[r]))
continue;
e[n] !== i[n] && o.push([n, e[n], i[n]]);
t[r] !== e[r] && n.push([r, t[r], e[r]]);
}
return o;
}, y = (e, i) => {
const o = [];
let n = 0;
for (const f in e)
f in i || (o[n] = [f, e[f]], n++);
return o;
}, g = (e, i, o, n) => {
const f = n ? e ? "[" : "." : "/", t = n ? e ? "]" : "" : e ? "[]" : "";
return i !== "" ? `${i}${f}${o}${t}` : `${n && e ? "[" : ""}${o}${t}`;
}, d = (e, i = !1, o = {}, n = "") => {
for (const f of Object.keys(e)) {
const t = g(Array.isArray(e), n, f, i);
typeof e[f] == "object" && e[f] !== null ? (Object.keys(e[f]).length === 0 && (o[t] = e[f]), d(e[f], i, o, t)) : o[t] = e[f];
return n;
}, $ = (t, e) => {
const n = [];
let r = 0;
for (const o in t)
o in e || (n[r] = [o, t[o]], r++);
return n;
}, L = (t, e, n, r) => {
const o = r ? t ? "[" : "." : "/", i = r ? t ? "]" : "" : t ? "[]" : "";
return e !== "" ? `${e}${o}${n}${i}` : `${r && t ? "[" : ""}${n}${i}`;
}, C = (t, e = !1, n = {}, r = "") => {
for (const o of Object.keys(t)) {
const i = L(Array.isArray(t), r, o, e);
typeof t[o] == "object" && t[o] !== null ? (Object.keys(t[o]).length === 0 && (n[i] = t[o]), C(t[o], e, n, i)) : n[i] = t[o];
}
return o;
}, $ = (e, i, o = !1) => {
const n = {
return n;
};
var l = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, K = "Expected a function", D = "__lodash_hash_undefined__", N = 1 / 0, J = 9007199254740991, U = "[object Function]", X = "[object GeneratorFunction]", q = "[object Symbol]", z = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, Y = /^\w*$/, B = /^\./, Q = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g, W = /[\\^$.*+?()[\]{}|]/g, Z = /\\(\\)?/g, V = /^\[object .+?Constructor\]$/, k = /^(?:0|[1-9]\d*)$/, tt = typeof l == "object" && l && l.Object === Object && l, et = typeof self == "object" && self && self.Object === Object && self, x = tt || et || Function("return this")();
function nt(t, e) {
return t == null ? void 0 : t[e];
}
function rt(t) {
var e = !1;
if (t != null && typeof t.toString != "function")
try {
e = !!(t + "");
} catch {
}
return e;
}
var ot = Array.prototype, it = Function.prototype, P = Object.prototype, O = x["__core-js_shared__"], T = function() {
var t = /[^.]+$/.exec(O && O.keys && O.keys.IE_PROTO || "");
return t ? "Symbol(src)_1." + t : "";
}(), F = it.toString, y = P.hasOwnProperty, H = P.toString, at = RegExp(
"^" + F.call(y).replace(W, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
), I = x.Symbol, st = ot.splice, ft = G(x, "Map"), d = G(Object, "create"), w = I ? I.prototype : void 0, E = w ? w.toString : void 0;
function a(t) {
var e = -1, n = t ? t.length : 0;
for (this.clear(); ++e < n; ) {
var r = t[e];
this.set(r[0], r[1]);
}
}
function ct() {
this.__data__ = d ? d(null) : {};
}
function ut(t) {
return this.has(t) && delete this.__data__[t];
}
function dt(t) {
var e = this.__data__;
if (d) {
var n = e[t];
return n === D ? void 0 : n;
}
return y.call(e, t) ? e[t] : void 0;
}
function pt(t) {
var e = this.__data__;
return d ? e[t] !== void 0 : y.call(e, t);
}
function ht(t, e) {
var n = this.__data__;
return n[t] = d && e === void 0 ? D : e, this;
}
a.prototype.clear = ct;
a.prototype.delete = ut;
a.prototype.get = dt;
a.prototype.has = pt;
a.prototype.set = ht;
function c(t) {
var e = -1, n = t ? t.length : 0;
for (this.clear(); ++e < n; ) {
var r = t[e];
this.set(r[0], r[1]);
}
}
function lt() {
this.__data__ = [];
}
function _t(t) {
var e = this.__data__, n = g(e, t);
if (n < 0)
return !1;
var r = e.length - 1;
return n == r ? e.pop() : st.call(e, n, 1), !0;
}
function yt(t) {
var e = this.__data__, n = g(e, t);
return n < 0 ? void 0 : e[n][1];
}
function gt(t) {
return g(this.__data__, t) > -1;
}
function bt(t, e) {
var n = this.__data__, r = g(n, t);
return r < 0 ? n.push([t, e]) : n[r][1] = e, this;
}
c.prototype.clear = lt;
c.prototype.delete = _t;
c.prototype.get = yt;
c.prototype.has = gt;
c.prototype.set = bt;
function s(t) {
var e = -1, n = t ? t.length : 0;
for (this.clear(); ++e < n; ) {
var r = t[e];
this.set(r[0], r[1]);
}
}
function mt() {
this.__data__ = {
hash: new a(),
map: new (ft || c)(),
string: new a()
};
}
function Ot(t) {
return b(this, t).delete(t);
}
function vt(t) {
return b(this, t).get(t);
}
function Ct(t) {
return b(this, t).has(t);
}
function xt(t, e) {
return b(this, t).set(t, e), this;
}
s.prototype.clear = mt;
s.prototype.delete = Ot;
s.prototype.get = vt;
s.prototype.has = Ct;
s.prototype.set = xt;
function St(t, e, n) {
var r = t[e];
(!(y.call(t, e) && R(r, n)) || n === void 0 && !(e in t)) && (t[e] = n);
}
function g(t, e) {
for (var n = t.length; n--; )
if (R(t[n][0], e))
return n;
return -1;
}
function jt(t) {
if (!_(t) || Nt(t))
return !1;
var e = Gt(t) || rt(t) ? at : V;
return e.test(Ht(t));
}
function $t(t, e, n, r) {
if (!_(t))
return t;
e = Et(e, t) ? [e] : It(e);
for (var o = -1, i = e.length, u = i - 1, f = t; f != null && ++o < i; ) {
var p = Ft(e[o]), h = n;
if (o != u) {
var m = f[p];
h = r ? r(m, p, f) : void 0, h === void 0 && (h = _(m) ? m : wt(e[o + 1]) ? [] : {});
}
St(f, p, h), f = f[p];
}
return t;
}
function Tt(t) {
if (typeof t == "string")
return t;
if (j(t))
return E ? E.call(t) : "";
var e = t + "";
return e == "0" && 1 / t == -N ? "-0" : e;
}
function It(t) {
return A(t) ? t : Pt(t);
}
function b(t, e) {
var n = t.__data__;
return Dt(e) ? n[typeof e == "string" ? "string" : "hash"] : n.map;
}
function G(t, e) {
var n = nt(t, e);
return jt(n) ? n : void 0;
}
function wt(t, e) {
return e = e ?? J, !!e && (typeof t == "number" || k.test(t)) && t > -1 && t % 1 == 0 && t < e;
}
function Et(t, e) {
if (A(t))
return !1;
var n = typeof t;
return n == "number" || n == "symbol" || n == "boolean" || t == null || j(t) ? !0 : Y.test(t) || !z.test(t) || e != null && t in Object(e);
}
function Dt(t) {
var e = typeof t;
return e == "string" || e == "number" || e == "symbol" || e == "boolean" ? t !== "__proto__" : t === null;
}
function Nt(t) {
return !!T && T in t;
}
var Pt = S(function(t) {
t = At(t);
var e = [];
return B.test(t) && e.push(""), t.replace(Q, function(n, r, o, i) {
e.push(o ? i.replace(Z, "$1") : r || n);
}), e;
});
function Ft(t) {
if (typeof t == "string" || j(t))
return t;
var e = t + "";
return e == "0" && 1 / t == -N ? "-0" : e;
}
function Ht(t) {
if (t != null) {
try {
return F.call(t);
} catch {
}
try {
return t + "";
} catch {
}
}
return "";
}
function S(t, e) {
if (typeof t != "function" || e && typeof e != "function")
throw new TypeError(K);
var n = function() {
var r = arguments, o = e ? e.apply(this, r) : r[0], i = n.cache;
if (i.has(o))
return i.get(o);
var u = t.apply(this, r);
return n.cache = i.set(o, u), u;
};
return n.cache = new (S.Cache || s)(), n;
}
S.Cache = s;
function R(t, e) {
return t === e || t !== t && e !== e;
}
var A = Array.isArray;
function Gt(t) {
var e = _(t) ? H.call(t) : "";
return e == U || e == X;
}
function _(t) {
var e = typeof t;
return !!t && (e == "object" || e == "function");
}
function Rt(t) {
return !!t && typeof t == "object";
}
function j(t) {
return typeof t == "symbol" || Rt(t) && H.call(t) == q;
}
function At(t) {
return t == null ? "" : Tt(t);
}
function Mt(t, e, n) {
return t == null ? t : $t(t, e, n);
}
var v = Mt;
const Lt = (t) => {
const e = t.removed.map((o) => {
const i = {};
return v(i, o[0], o[1]), i;
}), n = t.edited.map((o) => v({}, "cafe/123", "8888")), r = t.added.map((o) => v({}, o[0], o[1]));
return {
removed: e,
edited: n,
added: r
};
}, Kt = {
isLodashLike: !1
}, Jt = (t, e, n = Kt) => {
let r = {
added: [],
removed: [],
edited: []
}, f = d(e, o), t = d(i, o);
return n.removed = y(f, t), n.added = y(t, f), n.edited = c(f, t), n;
};
const o = C(t, n.isLodashLike), i = C(e, n.isLodashLike);
return r.removed = $(o, i), r.added = $(i, o), r.edited = M(o, i), n.isObjectOutput && (r = Lt(r)), r;
};
export {
$ as getDiff,
c as getEditedPaths,
y as getPathsDiff,
d as getStructPaths
Jt as getDiff,
M as getEditedPaths,
$ as getPathsDiff,
C as getStructPaths
};
2 changes: 1 addition & 1 deletion dist.browser/json-difference.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@
"typescript": "4.4.3",
"vite": "^4.0.4",
"vite-tsconfig-paths": "^4.0.5"
},
"dependencies": {
"@types/lodash.set": "^4.3.7",
"lodash.set": "^4.3.2",
"remeda": "^1.6.1"
}
}
Loading

0 comments on commit 8835b1d

Please sign in to comment.