Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git-diff-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-diff-parser - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

lib/parser.js

1

index.js

@@ -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)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc