parse-diff
Advanced tools
Comparing version 0.0.15 to 0.1.0
@@ -9,3 +9,3 @@ (function() { | ||
module.exports = function(input) { | ||
var add, chunk, del, deleted_file, file, files, from_file, i, index, len, line, lines, ln_add, ln_del, new_file, noeol, normal, parse, restart, schema, start, to_file; | ||
var add, chunk, current, del, deleted_file, file, files, from_file, i, index, len, line, lines, ln_add, ln_del, new_file, noeol, normal, parse, restart, schema, start, to_file; | ||
if (!input) { | ||
@@ -25,5 +25,6 @@ return []; | ||
ln_add = 0; | ||
current = null; | ||
start = function() { | ||
file = { | ||
lines: [], | ||
chunks: [], | ||
deletions: 0, | ||
@@ -35,3 +36,3 @@ additions: 0 | ||
restart = function() { | ||
if (!file || file.lines.length) { | ||
if (!file || file.chunks.length) { | ||
return start(); | ||
@@ -61,12 +62,19 @@ } | ||
chunk = function(line, match) { | ||
ln_del = +match[1]; | ||
ln_add = +match[3]; | ||
return file.lines.push({ | ||
type: 'chunk', | ||
chunk: true, | ||
content: line | ||
}); | ||
var newLines, newStart, oldLines, oldStart; | ||
ln_del = oldStart = +match[1]; | ||
oldLines = +(match[2] || 0); | ||
ln_add = newStart = +match[3]; | ||
newLines = +(match[4] || 0); | ||
current = { | ||
content: line, | ||
changes: [], | ||
oldStart: oldStart, | ||
oldLines: oldLines, | ||
newStart: newStart, | ||
newLines: newLines | ||
}; | ||
return file.chunks.push(current); | ||
}; | ||
del = function(line) { | ||
file.lines.push({ | ||
current.changes.push({ | ||
type: 'del', | ||
@@ -80,3 +88,3 @@ del: true, | ||
add = function(line) { | ||
file.lines.push({ | ||
current.changes.push({ | ||
type: 'add', | ||
@@ -94,3 +102,3 @@ add: true, | ||
} | ||
return file.lines.push({ | ||
return current.changes.push({ | ||
type: 'normal', | ||
@@ -130,3 +138,3 @@ normal: true, | ||
s = s.trim(); | ||
t = /\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d(.\d+)?\s(\+|-)\d\d\d\d/.exec(s); | ||
t = /\t.*|\d{4}-\d\d-\d\d\s\d\d:\d\d:\d\d(.\d+)?\s(\+|-)\d\d\d\d/.exec(s); | ||
if (t) { | ||
@@ -133,0 +141,0 @@ s = s.substring(0, t.index).trim(); |
require('coffee-script/register'); | ||
module.exports = require('./parse'); |
{ | ||
"name": "parse-diff", | ||
"version": "0.0.15", | ||
"version": "0.1.0", | ||
"description": "Unified diff parser", | ||
@@ -18,3 +18,5 @@ "author": "Sergey Todyshev <stodyshev@gmail.com>", | ||
"Sergey Todyshev <stodyshev@gmail.com>", | ||
"Scott Christopherson <scott@scott-christopherson.com>" | ||
"Quest <quest@windwards.net>", | ||
"Scott Christopherson <scott@scott-christopherson.com>", | ||
"Quest <quest@lysator.liu.se>" | ||
], | ||
@@ -24,6 +26,6 @@ "dependencies": { | ||
"underscore": "~1.8", | ||
"underscore.string": "~3.0" | ||
"underscore.string": "~3.1" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4", | ||
"grunt": "~0.4.5", | ||
"grunt-contrib-jshint": "~0.11", | ||
@@ -30,0 +32,0 @@ "grunt-coffeelint": "~0.0.13", |
@@ -20,4 +20,5 @@ [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/) | ||
files.forEach(function(file) { | ||
console.log(file.lines.length); // number of hunk/added/deleted lines | ||
// each line in file.lines is a string | ||
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 | ||
@@ -24,0 +25,0 @@ console.log(file.additions); // number of additions in the patch |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17493
141
27
+ Addedunderscore.string@3.1.1(transitive)
- Removedunderscore.string@3.0.3(transitive)
Updatedunderscore.string@~3.1