Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON Demo Diffview JS

From Leeroopedia
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

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);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment