Skip to content
This repository has been archived by the owner on Jan 6, 2021. It is now read-only.

Commit

Permalink
removed default value behaviour and set type to only number for limit…
Browse files Browse the repository at this point in the history
…ChildrenCound
  • Loading branch information
Phaiax committed Jun 10, 2014
1 parent 6b15f6f commit 31804a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
16 changes: 7 additions & 9 deletions lib/formatio.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
var formatio = {
excludeConstructors: ["Object", /^.$/],
quoteStrings: true,
limitChildrenCount: false
limitChildrenCount: 0
};

var hasOwn = Object.prototype.hasOwnProperty;
Expand Down Expand Up @@ -107,10 +107,9 @@
processed = processed || [];
processed.push(array);
var pieces = [];
var i, l = array.length;
if (this.limitChildrenCount && this.limitChildrenCount !== false)
l = (typeof this.limitChildrenCount == "number") ?
this.limitChildrenCount : 100;
var i, l;
l = (this.limitChildrenCount > 0) ?
this.limitChildrenCount : array.length;

for (i = 0; i < l; ++i) {
pieces.push(ascii(this, array[i], processed));
Expand All @@ -128,10 +127,9 @@
indent = indent || 0;
var pieces = [], properties = samsam.keys(object).sort();
var length = 3;
var prop, str, obj, i, k, l = properties.length;
if (this.limitChildrenCount && this.limitChildrenCount !== false)
l = (typeof this.limitChildrenCount == "number") ?
this.limitChildrenCount : 100;
var prop, str, obj, i, k, l;
l = (this.limitChildrenCount > 0) ?
this.limitChildrenCount : properties.length;

for (i = 0; i < l; ++i) {
prop = properties[i];
Expand Down
16 changes: 0 additions & 16 deletions test/formatio-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@
assert.contains(str, "[... 270 more elements]");
},

"should stop at default limit 100 if limitChildrenCount=true" : function () {
var configuredFormatio = formatio.configure(
{limitChildrenCount : true});
var str = configuredFormatio.ascii(this.array);
refute.contains(str, "100");
assert.contains(str, "99");
},

"should format all array elements if no config is used" : function () {
var str = formatio.ascii(this.array);
assert.contains(str, "100");
Expand All @@ -142,14 +134,6 @@
assert.contains(str, "[... 270 more elements]");
},

"should stop at default limit 100 if limitChildrenCount=true" : function () {
var configuredFormatio = formatio.configure(
{limitChildrenCount : true});
var str = configuredFormatio.ascii(this.testobject);
assert.equals(100 + 3, str.split("\n").length);
assert.contains(str, "[... 200 more elements]");
},

"should format all properties if no config is used" : function () {
var str = formatio.ascii(this.testobject);
assert.equals(300 + 2, str.split("\n").length);
Expand Down

0 comments on commit 31804a3

Please sign in to comment.