aboutsummaryrefslogtreecommitdiff
path: root/lib/tree.js
diff options
context:
space:
mode:
authorcyanos3 <[email protected]>2013-11-05 17:44:10 -0700
committercyanos3 <[email protected]>2013-11-05 17:44:10 -0700
commit5aa4062dcabc2fdac1c93df09e71d702ec7ec81e (patch)
tree5022d64e6be92badc9282e7c40c0817ecacd3c95 /lib/tree.js
parent229f9b9d04bab0d57d575b71f2f8a281e53a58ec (diff)
downloadfaker-5aa4062dcabc2fdac1c93df09e71d702ec7ec81e.tar.xz
faker-5aa4062dcabc2fdac1c93df09e71d702ec7ec81e.zip
Tree: let the width parameter also be a function that returns an int
Diffstat (limited to 'lib/tree.js')
-rw-r--r--lib/tree.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/tree.js b/lib/tree.js
index 75e2d75f..839b698c 100644
--- a/lib/tree.js
+++ b/lib/tree.js
@@ -25,6 +25,7 @@ var tree = {
};
}
+
if (width <= 0) {
throw {
name: "TreeParamError",
@@ -46,9 +47,19 @@ var tree = {
else {
if (depth !== 0) {
value = [];
- for (var i = 0; i < width; i++) {
+ var evalWidth = 1;
+
+ if (typeof(width) == "function") {
+ evalWidth = width();
+ }
+ else {
+ evalWidth = width;
+ }
+
+ for (var i = 0; i < evalWidth; i++) {
value.push(this.createTree(depth - 1, width, obj));
}
+
}
}
@@ -61,4 +72,4 @@ var tree = {
};
-module.exports = tree; \ No newline at end of file
+module.exports = tree;