phhu / parse-diff

Unified diff parser for nodejs and browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status DevDeps Status Total downloads

NPM

parse-diff

Simple unified diff parser for nodejs

JavaScript Usage Example

// optional content transform function - defaults is removal of first character. Runs on add / del / normal lines 
var config = {
	// contentTransform: line=>(''+line).slice(1)
};
var parse = require('parse-diff')(config);
var diff = ''; // input diff string
var files = parse(diff);
console.log(files.length); // number of patched files
files.forEach(function(file) {
	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 a string
	console.log(file.deletions); // number of deletions in the patch
	console.log(file.additions); // number of additions in the patch
});

About

Unified diff parser for nodejs and browser

License:MIT License


Languages

Language:JavaScript 71.2%Language:CoffeeScript 28.8%