Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@sanity/diff-match-patch
Advanced tools
Robust diff, match and patch algorithms to perform operations required for synchronizing plain text
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.
import {makePatches, applyPatches, stringifyPatches, parsePatches} from '@sanity/diff-match-patch'
// Make array of diffs in internal array format, eg tuples of `[DiffType, string]`
const patches = makePatches('from this', 'to this')
// Make unidiff-formatted (string) patch
const patch = stringifyPatches(patches)
// Apply the patch (array representation)
const [newValue] = applyPatches(patches, 'from this')
// Apply the patch (unidiff-formatted)
const [alsoNewValue] = applyPatches(parsePatch(patch), 'from this')
import {makeDiff} from '@sanity/diff-match-patch'
// Make an array of diff tuples, eg `[DiffType, string]`
const diff = makeDiff('from this', 'to this')
import {match} from '@sanity/diff-match-patch'
// Find position in text for the given pattern, at the approximate location given
const position = match('some text to match against', 'match', 9)
import {applyPatches} from '@sanity/diff-match-patch'
const [newValue, results] = applyPatches(patch, 'source text')
const matches = results.filter((matched) => matched === true).length
const misses = results.length - matches
console.log('Patch applied with %d matches and %d misses', matches, misses)
console.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:
-import {diff_match_patch as DiffMatchPatch} from 'diff-match-patch'
-const dmp = new DiffMatchPatch()
-const diffs = dmp.diff_main('from this', 'to this')
-dmp.diff_cleanupSemantic(diffs)
+import {makeDiff, cleanupSemantic} from '@sanity/diff-match-patch'
+const diffs = cleanupSemantic(makeDiff('from this', 'to this'))
-import {diff_match_patch as DiffMatchPatch} from 'diff-match-patch'
-const dmp = new DiffMatchPatch()
-const rawPatch = dmp.patch_make('from this', 'to this')
-const patch = rawPatch.map(p => p.toString()).join('')
+import {makePatches, stringifyPatches} from '@sanity/diff-match-patch'
+const patch = stringifyPatches(makePatches('from this', 'to this'))
-import {diff_match_patch as DiffMatchPatch} from 'diff-match-patch'
-const dmp = new DiffMatchPatch()
-const patch = dmp.patch_fromText('some-text-patch')
-const [newValue] = dmp.patch_apply(patch, 'source text')
+import {applyPatches, parsePatch} from '@sanity/diff-match-patch'
+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
FAQs
Robust diff, match and patch algorithms to perform operations required for synchronizing plain text
The npm package @sanity/diff-match-patch receives a total of 102,776 weekly downloads. As such, @sanity/diff-match-patch popularity was classified as popular.
We found that @sanity/diff-match-patch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 37 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.