From bbe19b158625d7c404fc01e5e9226a3597736e24 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Mon, 3 Jun 2013 08:06:47 +0100 Subject: [PATCH 1/2] added depth limit --- index.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 9f6680c..e59ab83 100644 --- a/index.js +++ b/index.js @@ -24,16 +24,17 @@ function isDirectory (fpath) { function extend (obj, source) { for (var key in source){ if (source.hasOwnProperty(key)) { - obj[key] = source[key] + obj[key] = source[key] } } return obj } -function require_tree (directory, options) { - +function require_tree (directory, options, depth) { + depth = depth || 0; options = extend({ - index: true + index: true, + depthLimit: 9999 // let's hope no one will have more than 9999 nested directories }, options) var dir = path.resolve(directory) @@ -51,7 +52,9 @@ function require_tree (directory, options) { , item, obj if (isDirectory(fpath)) { - tree[name] = require_tree(fpath, options) + if(depth < options.depthLimit) { + tree[name] = require_tree(fpath, options, depth + 1) + } return } From a43970981bdebef6d0f2deb778b36f2e3dca2948 Mon Sep 17 00:00:00 2001 From: Gabor Javorszky Date: Mon, 3 Jun 2013 23:34:18 +0100 Subject: [PATCH 2/2] Infinity > 9999 --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e59ab83..dac3cd2 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,7 @@ function require_tree (directory, options, depth) { depth = depth || 0; options = extend({ index: true, - depthLimit: 9999 // let's hope no one will have more than 9999 nested directories + depthLimit: Infinity // let's hope no one will have more than 9999 nested directories }, options) var dir = path.resolve(directory)