Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleaner diffs for objects

  • Loading branch information...
commit 16e91e63b719e0c1706d814585a7e5b359e12cd9 1 parent 34d64da
@substack authored
Showing with 23 additions and 5 deletions.
  1. +23 −5 index.js
View
28 index.js
@@ -44,7 +44,9 @@ function difflet (opts, prev, next) {
inserted : 'green',
updated : 'blue',
deleted : 'red',
+ comment : 'cyan',
}[type]);
+ c.display('bright');
};
opts.stop = function (type) {
c.display('reset');
@@ -57,11 +59,11 @@ function difflet (opts, prev, next) {
var commaFirst = opts.comma === 'first';
- var stringify = function (node) {
- return stringifier.call(this, true, node);
+ var stringify = function (node, params) {
+ return stringifier.call(this, true, node, params || opts);
};
- var plainStringify = function (node) {
- return stringifier.call(this, false, node);
+ var plainStringify = function (node, params) {
+ return stringifier.call(this, false, node, params || opts);
};
var levels = 0;
@@ -74,7 +76,7 @@ function difflet (opts, prev, next) {
if (--levels === 0) opts.stop(type, stream);
}
- function stringifier (insertable, node) {
+ function stringifier (insertable, node, opts) {
var indent = opts.indent;
if (insertable) {
@@ -219,6 +221,16 @@ function difflet (opts, prev, next) {
if (insertedKey) unset('inserted');
insertedKey = false;
}
+
+ var prev = prevNode && prevNode[child.key];
+ if (opts.diff && child.node !== prev
+ && (typeof child.node !== 'object' || typeof prev !== 'object')
+ ) {
+ set('comment');
+ write(' // != ');
+ plainStringify(prev, { indent : 0 });
+ unset('comment');
+ }
});
this.after(function () {
@@ -280,6 +292,12 @@ function difflet (opts, prev, next) {
: '[Function]'
);
}
+ else if (node === undefined) {
+ write('undefined');
+ }
+ else if (node === null) {
+ write('null');
+ }
else {
write(node.toString());
}
Please sign in to comment.
Something went wrong with that request. Please try again.