const path = require('path'); const fs = require('fs'); const os = require('os'); const isWin32 = os.platform() === 'win32'; const dirTraveler = (dir: string, match?: RegExp) => { const base = dir; const memo: { [key: string]: string; } = {}; (function walk(p) { try { const stats = fs.statSync(p); if (stats.isDirectory()) { const files = fs.readdirSync(p); files.forEach((file: string) => { if (/^\./.test(file)) { return; } walk(path.resolve(p, file)); }); } else { let key = path.relative(base, p); if (isWin32) { key = key.replace(/\\/g, '/'); } if (!match || match.test(key)) { memo[key] = p; } } } catch (e) { throw e; } })(dir); return memo; }; (dirTraveler as any).default = dirTraveler; export = dirTraveler;