Skip to content

Commit

Permalink
moved some code around and shortdown the empty array object string
Browse files Browse the repository at this point in the history
  • Loading branch information
frozzare committed Aug 10, 2012
1 parent 8377f58 commit 80f4e23
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions index.js
Expand Up @@ -43,31 +43,34 @@ function to_html (obj) {
return '<span class="boolean">' + obj.toString() + '</span>';
} else if (obj === null) {
return '<span class="null">null</span>';
} else if ((obj instanceof Array && !obj.length) || (!Object.keys(obj).length)) {
return '<span class="' + (obj instanceof Array ? 'array' : 'object') + '">' + (obj instanceof Array ? '[]' : '{}') + '</span>';
} else {
var arr = obj instanceof Array
, str = (arr ? '[' : '{') + '\n'
, res = [];
var arr = obj instanceof Array;

if ((arr && !obj.length) || (!Object.keys(obj).length)) {
return '<span class="' + (arr ? 'array' : 'object') + '">' + (arr ? '[]' : '{}') + '</span>';
} else {
var str = (arr ? '[' : '{') + '\n'
, res = [];

indents++;
indents++;

if (arr) {
for (var i = 0; i < obj.length; i++) {
res.push(indent(to_html(obj[i])));
}
} else {
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
res.push(indent(to_html(k) + ': ' + to_html(obj[k])));
if (arr) {
for (var i = 0; i < obj.length; i++) {
res.push(indent(to_html(obj[i])));
}
} else {
for (var k in obj) {
if (obj.hasOwnProperty(k)) {
res.push(indent(to_html(k) + ': ' + to_html(obj[k])));
}
}
}
}

str += res.join(',\n') + '\n';
indents--;
str += indent(arr ? ']' : '}');
return str;
str += res.join(',\n') + '\n';
indents--;
str += indent(arr ? ']' : '}');
return str;
}
}
}

Expand Down

0 comments on commit 80f4e23

Please sign in to comment.