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 Difflib JS

From Leeroopedia
Knowledge Sources
Domains Frontend, Diff_Algorithm
Last Updated 2026-10-14 00:00 GMT

Overview

Vendored jsdifflib library providing sequence matching and diff computation algorithms for comparing text in the APIJSON Demo testing UI.

Description

The difflib JavaScript module (from jsdifflib by Chas Emerick) implements the Python difflib.SequenceMatcher algorithm in JavaScript. It provides difflib.stringAsLines(), difflib.SequenceMatcher with get_opcodes(), and difflib.deepCopy. It is used alongside Implementation:APIJSON_APIJSON_Demo_Diffview_JS to render visual diffs of API responses.

Usage

Include difflib.js before diffview.js when you need to compute and display text diffs in the APIJSON testing UI.

Code Reference

Source Location

  • Repository: jsdifflib
  • File: static/unit/js/difflib.js (L1-413)

Signature

var difflib = {
  stringAsLines: function(str) { ... },
  SequenceMatcher: function(baseTextLines, newTextLines) {
    this.get_opcodes: function() { ... };
    // ...
  },
  deepCopy: function(obj) { ... }
};

I/O Contract

Inputs

Name Type Required Description
baseTextLines Array<String> Yes Original text lines
newTextLines Array<String> Yes Modified text lines

Outputs

Name Type Description
get_opcodes() returns Array Diff opcodes (equal, replace, delete, insert)

Usage Examples

Compute Diff Opcodes

var difflib = require("./difflib");

var matcher = new difflib.SequenceMatcher(
  difflib.stringAsLines("hello\nworld"),
  difflib.stringAsLines("hello\nearth")
);
var opcodes = matcher.get_opcodes();
// [ ['equal', 0, 1, 0, 1], ['replace', 1, 2, 1, 2] ]

Related Pages

Page Connections

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