gitdiff-parser is a JavaScript/TypeScript library designed to programmatically parse the output of the standard `git diff` command into a structured data format. It aims for speed and reliability in processing various `git diff` outputs, including additions, deletions, modifications, and renames, extracting details like file paths, modes, hunks, and individual line changes. The current stable version is 0.3.1, indicating that it is in a pre-1.0 development phase where API changes might occur more frequently than in a major stable release. It provides a robust, typed interface for accessing file, hunk, and change-level details from raw diff strings, making it suitable for building tools that need to analyze or manipulate repository changes programmatically, such as code review tools, linters, or continuous integration systems.
npm install gitdiff-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install the package, import the parser, feed it a sample `git diff` string, and inspect the structured output including files, hunks, and individual changes.
Always pin to exact versions (e.g., `"gitdiff-parser": "0.3.1"`) and review the changelog thoroughly before upgrading. Consider using tools like `npm-check-updates` with care.
Ensure the `git diff` command used to generate the input produces standard, clean output. Test with simplified diffs to isolate parsing issues. If encountering consistent problems with seemingly valid diffs, report them to the library's issue tracker with the problematic diff content.
For very large diffs, consider strategies such as chunking the diff input if feasible, processing diffs in a separate worker thread, or optimizing the source of the diff to only include relevant changes.
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`) and use `import gitDiffParser from 'gitdiff-parser';`. If you must use CommonJS, you might need a bundler like Webpack or Rollup, or ensure your `tsconfig.json` (for TypeScript) is configured with `"module": "NodeNext"` or `"CommonJS"` and appropriate `moduleResolution`.
The `parse` function is a method of the default export object. Use `import gitDiffParser from 'gitdiff-parser';` then call it via `gitDiffParser.parse(...)`.
When importing types, use the `import type` syntax: `import type { File, Hunk, Change } from 'gitdiff-parser';`.Double-check the exact output of your `git diff` command. Try simplifying the diff content to isolate the problematic part. Verify line endings and encoding. If the issue persists, file a bug report on the library's GitHub repository, including the exact diff string that causes the problem.
No dependency data recorded yet.