Gathering detailed insights and metrics for @sanity/diff-match-patch
Gathering detailed insights and metrics for @sanity/diff-match-patch
Gathering detailed insights and metrics for @sanity/diff-match-patch
Gathering detailed insights and metrics for @sanity/diff-match-patch
npm install @sanity/diff-match-patch
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.4
Supply Chain
99.6
Quality
91.9
Maintenance
100
Vulnerability
100
License
Total Downloads
5,638,180
Last Day
28,639
Last Week
134,841
Last Month
571,052
Last Year
4,677,472
Latest Version
3.2.0
Package Id
@sanity/diff-match-patch@3.2.0
Unpacked Size
458.56 kB
Size
110.05 kB
File Count
40
NPM Version
10.9.2
Node Version
22.12.0
Publised On
22 Jan 2025
Cumulative downloads
Total Downloads
Last day
-21.1%
28,639
Compared to previous day
Last week
-17.6%
134,841
Compared to previous week
Last month
31%
571,052
Compared to previous month
Last year
387.4%
4,677,472
Compared to previous year
24
A TypeScript fork of the JavaScript version of google/diff-match-patch, that includes a few long-standing pull requests, fixing certain bugs and with an API more familiar to the JavaScript ecosystem.
npm install --save @sanity/diff-match-patch
The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text.
Originally built in 2006 to power Google Docs, this library is now available in C++, C#, Dart, Java, JavaScript, Lua, Objective C, and Python.
1import {makePatches, applyPatches, stringifyPatches, parsePatches} from '@sanity/diff-match-patch' 2 3// Make array of diffs in internal array format, eg tuples of `[DiffType, string]` 4const patches = makePatches('from this', 'to this') 5 6// Make unidiff-formatted (string) patch 7const patch = stringifyPatches(patches) 8 9// Apply the patch (array representation) 10const [newValue] = applyPatches(patches, 'from this') 11 12// Apply the patch (unidiff-formatted) 13const [alsoNewValue] = applyPatches(parsePatch(patch), 'from this')
1import {makeDiff} from '@sanity/diff-match-patch' 2 3// Make an array of diff tuples, eg `[DiffType, string]` 4const diff = makeDiff('from this', 'to this')
1import {match} from '@sanity/diff-match-patch' 2 3// Find position in text for the given pattern, at the approximate location given 4const position = match('some text to match against', 'match', 9)
1import {applyPatches} from '@sanity/diff-match-patch' 2 3const [newValue, results] = applyPatches(patch, 'source text') 4const matches = results.filter((matched) => matched === true).length 5const misses = results.length - matches 6console.log('Patch applied with %d matches and %d misses', matches, misses) 7console.log('New value: %s', newValue)
diff-match-patch
The original library that this is a fork of has a different API, meaning this fork is not a drop-in replacement. Here's a breakdown of the most common operations and their API differences:
1-import {diff_match_patch as DiffMatchPatch} from 'diff-match-patch' 2-const dmp = new DiffMatchPatch() 3-const diffs = dmp.diff_main('from this', 'to this') 4-dmp.diff_cleanupSemantic(diffs) 5+import {makeDiff, cleanupSemantic} from '@sanity/diff-match-patch' 6+const diffs = cleanupSemantic(makeDiff('from this', 'to this'))
1-import {diff_match_patch as DiffMatchPatch} from 'diff-match-patch' 2-const dmp = new DiffMatchPatch() 3-const rawPatch = dmp.patch_make('from this', 'to this') 4-const patch = rawPatch.map(p => p.toString()).join('') 5+import {makePatches, stringifyPatches} from '@sanity/diff-match-patch' 6+const patch = stringifyPatches(makePatches('from this', 'to this'))
1-import {diff_match_patch as DiffMatchPatch} from 'diff-match-patch' 2-const dmp = new DiffMatchPatch() 3-const patch = dmp.patch_fromText('some-text-patch') 4-const [newValue] = dmp.patch_apply(patch, 'source text') 5+import {applyPatches, parsePatch} from '@sanity/diff-match-patch' 6+const [newValue] = applyPatches(parsePatch('some-text-patch'), 'source text')
This library implements Myer's diff algorithm which is generally considered to be the best general-purpose diff. A layer of pre-diff speedups and post-diff cleanups surround the diff algorithm, improving both performance and output quality.
This library also implements a Bitap matching algorithm at the heart of a flexible matching and patching strategy.
This fork has a few modifications to the original:
DiffMatchPatch
prototype. Enables better tree-shaking.Apache-2.0 Copyright 2018 The diff-match-patch Authors https://github.com/google/diff-match-patch
No vulnerabilities found.
No security vulnerabilities found.