Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

diff-match-patch-typescript

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff-match-patch-typescript

TypeScript port of diff-match-patch.

latest
Source
npmnpm
Version
1.1.3
Version published
Weekly downloads
2.1K
-52%
Maintainers
1
Weekly downloads
 
Created
Source

diff-match-patch-typescript

TypeScript port of google/diff-match-patch.

GitHub CI GitHub License NPM Downloads

Installation

npm i diff-match-patch-typescript

Usage

import { DiffMatchPatch, DiffOperation } from "diff-match-patch-typescript";

const dmp = new DiffMatchPatch();

// Diff
const diffs = dmp.diff_main("Hello World", "Hello TypeScript");
// [
//   [DiffOperation.DIFF_EQUAL, "Hello "],
//   [DiffOperation.DIFF_DELETE, "World"],
//   [DiffOperation.DIFF_INSERT, "TypeScript"]
// ]

// Match
const position = dmp.match_main("Hello World", "World", 0); // 6

// Patch
const patches = dmp.patch_make("Hello World", "Hello TypeScript");
const [newText, results] = dmp.patch_apply(patches, "Hello World");
// newText: "Hello TypeScript"
// results: [true]

API Reference

DiffMatchPatch Class Configuration

PropertyTypeDefaultDescription
diffTimeoutnumber1.0Seconds to compute a diff before giving up (0 = infinity).
diffEditCostnumber4Cost of an empty edit operation.
matchThresholdnumber0.5Threshold for match (0.0 = perfect, 1.0 = loose).
matchDistancenumber1000How far to search for a match.
patchDeleteThresholdnumber0.5Threshold for patch deletion matching.
patchMarginnumber4Chunk size for context length.

Diff functions

Match functions

  • match_main - Locates the best instance of a pattern in text near a given location.

Patch functions

Keywords

diff-match-patch-typescript

FAQs

Package last updated on 26 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts