parse-diff
Advanced tools
Comparing version 0.2.0 to 0.3.0
48
index.js
@@ -1,5 +0,5 @@ | ||
var defaultToWhiteSpace, escapeRegExp, ltrim, makeString, parseFile, trimLeft; | ||
var defaultToWhiteSpace, escapeRegExp, ltrim, makeString, parseFile, parseFileFallback, trimLeft; | ||
module.exports = function(input) { | ||
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; | ||
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; | ||
if (!input) { | ||
@@ -20,3 +20,4 @@ return []; | ||
current = null; | ||
start = function() { | ||
start = function(line) { | ||
var fileNames; | ||
file = { | ||
@@ -27,3 +28,10 @@ chunks: [], | ||
}; | ||
return files.push(file); | ||
files.push(file); | ||
if (!file.to && !file.from) { | ||
fileNames = parseFile(line); | ||
if (fileNames) { | ||
file.from = fileNames[0]; | ||
return file.to = fileNames[1]; | ||
} | ||
} | ||
}; | ||
@@ -37,7 +45,9 @@ restart = function() { | ||
restart(); | ||
return file["new"] = true; | ||
file["new"] = true; | ||
return file.from = '/dev/null'; | ||
}; | ||
deleted_file = function() { | ||
restart(); | ||
return file.deleted = true; | ||
file.deleted = true; | ||
return file.to = '/dev/null'; | ||
}; | ||
@@ -50,7 +60,7 @@ index = function(line) { | ||
restart(); | ||
return file.from = parseFile(line); | ||
return file.from = parseFileFallback(line); | ||
}; | ||
to_file = function(line) { | ||
restart(); | ||
return file.to = parseFile(line); | ||
return file.to = parseFileFallback(line); | ||
}; | ||
@@ -106,5 +116,5 @@ chunk = function(line, match) { | ||
parse = function(line) { | ||
var i, len, m, p; | ||
for (i = 0, len = schema.length; i < len; i++) { | ||
p = schema[i]; | ||
var j, len, m, p; | ||
for (j = 0, len = schema.length; j < len; j++) { | ||
p = schema[j]; | ||
m = line.match(p[0]); | ||
@@ -118,4 +128,4 @@ if (m) { | ||
}; | ||
for (i = 0, len = lines.length; i < len; i++) { | ||
line = lines[i]; | ||
for (j = 0, len = lines.length; j < len; j++) { | ||
line = lines[j]; | ||
if (!parse(line)) { | ||
@@ -129,2 +139,14 @@ normal(line); | ||
parseFile = function(s) { | ||
var fileNames; | ||
if (!s) { | ||
return; | ||
} | ||
fileNames = s.split(' ').slice(-2); | ||
fileNames.map(function(fileName, i) { | ||
return fileNames[i] = fileName.replace(/^(a|b)\//, ''); | ||
}); | ||
return fileNames; | ||
}; | ||
parseFileFallback = function(s) { | ||
var t; | ||
@@ -131,0 +153,0 @@ s = ltrim(s, '-'); |
{ | ||
"name": "parse-diff", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Unified diff parser", | ||
@@ -29,3 +29,3 @@ "author": "Sergey Todyshev <stodyshev@gmail.com>", | ||
"grunt-npm": "~0.0.2", | ||
"grunt-bump": "~0.3.0", | ||
"grunt-bump": "~0.3.2", | ||
"grunt-auto-release": "~0.0.6", | ||
@@ -32,0 +32,0 @@ "grunt-cli": "~0.1", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19803
184
0