json-diff-kit
Advanced tools
Comparing version 1.0.21 to 1.0.22
@@ -11,3 +11,3 @@ 'use strict'; | ||
exports.Differ = differ; | ||
exports.Differ = differ["default"]; | ||
exports.Viewer = viewer; |
@@ -596,2 +596,11 @@ 'use strict'; | ||
} | ||
if (text === 'undefined' || text === 'Infinity' || text === '-Infinity' || text === 'NaN' || /^\d+n$/i.test(text) || text.startsWith('Symbol(') || text.startsWith('function') || text.startsWith('(')) { | ||
return [ | ||
{ | ||
token: 'invalid', | ||
start: offset, | ||
end: text.length + offset | ||
} | ||
]; | ||
} | ||
if (!Number.isNaN(Number(text))) { | ||
@@ -706,4 +715,4 @@ return [ | ||
}; | ||
const getSegments = (l, r, options)=>{ | ||
if (!options) { | ||
const getSegments = (l, r, options, jsonsAreEqual)=>{ | ||
if (!options || jsonsAreEqual) { | ||
return [ | ||
@@ -818,5 +827,15 @@ { | ||
const DEFAULT_EXPAND_MORE_LINES_LIMIT = 20; | ||
const DEFAULT_TEXTS = { | ||
noChangeDetected: 'No change detected' | ||
}; | ||
const Viewer = (props)=>{ | ||
var _props_inlineDiffOptions, _props_inlineDiffOptions1; | ||
const [linesLeft, linesRight] = props.diff; | ||
const jsonsAreEqual = React__namespace.useMemo(()=>{ | ||
return linesLeft.length === linesRight.length && linesLeft.every((item)=>item.type === 'equal') && linesRight.every((item)=>item.type === 'equal'); | ||
}, [ | ||
linesLeft, | ||
linesRight | ||
]); | ||
const mergedTexts = _extends({}, DEFAULT_TEXTS, props.texts); | ||
const lineNumberWidth = props.lineNumbers ? `calc(${String(linesLeft.length).length}ch + 16px)` : 0; | ||
@@ -840,3 +859,3 @@ var _props_indent; | ||
const linesRightRef = React__namespace.useRef(linesRight); | ||
const segmentsRef = React__namespace.useRef(getSegments(linesLeft, linesRight, hideUnchangedLines)); | ||
const segmentsRef = React__namespace.useRef(getSegments(linesLeft, linesRight, hideUnchangedLines, jsonsAreEqual)); | ||
const accTopRef = React__namespace.useRef([]); | ||
@@ -871,3 +890,3 @@ const totalHeightRef = React__namespace.useRef(0); | ||
linesRightRef.current = linesRight; | ||
segmentsRef.current = getSegments(linesLeft, linesRight, hideUnchangedLines); | ||
segmentsRef.current = getSegments(linesLeft, linesRight, hideUnchangedLines, jsonsAreEqual); | ||
updateViewer(); | ||
@@ -1005,7 +1024,7 @@ }, [ | ||
onClick: ()=>onExpandBefore(index)(expandMoreLinesLimit) | ||
}, "⬆️ Show ", expandMoreLinesLimit, " lines before"), /*#__PURE__*/ React__namespace.createElement("button", { | ||
}, "⭡ Show ", expandMoreLinesLimit, " lines before"), /*#__PURE__*/ React__namespace.createElement("button", { | ||
onClick: ()=>onExpandAll(index)() | ||
}, "↕️ Show all unchanged lines"), hasLinesAfter && /*#__PURE__*/ React__namespace.createElement("button", { | ||
}, "⭥ Show all unchanged lines"), hasLinesAfter && /*#__PURE__*/ React__namespace.createElement("button", { | ||
onClick: ()=>onExpandAfter(index)(expandMoreLinesLimit) | ||
}, "⬇️ Show ", expandMoreLinesLimit, " lines after")); | ||
}, "⭣ Show ", expandMoreLinesLimit, " lines after")); | ||
}; | ||
@@ -1041,2 +1060,10 @@ const renderSegment = (segment, index, renderStart, renderEnd, syntaxHighlightEnabled)=>{ | ||
const renderTbody = (syntaxHighlightEnabled)=>{ | ||
if (jsonsAreEqual && hideUnchangedLines) { | ||
return /*#__PURE__*/ React__namespace.createElement("tr", { | ||
key: "message-line", | ||
className: "message-line" | ||
}, /*#__PURE__*/ React__namespace.createElement("td", { | ||
colSpan: 4 | ||
}, mergedTexts.noChangeDetected)); | ||
} | ||
if (!props.virtual) { | ||
@@ -1043,0 +1070,0 @@ return segmentsRef.current.map((item, index)=>renderSegment(item, index, 0, linesLeftRef.current.length, syntaxHighlightEnabled)); |
@@ -574,2 +574,11 @@ import * as React from 'react'; | ||
} | ||
if (text === 'undefined' || text === 'Infinity' || text === '-Infinity' || text === 'NaN' || /^\d+n$/i.test(text) || text.startsWith('Symbol(') || text.startsWith('function') || text.startsWith('(')) { | ||
return [ | ||
{ | ||
token: 'invalid', | ||
start: offset, | ||
end: text.length + offset | ||
} | ||
]; | ||
} | ||
if (!Number.isNaN(Number(text))) { | ||
@@ -684,4 +693,4 @@ return [ | ||
}; | ||
const getSegments = (l, r, options)=>{ | ||
if (!options) { | ||
const getSegments = (l, r, options, jsonsAreEqual)=>{ | ||
if (!options || jsonsAreEqual) { | ||
return [ | ||
@@ -796,5 +805,15 @@ { | ||
const DEFAULT_EXPAND_MORE_LINES_LIMIT = 20; | ||
const DEFAULT_TEXTS = { | ||
noChangeDetected: 'No change detected' | ||
}; | ||
const Viewer = (props)=>{ | ||
var _props_inlineDiffOptions, _props_inlineDiffOptions1; | ||
const [linesLeft, linesRight] = props.diff; | ||
const jsonsAreEqual = React.useMemo(()=>{ | ||
return linesLeft.length === linesRight.length && linesLeft.every((item)=>item.type === 'equal') && linesRight.every((item)=>item.type === 'equal'); | ||
}, [ | ||
linesLeft, | ||
linesRight | ||
]); | ||
const mergedTexts = _extends({}, DEFAULT_TEXTS, props.texts); | ||
const lineNumberWidth = props.lineNumbers ? `calc(${String(linesLeft.length).length}ch + 16px)` : 0; | ||
@@ -818,3 +837,3 @@ var _props_indent; | ||
const linesRightRef = React.useRef(linesRight); | ||
const segmentsRef = React.useRef(getSegments(linesLeft, linesRight, hideUnchangedLines)); | ||
const segmentsRef = React.useRef(getSegments(linesLeft, linesRight, hideUnchangedLines, jsonsAreEqual)); | ||
const accTopRef = React.useRef([]); | ||
@@ -849,3 +868,3 @@ const totalHeightRef = React.useRef(0); | ||
linesRightRef.current = linesRight; | ||
segmentsRef.current = getSegments(linesLeft, linesRight, hideUnchangedLines); | ||
segmentsRef.current = getSegments(linesLeft, linesRight, hideUnchangedLines, jsonsAreEqual); | ||
updateViewer(); | ||
@@ -983,7 +1002,7 @@ }, [ | ||
onClick: ()=>onExpandBefore(index)(expandMoreLinesLimit) | ||
}, "⬆️ Show ", expandMoreLinesLimit, " lines before"), /*#__PURE__*/ React.createElement("button", { | ||
}, "⭡ Show ", expandMoreLinesLimit, " lines before"), /*#__PURE__*/ React.createElement("button", { | ||
onClick: ()=>onExpandAll(index)() | ||
}, "↕️ Show all unchanged lines"), hasLinesAfter && /*#__PURE__*/ React.createElement("button", { | ||
}, "⭥ Show all unchanged lines"), hasLinesAfter && /*#__PURE__*/ React.createElement("button", { | ||
onClick: ()=>onExpandAfter(index)(expandMoreLinesLimit) | ||
}, "⬇️ Show ", expandMoreLinesLimit, " lines after")); | ||
}, "⭣ Show ", expandMoreLinesLimit, " lines after")); | ||
}; | ||
@@ -1019,2 +1038,10 @@ const renderSegment = (segment, index, renderStart, renderEnd, syntaxHighlightEnabled)=>{ | ||
const renderTbody = (syntaxHighlightEnabled)=>{ | ||
if (jsonsAreEqual && hideUnchangedLines) { | ||
return /*#__PURE__*/ React.createElement("tr", { | ||
key: "message-line", | ||
className: "message-line" | ||
}, /*#__PURE__*/ React.createElement("td", { | ||
colSpan: 4 | ||
}, mergedTexts.noChangeDetected)); | ||
} | ||
if (!props.virtual) { | ||
@@ -1021,0 +1048,0 @@ return segmentsRef.current.map((item, index)=>renderSegment(item, index, 0, linesLeftRef.current.length, syntaxHighlightEnabled)); |
{ | ||
"name": "json-diff-kit", | ||
"version": "1.0.21", | ||
"version": "1.0.22", | ||
"description": "A better JSON differ & viewer.", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
@@ -121,5 +121,5 @@ # JSON Diff Kit | ||
- [x] Generate code directly in the demo page (covered by playground) | ||
- [x] Optimise `Viewer` performance by adding virtual scrolling | ||
- [ ] Add CLI tool | ||
- [ ] Improve unit tests | ||
- [ ] Optimise `Viewer` performance by adding virtual scrolling | ||
- [ ] Provide a Vue version of `Viewer` | ||
@@ -126,0 +126,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
890552
68
11369