1 module.exports = fileCompletion
3 var mkdir = require("mkdirp")
4 , path = require("path")
5 , glob = require("glob")
7 function fileCompletion (root, req, depth, cb) {
8 if (typeof cb !== "function") cb = depth, depth = Infinity
9 mkdir(root, function (er) {
12 // can be either exactly the req, or a descendent
13 var pattern = root + "/{" + req + "," + req + "/**/*}"
14 , opts = { mark: true, dot: true, maxDepth: depth }
15 glob(pattern, opts, function (er, files) {
17 return cb(null, (files || []).map(function (f) {
18 var tail = f.substr(root.length + 1).replace(/^\//, "")
19 return path.join(req, tail)