Skip to content

Commit 8835b1d

Browse files
committed
wip: to object
1 parent 03a8caa commit 8835b1d

10 files changed

Lines changed: 396 additions & 42 deletions

dist.browser/json-difference.mjs

Lines changed: 289 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,298 @@
1-
const c = (e, i) => {
2-
const o = [];
3-
for (const n in e)
4-
if (i.hasOwnProperty(n)) {
5-
if (typeof e[n] == "object" && typeof i[n] == "object" && JSON.stringify(e[n]) === JSON.stringify(i[n]))
1+
const M = (t, e) => {
2+
const n = [];
3+
for (const r in t)
4+
if (e.hasOwnProperty(r)) {
5+
if (typeof t[r] == "object" && typeof e[r] == "object" && JSON.stringify(t[r]) === JSON.stringify(e[r]))
66
continue;
7-
e[n] !== i[n] && o.push([n, e[n], i[n]]);
7+
t[r] !== e[r] && n.push([r, t[r], e[r]]);
88
}
9-
return o;
10-
}, y = (e, i) => {
11-
const o = [];
12-
let n = 0;
13-
for (const f in e)
14-
f in i || (o[n] = [f, e[f]], n++);
15-
return o;
16-
}, g = (e, i, o, n) => {
17-
const f = n ? e ? "[" : "." : "/", t = n ? e ? "]" : "" : e ? "[]" : "";
18-
return i !== "" ? `${i}${f}${o}${t}` : `${n && e ? "[" : ""}${o}${t}`;
19-
}, d = (e, i = !1, o = {}, n = "") => {
20-
for (const f of Object.keys(e)) {
21-
const t = g(Array.isArray(e), n, f, i);
22-
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];
9+
return n;
10+
}, $ = (t, e) => {
11+
const n = [];
12+
let r = 0;
13+
for (const o in t)
14+
o in e || (n[r] = [o, t[o]], r++);
15+
return n;
16+
}, L = (t, e, n, r) => {
17+
const o = r ? t ? "[" : "." : "/", i = r ? t ? "]" : "" : t ? "[]" : "";
18+
return e !== "" ? `${e}${o}${n}${i}` : `${r && t ? "[" : ""}${n}${i}`;
19+
}, C = (t, e = !1, n = {}, r = "") => {
20+
for (const o of Object.keys(t)) {
21+
const i = L(Array.isArray(t), r, o, e);
22+
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];
2323
}
24-
return o;
25-
}, $ = (e, i, o = !1) => {
26-
const n = {
24+
return n;
25+
};
26+
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")();
27+
function nt(t, e) {
28+
return t == null ? void 0 : t[e];
29+
}
30+
function rt(t) {
31+
var e = !1;
32+
if (t != null && typeof t.toString != "function")
33+
try {
34+
e = !!(t + "");
35+
} catch {
36+
}
37+
return e;
38+
}
39+
var ot = Array.prototype, it = Function.prototype, P = Object.prototype, O = x["__core-js_shared__"], T = function() {
40+
var t = /[^.]+$/.exec(O && O.keys && O.keys.IE_PROTO || "");
41+
return t ? "Symbol(src)_1." + t : "";
42+
}(), F = it.toString, y = P.hasOwnProperty, H = P.toString, at = RegExp(
43+
"^" + F.call(y).replace(W, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$"
44+
), 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;
45+
function a(t) {
46+
var e = -1, n = t ? t.length : 0;
47+
for (this.clear(); ++e < n; ) {
48+
var r = t[e];
49+
this.set(r[0], r[1]);
50+
}
51+
}
52+
function ct() {
53+
this.__data__ = d ? d(null) : {};
54+
}
55+
function ut(t) {
56+
return this.has(t) && delete this.__data__[t];
57+
}
58+
function dt(t) {
59+
var e = this.__data__;
60+
if (d) {
61+
var n = e[t];
62+
return n === D ? void 0 : n;
63+
}
64+
return y.call(e, t) ? e[t] : void 0;
65+
}
66+
function pt(t) {
67+
var e = this.__data__;
68+
return d ? e[t] !== void 0 : y.call(e, t);
69+
}
70+
function ht(t, e) {
71+
var n = this.__data__;
72+
return n[t] = d && e === void 0 ? D : e, this;
73+
}
74+
a.prototype.clear = ct;
75+
a.prototype.delete = ut;
76+
a.prototype.get = dt;
77+
a.prototype.has = pt;
78+
a.prototype.set = ht;
79+
function c(t) {
80+
var e = -1, n = t ? t.length : 0;
81+
for (this.clear(); ++e < n; ) {
82+
var r = t[e];
83+
this.set(r[0], r[1]);
84+
}
85+
}
86+
function lt() {
87+
this.__data__ = [];
88+
}
89+
function _t(t) {
90+
var e = this.__data__, n = g(e, t);
91+
if (n < 0)
92+
return !1;
93+
var r = e.length - 1;
94+
return n == r ? e.pop() : st.call(e, n, 1), !0;
95+
}
96+
function yt(t) {
97+
var e = this.__data__, n = g(e, t);
98+
return n < 0 ? void 0 : e[n][1];
99+
}
100+
function gt(t) {
101+
return g(this.__data__, t) > -1;
102+
}
103+
function bt(t, e) {
104+
var n = this.__data__, r = g(n, t);
105+
return r < 0 ? n.push([t, e]) : n[r][1] = e, this;
106+
}
107+
c.prototype.clear = lt;
108+
c.prototype.delete = _t;
109+
c.prototype.get = yt;
110+
c.prototype.has = gt;
111+
c.prototype.set = bt;
112+
function s(t) {
113+
var e = -1, n = t ? t.length : 0;
114+
for (this.clear(); ++e < n; ) {
115+
var r = t[e];
116+
this.set(r[0], r[1]);
117+
}
118+
}
119+
function mt() {
120+
this.__data__ = {
121+
hash: new a(),
122+
map: new (ft || c)(),
123+
string: new a()
124+
};
125+
}
126+
function Ot(t) {
127+
return b(this, t).delete(t);
128+
}
129+
function vt(t) {
130+
return b(this, t).get(t);
131+
}
132+
function Ct(t) {
133+
return b(this, t).has(t);
134+
}
135+
function xt(t, e) {
136+
return b(this, t).set(t, e), this;
137+
}
138+
s.prototype.clear = mt;
139+
s.prototype.delete = Ot;
140+
s.prototype.get = vt;
141+
s.prototype.has = Ct;
142+
s.prototype.set = xt;
143+
function St(t, e, n) {
144+
var r = t[e];
145+
(!(y.call(t, e) && R(r, n)) || n === void 0 && !(e in t)) && (t[e] = n);
146+
}
147+
function g(t, e) {
148+
for (var n = t.length; n--; )
149+
if (R(t[n][0], e))
150+
return n;
151+
return -1;
152+
}
153+
function jt(t) {
154+
if (!_(t) || Nt(t))
155+
return !1;
156+
var e = Gt(t) || rt(t) ? at : V;
157+
return e.test(Ht(t));
158+
}
159+
function $t(t, e, n, r) {
160+
if (!_(t))
161+
return t;
162+
e = Et(e, t) ? [e] : It(e);
163+
for (var o = -1, i = e.length, u = i - 1, f = t; f != null && ++o < i; ) {
164+
var p = Ft(e[o]), h = n;
165+
if (o != u) {
166+
var m = f[p];
167+
h = r ? r(m, p, f) : void 0, h === void 0 && (h = _(m) ? m : wt(e[o + 1]) ? [] : {});
168+
}
169+
St(f, p, h), f = f[p];
170+
}
171+
return t;
172+
}
173+
function Tt(t) {
174+
if (typeof t == "string")
175+
return t;
176+
if (j(t))
177+
return E ? E.call(t) : "";
178+
var e = t + "";
179+
return e == "0" && 1 / t == -N ? "-0" : e;
180+
}
181+
function It(t) {
182+
return A(t) ? t : Pt(t);
183+
}
184+
function b(t, e) {
185+
var n = t.__data__;
186+
return Dt(e) ? n[typeof e == "string" ? "string" : "hash"] : n.map;
187+
}
188+
function G(t, e) {
189+
var n = nt(t, e);
190+
return jt(n) ? n : void 0;
191+
}
192+
function wt(t, e) {
193+
return e = e ?? J, !!e && (typeof t == "number" || k.test(t)) && t > -1 && t % 1 == 0 && t < e;
194+
}
195+
function Et(t, e) {
196+
if (A(t))
197+
return !1;
198+
var n = typeof t;
199+
return n == "number" || n == "symbol" || n == "boolean" || t == null || j(t) ? !0 : Y.test(t) || !z.test(t) || e != null && t in Object(e);
200+
}
201+
function Dt(t) {
202+
var e = typeof t;
203+
return e == "string" || e == "number" || e == "symbol" || e == "boolean" ? t !== "__proto__" : t === null;
204+
}
205+
function Nt(t) {
206+
return !!T && T in t;
207+
}
208+
var Pt = S(function(t) {
209+
t = At(t);
210+
var e = [];
211+
return B.test(t) && e.push(""), t.replace(Q, function(n, r, o, i) {
212+
e.push(o ? i.replace(Z, "$1") : r || n);
213+
}), e;
214+
});
215+
function Ft(t) {
216+
if (typeof t == "string" || j(t))
217+
return t;
218+
var e = t + "";
219+
return e == "0" && 1 / t == -N ? "-0" : e;
220+
}
221+
function Ht(t) {
222+
if (t != null) {
223+
try {
224+
return F.call(t);
225+
} catch {
226+
}
227+
try {
228+
return t + "";
229+
} catch {
230+
}
231+
}
232+
return "";
233+
}
234+
function S(t, e) {
235+
if (typeof t != "function" || e && typeof e != "function")
236+
throw new TypeError(K);
237+
var n = function() {
238+
var r = arguments, o = e ? e.apply(this, r) : r[0], i = n.cache;
239+
if (i.has(o))
240+
return i.get(o);
241+
var u = t.apply(this, r);
242+
return n.cache = i.set(o, u), u;
243+
};
244+
return n.cache = new (S.Cache || s)(), n;
245+
}
246+
S.Cache = s;
247+
function R(t, e) {
248+
return t === e || t !== t && e !== e;
249+
}
250+
var A = Array.isArray;
251+
function Gt(t) {
252+
var e = _(t) ? H.call(t) : "";
253+
return e == U || e == X;
254+
}
255+
function _(t) {
256+
var e = typeof t;
257+
return !!t && (e == "object" || e == "function");
258+
}
259+
function Rt(t) {
260+
return !!t && typeof t == "object";
261+
}
262+
function j(t) {
263+
return typeof t == "symbol" || Rt(t) && H.call(t) == q;
264+
}
265+
function At(t) {
266+
return t == null ? "" : Tt(t);
267+
}
268+
function Mt(t, e, n) {
269+
return t == null ? t : $t(t, e, n);
270+
}
271+
var v = Mt;
272+
const Lt = (t) => {
273+
const e = t.removed.map((o) => {
274+
const i = {};
275+
return v(i, o[0], o[1]), i;
276+
}), n = t.edited.map((o) => v({}, "cafe/123", "8888")), r = t.added.map((o) => v({}, o[0], o[1]));
277+
return {
278+
removed: e,
279+
edited: n,
280+
added: r
281+
};
282+
}, Kt = {
283+
isLodashLike: !1
284+
}, Jt = (t, e, n = Kt) => {
285+
let r = {
27286
added: [],
28287
removed: [],
29288
edited: []
30-
}, f = d(e, o), t = d(i, o);
31-
return n.removed = y(f, t), n.added = y(t, f), n.edited = c(f, t), n;
289+
};
290+
const o = C(t, n.isLodashLike), i = C(e, n.isLodashLike);
291+
return r.removed = $(o, i), r.added = $(i, o), r.edited = M(o, i), n.isObjectOutput && (r = Lt(r)), r;
32292
};
33293
export {
34-
$ as getDiff,
35-
c as getEditedPaths,
36-
y as getPathsDiff,
37-
d as getStructPaths
294+
Jt as getDiff,
295+
M as getEditedPaths,
296+
$ as getPathsDiff,
297+
C as getStructPaths
38298
};

dist.browser/json-difference.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,10 @@
4949
"typescript": "4.4.3",
5050
"vite": "^4.0.4",
5151
"vite-tsconfig-paths": "^4.0.5"
52+
},
53+
"dependencies": {
54+
"@types/lodash.set": "^4.3.7",
55+
"lodash.set": "^4.3.2",
56+
"remeda": "^1.6.1"
5257
}
5358
}

0 commit comments

Comments
 (0)