Registry / data / diffparser

diffparser

JSON →
library2.0.1jsnpmunverified

diffparser is a robust JavaScript library specifically engineered for parsing unified diff format strings, which are the standard output for showing changes between files in version control systems like Git. Currently stable at version 2.0.1, the project appears to follow a feature-driven release cadence, with its latest major iteration focusing on modern JavaScript (ES2015) syntax and module patterns. A primary differentiator of diffparser is its capability to generate position information for individual changes, which is a critical requirement for integrating with services such as the GitHub Comments API for precise inline commenting. Furthermore, it offers an optional but powerful rename detection feature, allowing users to accurately identify files that have been renamed within a diff. This package serves as an actively maintained, ES2015-native spiritual successor to the earlier parse-diff project, providing a clean API and a comprehensive test suite for reliable diff processing in both Node.js and browser environments.

data
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Since v2.0.0, diffparser is distributed as an ES module. CommonJS `require()` is not supported. Ensure your project is configured for ESM.

import parse from 'diffparser';

Demonstrates parsing a basic unified diff and an example with rename detection.

import parse from 'diffparser'; const diffContent = ` diff --git a/file b/file index 123..456 789 --- a/file +++ b/file @@ -1,2 +1,2 @@ - line1 + line2 `; const parsedDiff = parse(diffContent); console.log(JSON.stringify(parsedDiff, null, 2)); const diffWithRename = ` diff --git a/oldfile b/newfile rename from oldfile rename to newfile index 0000000..4e4b354 --- a/oldfile +++ b/newfile @@ -1 +1 @@ -hello +world `; const parsedRename = parse(diffWithRename, { findRenames: true }); console.log(JSON.stringify(parsedRename, null, 2));
Debug
Known footguns
breakingdiffparser transitioned to an ES module (ESM) in version 2.0.0. This means traditional CommonJS `require()` syntax will no longer work, leading to import errors.
gotchaThe parser expects input strings to strictly adhere to the unified diff format. Malformed or incomplete diffs can lead to parsing errors or unexpected output structures.
gotchaBy default, diffparser does not detect file renames. To identify renamed files, you must explicitly enable the `findRenames` option.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources