git-diff-parser is a minimalist JavaScript library designed for parsing the output of `git diff` and `git format-patch` commands into a structured object representation. It provides a way to programmatically analyze changes, including commit details, file additions/deletions, renames, and line-by-line diff information. Released as version 1.0.0, the package appears to have seen no significant updates since its initial creation around 2014, as indicated by the license date and README notes. The author explicitly states it was created quickly with "no error handling or tests of any sorts implemented yet," suggesting it is a raw utility rather than a robust, production-ready parser. This also implies an irregular, likely non-existent, release cadence. Its primary differentiator is its simplicity and directness in parsing, suitable for quick, personal scripting where robust error handling is not critical. Alternatives often offer more comprehensive parsing, testing, and active maintenance.
npm install git-diff-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a raw Git diff string using `git-diff-parser` and iterate through the resulting commit and file objects to display changes.
Implement custom error handling around the parser calls, validate input diff strings, and thoroughly test with expected and unexpected diff formats relevant to your use case.
For critical applications, consider using actively maintained alternatives or be prepared to fork and maintain the library yourself to ensure compatibility and security.
Use `const parser = require('git-diff-parser');` in Node.js environments. If using with ESM, ensure your build setup (e.g., Webpack, Rollup, esbuild) correctly handles CommonJS module interoperability.Ensure the input diff string is valid and adheres to standard `git diff` output. If the issue persists with valid diffs, the parser itself may not support that specific format. Consider pre-processing the diff or switching to a more robust parser.
Use the ESM import syntax: `import parser from 'git-diff-parser';`. If the package only provides CommonJS and you must use `require` in an ESM context, you might need to use `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const parser = require('git-diff-parser');` (Node.js specific).No dependency data recorded yet.