Skip to content

Latest commit

 

History

History
30 lines (23 loc) · 1.23 KB

README.md

File metadata and controls

30 lines (23 loc) · 1.23 KB

Build Status Total downloads

NPM

parse-diff

Simple unified diff parser for JavaScript and TypeScript

TypeScript Usage Example

import parse from "parse-diff";

const diff = ""; // input diff string
const files = parse(diff);
console.log(files.length); // number of patched files
for (const file of files) {
  console.log(file.chunks.length); // number of hunks
  console.log(file.chunks[0].changes.length); // hunk added/deleted/context lines
  // each item in changes is an object; its text is in `content`
  console.log(file.deletions); // number of deletions in the patch
  console.log(file.additions); // number of additions in the patch
}

Types are bundled with the package. Use import parse = require("parse-diff") if your tsconfig.json has neither esModuleInterop nor allowSyntheticDefaultImports enabled. In plain CommonJS JavaScript, use const parse = require("parse-diff").