parse-diff
Advanced tools
Comparing version
27
index.js
var defaultToWhiteSpace, escapeRegExp, ltrim, makeString, parseFile, parseFileFallback, trimLeft; | ||
module.exports = function(input) { | ||
var add, chunk, current, del, deleted_file, file, files, from_file, index, j, len, line, lines, ln_add, ln_del, new_file, noeol, normal, parse, restart, schema, start, to_file; | ||
var add, chunk, current, del, deleted_file, eof, file, files, from_file, index, j, len, line, lines, ln_add, ln_del, new_file, normal, parse, restart, schema, start, to_file; | ||
if (!input) { | ||
@@ -97,16 +97,27 @@ return []; | ||
}; | ||
noeol = '\\ No newline at end of file'; | ||
normal = function(line) { | ||
if (!file) { | ||
return; | ||
} | ||
return current.changes.push({ | ||
type: 'normal', | ||
normal: true, | ||
ln1: line !== noeol ? ln_del++ : void 0, | ||
ln2: line !== noeol ? ln_add++ : void 0, | ||
ln1: ln_del++, | ||
ln2: ln_add++, | ||
content: line | ||
}); | ||
}; | ||
schema = [[/^\s+/, normal], [/^diff\s/, start], [/^new file mode \d+$/, new_file], [/^deleted file mode \d+$/, deleted_file], [/^index\s[\da-zA-Z]+\.\.[\da-zA-Z]+(\s(\d+))?$/, index], [/^---\s/, from_file], [/^\+\+\+\s/, to_file], [/^@@\s+\-(\d+),?(\d+)?\s+\+(\d+),?(\d+)?\s@@/, chunk], [/^-/, del], [/^\+/, add]]; | ||
eof = function(line) { | ||
var obj, recentChange, ref; | ||
ref = current.changes, recentChange = ref[ref.length - 1]; | ||
return current.changes.push(( | ||
obj = { | ||
type: recentChange.type | ||
}, | ||
obj["" + recentChange.type] = true, | ||
obj.ln1 = recentChange.ln1, | ||
obj.ln2 = recentChange.ln2, | ||
obj.ln = recentChange.ln, | ||
obj.content = line, | ||
obj | ||
)); | ||
}; | ||
schema = [[/^\s+/, normal], [/^diff\s/, start], [/^new file mode \d+$/, new_file], [/^deleted file mode \d+$/, deleted_file], [/^index\s[\da-zA-Z]+\.\.[\da-zA-Z]+(\s(\d+))?$/, index], [/^---\s/, from_file], [/^\+\+\+\s/, to_file], [/^@@\s+\-(\d+),?(\d+)?\s+\+(\d+),?(\d+)?\s@@/, chunk], [/^-/, del], [/^\+/, add], [/^\\ No newline at end of file$/, eof]]; | ||
parse = function(line) { | ||
@@ -113,0 +124,0 @@ var j, len, m, p; |
{ | ||
"name": "parse-diff", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Unified diff parser", | ||
@@ -21,2 +21,3 @@ "author": "Sergey Todyshev <stodyshev@gmail.com>", | ||
"Scott Christopherson <scott@scott-christopherson.com>", | ||
"DAB0mB <emanor6@gmail.com>", | ||
"Quest <quest@lysator.liu.se>", | ||
@@ -27,12 +28,12 @@ "Sung Won Cho <mikeswcho@gmail.com>", | ||
"devDependencies": { | ||
"coffee-script": "^1.10.0", | ||
"coffeelint": "^1.14.2", | ||
"coffee-script": "^1.11.1", | ||
"coffeelint": "^1.16.0", | ||
"expect.js": "^0.3.1", | ||
"grunt": "^0.4.5", | ||
"grunt": "^1.0.1", | ||
"grunt-auto-release": "^0.0.6", | ||
"grunt-bump": "^0.7.0", | ||
"grunt-cli": "^0.1.13", | ||
"grunt-coffeelint": "^0.0.13", | ||
"grunt-contrib-coffee": "^0.13.0", | ||
"grunt-contrib-jshint": "^0.11.3", | ||
"grunt-bump": "^0.8.0", | ||
"grunt-cli": "^1.2.0", | ||
"grunt-coffeelint": "^0.0.16", | ||
"grunt-contrib-coffee": "^1.0.0", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-npm": "^0.0.2", | ||
@@ -39,0 +40,0 @@ "grunt-simple-mocha": "^0.4.1" |
[](http://gruntjs.com/) | ||
[](https://drone.io/github.com/sergeyt/parse-diff/latest) | ||
[](https://travis-ci.org/sergeyt/parse-diff) | ||
[](https://david-dm.org/sergeyt/parse-diff#info=devDependencies) | ||
@@ -4,0 +4,0 @@ [](https://www.npmjs.com/package/parse-diff) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21847
6.29%11
22.22%193
6.04%