explaingit

joshuakgoldberg/jsdiff

Analysis updated 2026-07-08 · repo last pushed 2024-10-27

Audience · developerComplexity · 2/5StaleLicenseSetup · easy

TLDR

jsdiff is a JavaScript library that compares two pieces of text and shows exactly what was added, deleted, or kept the same. It powers features like track changes in document editors.

Mindmap

mindmap
  root((repo))
    What it does
      Compares text changes
      Finds added and deleted words
      Supports JSON CSS and plain text
    How it works
      Chops text into tokens
      Analyzes token changes
      Returns list of changes
    Use cases
      Collaborative writing tools
      Note-taking apps
      Code review highlights
    Flexibility
      Handles different languages
      Limits work on large files
      Customizable token matching
    Tech stack
      JavaScript
      Internationalization APIs
      Patch file support
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Build a collaborative writing tool that highlights what a co-author added or removed.

USE CASE 2

Create a note-taking app that shows edits between saved versions of a document.

USE CASE 3

Compare two JSON objects and see exactly which fields changed.

USE CASE 4

Generate and apply standard patch files for tracking text changes.

What is it built with?

JavaScript

How does it compare?

joshuakgoldberg/jsdiff0xhassaan/nn-from-scratch0xzgbot/hermes-comfyui-skills
Stars00
LanguagePython
Last pushed2024-10-27
MaintenanceStale
Setup difficultyeasymoderateeasy
Complexity2/54/51/5
Audiencedeveloperdeveloperdesigner

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Install via npm and import the diff functions directly, no external dependencies or configuration required.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

jsdiff is a JavaScript library that compares two pieces of text and tells you exactly what changed between them. Think of it as the engine behind the "track changes" feature in a document editor or the red and green highlights you see when reviewing code changes online. It figures out which words, lines, or characters were added, deleted, or kept the same when going from an original version to a new one. At a high level, the library works in three steps. First, it chops both the old and new text into smaller pieces called "tokens." A token can be whatever you want: a single character, a whole word, a sentence, or an entire line. Second, it analyzes those tokens to find the smallest set of insertions and deletions needed to transform the old text into the new text. Finally, it hands you a straightforward list showing the sequence of changes, noting which tokens were added, removed, or left alone. You can tweak how it decides if two tokens are "equal," such as telling it to ignore uppercase and lowercase differences. The library is useful for anyone building an app that needs to show changes in text. For example, if you are building a collaborative writing tool and want to show users what their co-author just added, or a note-taking app that highlights edits between versions, this library does the heavy lifting for you. It includes specific tools for comparing different formats out of the box, like JSON objects, CSS code, or standard plain text, and can even generate and apply standard "patch" files used in software development. One notable thing about the project is its flexibility in how it handles different languages and granularities. For instance, it can break text into words using built-in internationalization tools, which means it can accurately identify word boundaries in languages like Chinese that don't use spaces. It also lets you set limits on how hard it works, so if you accidentally compare two massive, completely different documents, you can tell it to give up early rather than freezing your application.

Copy-paste prompts

Prompt 1
Using the jsdiff library in JavaScript, write a function that takes two strings and returns a list of words that were added, removed, or kept the same.
Prompt 2
Use jsdiff to compare two JSON objects and output a human-readable summary of which fields were added, changed, or deleted.
Prompt 3
Create a JavaScript snippet using jsdiff that compares two versions of a plain text document and outputs an HTML diff view with green highlights for additions and red strikethrough for deletions.
Prompt 4
Using jsdiff, write a function that breaks text into word tokens while respecting Chinese word boundaries, then compares two Chinese text strings and logs the differences.

Frequently asked questions

What is jsdiff?

jsdiff is a JavaScript library that compares two pieces of text and shows exactly what was added, deleted, or kept the same. It powers features like track changes in document editors.

Is jsdiff actively maintained?

Stale — no commits in 1-2 years (last push 2024-10-27).

What license does jsdiff use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is jsdiff to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is jsdiff for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.