]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/lib/utils/completion/file-completion.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / lib / utils / completion / file-completion.js
1 module.exports = fileCompletion
2
3 var mkdir = require("mkdirp")
4   , path = require("path")
5   , glob = require("glob")
6
7 function fileCompletion (root, req, depth, cb) {
8   if (typeof cb !== "function") cb = depth, depth = Infinity
9   mkdir(root, function (er) {
10     if (er) return cb(er)
11
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) {
16       if (er) return cb(er)
17       return cb(null, (files || []).map(function (f) {
18         var tail = f.substr(root.length + 1).replace(/^\//, "")
19         return path.join(req, tail)
20       }))
21     })
22   })
23 }