Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions demos/html-demo/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,20 @@ const getExampleJson = function () {

const diffOptions = {
objectHash: function (obj, index) {
const objRecord = obj as Record<string, string>;
if (typeof objRecord._id !== 'undefined') {
return objRecord._id;
}
if (typeof objRecord.id !== 'undefined') {
return objRecord.id;
}
if (typeof objRecord.key !== 'undefined') {
return objRecord.key;
}
if (typeof objRecord.name !== 'undefined') {
return objRecord.name;
if (typeof obj === 'object' && obj !== null) {
const objRecord = obj as Record<string, string>;
if (typeof objRecord._id !== 'undefined') {
return objRecord._id;
}
if (typeof objRecord.id !== 'undefined') {
return objRecord.id;
}
if (typeof objRecord.key !== 'undefined') {
return objRecord.key;
}
if (typeof objRecord.name !== 'undefined') {
return objRecord.name;
}
}
return '$$index:' + index;
},
Expand Down
40 changes: 15 additions & 25 deletions demos/html-demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@
<meta content="utf-8" http-equiv="encoding" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />

<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-F2ZTFWQ8CL"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());

gtag('config', 'G-F2ZTFWQ8CL');
</script>

<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bulma/1.0.3/css/bulma.min.css"
Expand Down Expand Up @@ -501,30 +516,5 @@ <h2>Features</h2>
</p>
</footer>
<script src="build/demo.js" type="module"></script>

<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
(i[r] =
i[r] ||
function () {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(
window,
document,
'script',
'//www.google-analytics.com/analytics.js',
'ga',
);

ga('create', 'UA-75839528-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
6 changes: 5 additions & 1 deletion packages/jsondiffpatch/src/formatters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ class HtmlFormatter extends BaseFormatter<HtmlFormatterContext> {
}

formatValue(context: HtmlFormatterContext, value: unknown) {
context.out(`<pre>${htmlEscape(JSON.stringify(value, null, 2))}</pre>`);
const valueAsHtml =
typeof value === 'undefined'
? 'undefined'
: htmlEscape(JSON.stringify(value, null, 2));
context.out(`<pre>${valueAsHtml}</pre>`);
}

formatTextDiffString(context: HtmlFormatterContext, value: string) {
Expand Down