Browse files

Added colorized string diff in diff util

  • Loading branch information...
1 parent 026fe7d commit e787089f58673ea33c6e99ce0b6c06e41a2964bd @Sembiance committed Jul 10, 2014
Showing with 11 additions and 2 deletions.
  1. +7 −1 diff.js
  2. +2 −1 package.json
  3. +2 −0 test/diff.js
View
8 diff.js
@@ -2,6 +2,7 @@
var base = require("xbase"),
util = require("util"),
+ ansidiff = require("ansidiff"),
color = require("cli-color");
exports.diff = diff;
@@ -53,5 +54,10 @@ function diffArray(o, n, indent)
function diffValues(o, n)
{
if(o!==n)
- return color.whiteBright(JSON.stringify(o)) + color.yellow(" => ") + color.whiteBright(JSON.stringify(n)) + "\n";
+ {
+ if(typeof o==="string")
+ return ansidiff.words(JSON.stringify(o), JSON.stringify(n), ansidiff.subtle) + "\n";
+ else
+ return color.whiteBright(JSON.stringify(o)) + color.yellow(" => ") + color.whiteBright(JSON.stringify(n)) + "\n";
+ }
}
View
3 package.json
@@ -1,6 +1,6 @@
{
"name" : "xutil",
- "version" : "1.3.8",
+ "version" : "1.3.9",
"author" : "Robert Schultz <robert@cosmicrealms.com>",
"description" : "common util functions I use in many of my node projects",
"private" : true,
@@ -17,6 +17,7 @@
"erbridge" : ">= 1.0.0",
"accounting" : ">= 0.3.2",
"cli-color" : ">= 0.2.3",
+ "ansidiff" : ">= 1.0.0",
"xbase" : "git://github.com/Sembiance/xbase.git"
}
}
View
2 test/diff.js
@@ -10,3 +10,5 @@ console.log(diffUtil.diff(true, false));
console.log(diffUtil.diff(["a", 1, true], ["b", 1, 2]));
console.log(diffUtil.diff({num:1, sexy:true, color:"red", pets : ["cat", "dog"], employed:false}, {num:6, color:"green", pets : ["cat", "bird"], employed:true, age:47}));
+
+console.log(diffUtil.diff({abc:"+1: Creatures you control get +1/+1 and gain haste until end of turn.\n\n-2: Gain control of target creature until end of turn. Untap that creature. It gains haste until end of turn.\n\n-6: Put five 4/4 red Dragon creature tokens with flying onto the battlefield."}, {abc:"+1: Creatures you control get +1/+1 and gain haste until end of turn.\n\n−2: Gain control of target creature until end of turn. Untap that creature. It gains haste until end of turn.\n\n−6: Put five 4/4 red Dragon creature tokens with flying onto the battlefield."}));

0 comments on commit e787089

Please sign in to comment.