Skip to content

Commit 46b05b7

Browse files
authored
Merge pull request #407 from benjamine/fixes
couple more fixes
2 parents b653cce + c291c3c commit 46b05b7

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

demos/html-demo/demo.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,20 @@ const getExampleJson = function () {
268268

269269
const diffOptions = {
270270
objectHash: function (obj, index) {
271-
const objRecord = obj as Record<string, string>;
272-
if (typeof objRecord._id !== 'undefined') {
273-
return objRecord._id;
274-
}
275-
if (typeof objRecord.id !== 'undefined') {
276-
return objRecord.id;
277-
}
278-
if (typeof objRecord.key !== 'undefined') {
279-
return objRecord.key;
280-
}
281-
if (typeof objRecord.name !== 'undefined') {
282-
return objRecord.name;
271+
if (typeof obj === 'object' && obj !== null) {
272+
const objRecord = obj as Record<string, string>;
273+
if (typeof objRecord._id !== 'undefined') {
274+
return objRecord._id;
275+
}
276+
if (typeof objRecord.id !== 'undefined') {
277+
return objRecord.id;
278+
}
279+
if (typeof objRecord.key !== 'undefined') {
280+
return objRecord.key;
281+
}
282+
if (typeof objRecord.name !== 'undefined') {
283+
return objRecord.name;
284+
}
283285
}
284286
return '$$index:' + index;
285287
},

demos/html-demo/index.html

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@
5858
<meta content="utf-8" http-equiv="encoding" />
5959
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
6060

61+
<!-- Google tag (gtag.js) -->
62+
<script
63+
async
64+
src="https://www.googletagmanager.com/gtag/js?id=G-F2ZTFWQ8CL"
65+
></script>
66+
<script>
67+
window.dataLayer = window.dataLayer || [];
68+
function gtag() {
69+
dataLayer.push(arguments);
70+
}
71+
gtag('js', new Date());
72+
73+
gtag('config', 'G-F2ZTFWQ8CL');
74+
</script>
75+
6176
<link
6277
rel="stylesheet"
6378
href="https://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.3/css/bulma.min.css"
@@ -501,30 +516,5 @@ <h2>Features</h2>
501516
</p>
502517
</footer>
503518
<script src="build/demo.js" type="module"></script>
504-
505-
<script>
506-
(function (i, s, o, g, r, a, m) {
507-
i['GoogleAnalyticsObject'] = r;
508-
(i[r] =
509-
i[r] ||
510-
function () {
511-
(i[r].q = i[r].q || []).push(arguments);
512-
}),
513-
(i[r].l = 1 * new Date());
514-
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
515-
a.async = 1;
516-
a.src = g;
517-
m.parentNode.insertBefore(a, m);
518-
})(
519-
window,
520-
document,
521-
'script',
522-
'//www.google-analytics.com/analytics.js',
523-
'ga',
524-
);
525-
526-
ga('create', 'UA-75839528-1', 'auto');
527-
ga('send', 'pageview');
528-
</script>
529519
</body>
530520
</html>

packages/jsondiffpatch/src/formatters/html.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class HtmlFormatter extends BaseFormatter<HtmlFormatterContext> {
3030
}
3131

3232
formatValue(context: HtmlFormatterContext, value: unknown) {
33-
context.out(`<pre>${htmlEscape(JSON.stringify(value, null, 2))}</pre>`);
33+
const valueAsHtml =
34+
typeof value === 'undefined'
35+
? 'undefined'
36+
: htmlEscape(JSON.stringify(value, null, 2));
37+
context.out(`<pre>${valueAsHtml}</pre>`);
3438
}
3539

3640
formatTextDiffString(context: HtmlFormatterContext, value: string) {

0 commit comments

Comments
 (0)