gitwtfhub

wtf is jsdiff?

joshuakgoldberg/jsdiff — explained in plain English

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

Audience · developerComplexity · 2/5StaleLicenseSetup · easy

TL;DR

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

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

Why would anyone build with this?

REASON 1

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

REASON 2

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

REASON 3

Compare two JSON objects and see exactly which fields changed.

REASON 4

Generate and apply standard patch files for tracking text changes.

What's in the stack?

JavaScript

How it stacks up

joshuakgoldberg/jsdiff0verflowme/alarm-clock0xhassaan/nn-from-scratch
Stars0
LanguageCSSPython
Last pushed2024-10-272022-10-03
MaintenanceStaleDormant
Setup difficultyeasyeasymoderate
Complexity2/52/54/5
Audiencedevelopervibe coderdeveloper

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

How do you spin it up?

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.

Wtf does this do

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.

Yoink these 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

wtf 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.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.