Implementation:APIJSON APIJSON Demo Diffview JS
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Diff_Visualization |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for rendering visual side-by-side or inline diff views from text line arrays and diff opcodes.
Description
The diffview JavaScript module (from jsdifflib by Chas Emerick) provides buildView which takes base/new text line arrays, opcodes from SequenceMatcher.get_opcodes(), and renders an HTML diff view. Supports side-by-side (viewType=0) and inline (viewType=1) modes with configurable context size.
Usage
Import this module when you need to display visual text diffs in the APIJSON testing UI for comparing API responses.
Code Reference
Source Location
- Repository: APIJSON_APIJSON_Demo
- File: APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/api/js/diffview.js
- Lines: 1-198
Signature
diffview = {
buildView: function (params) {
// params: baseTextLines, newTextLines, opcodes,
// baseTextName, newTextName, contextSize, viewType
// Returns HTML element
}
};
Import
<script src="diffview.js"></script>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| baseTextLines | Array<String> | Yes | Original text lines |
| newTextLines | Array<String> | Yes | Modified text lines |
| opcodes | Array | Yes | Diff opcodes from SequenceMatcher |
| viewType | Number | No | 0=side-by-side, 1=inline |
Outputs
| Name | Type | Description |
|---|---|---|
| buildView() returns | HTMLElement | Visual diff DOM element |
Usage Examples
Render Side-by-Side Diff
var diff = diffview.buildView({
baseTextLines: ["line1", "line2", "line3"],
newTextLines: ["line1", "modified", "line3"],
opcodes: matcher.get_opcodes(),
baseTextName: "Expected",
newTextName: "Actual",
viewType: 0
});
document.body.appendChild(diff);