git-diff-parser
Advanced tools
Comparing version 0.1.1 to 1.0.0
@@ -1,2 +0,1 @@ | ||
require("coffee-script/register"); | ||
module.exports = exports = require("./lib/parser"); |
{ | ||
"name": "git-diff-parser", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "A simple parser for Git diffs", | ||
@@ -19,5 +19,3 @@ "homepage": "https://github.com/spookd/git-diff-parser", | ||
"license": "MIT", | ||
"dependencies": { | ||
"coffee-script": "^1.8.0" | ||
} | ||
"dependencies": {} | ||
} |
@@ -15,35 +15,54 @@ # Git diff parser | ||
Instead of describing the resulting objects I figured an example was self explanatory (right?): | ||
```coffee | ||
parser = require("git-diff-parser") | ||
diff = parser(require("fs").readFileSync("some.diff")) | ||
```js | ||
const parser = require("git-diff-parser"); | ||
const diff = parser(require("fs").readFileSync("some.diff")); | ||
# Better viewing of linenumbers | ||
pad = (input = "-", toLeft = false) -> | ||
result = "#{input}" | ||
// Better viewing of linenumbers | ||
const pad = function(input, toLeft) { | ||
if (input === null) { input = "-"; } | ||
if (toLeft === null) { toLeft = false; } | ||
let result = `${input}`; | ||
while result.length < 5 | ||
result = if toLeft then "#{result} " else " #{result}" | ||
while (result.length < 5) { | ||
result = toLeft ? `${result} ` : ` ${result}`; | ||
} | ||
return result | ||
return result; | ||
}; | ||
# Loop all the commits | ||
for commit in diff.commits | ||
console.log "Commit ##{commit.sha} by #{commit.author} <#{commit.email}>" if diff.detailed | ||
// Loop all the commits | ||
diff.commits.forEach(function(commit, idx) { | ||
if (idx !== 0) { | ||
console.log("\n\n\n"); | ||
} | ||
if (diff.detailed) { | ||
console.log(`Commit #${commit.sha} by ${commit.author} <${commit.email}> at ${commit.date}`); | ||
} | ||
console.log(commit.message); | ||
console.log(""); | ||
for file, i in commit.files | ||
console.log "" if i isnt 0 | ||
console.log "[deleted] #{file.name}" if file.deleted | ||
console.log "[added] #{file.name}" if file.added | ||
console.log "[renamed] #{file.oldName} -> #{file.name}" if file.renamed | ||
console.log "[file] #{file.name}" if not file.added and not file.deleted and not file.renamed | ||
if file.binary | ||
console.log "<<< binary >>>" | ||
else | ||
for line in file.lines | ||
console.log "" if line.break | ||
console.log "#{pad()}/#{pad(line.ln1, true)} + #{line.text}" if line.type is "added" | ||
console.log "#{pad(line.ln1)}/#{pad("-", true)} - #{line.text}" if line.type is "deleted" | ||
console.log "#{pad(line.ln1)}/#{pad(line.ln2, true)} #{line.text}" if line.type is "normal" | ||
commit.files.forEach(function(file, idx) { | ||
if (idx !== 0) { | ||
console.log(""); | ||
if (file.deleted) { console.log(`[deleted] ${file.name}`); } | ||
if (file.added) { console.log(`[added] ${file.name}`); } | ||
if (file.renamed) { console.log(`[renamed] ${file.oldName} -> ${file.name}`); } | ||
if (!file.added && !file.deleted && !file.renamed) { console.log(`[file] ${file.name}`); } | ||
if (file.binary) { | ||
console.log("<<< binary >>>"); | ||
} else { | ||
file.lines.forEach(function(line) { | ||
if (line.break) { console.log(""); } | ||
if (line.type === "added") {console.log(`${pad()}/${pad(line.ln1, true)} + ${line.text}`); } | ||
if (line.type === "deleted") { console.log(`${pad(line.ln1)}/${pad("-", true)} - ${line.text}`); } | ||
if (line.type === "normal") { console.log(`${pad(line.ln1)}/${pad(line.ln2, true)} ${line.text}`); } | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
``` | ||
@@ -56,2 +75,3 @@ | ||
* spookd ([Github](https://github.com/spookd)) | ||
* ebutleratlassian ([Github](https://github.com/ebutleratlassian)) | ||
@@ -58,0 +78,0 @@ ## License (MIT) |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11424
0
185
1
97
0
5
- Removedcoffee-script@^1.8.0
- Removedcoffee-script@1.12.7(transitive)