Skip to content

Instantly share code, notes, and snippets.

@aconbere
Created November 30, 2010 04:48
Show Gist options
  • Select an option

  • Save aconbere/721169 to your computer and use it in GitHub Desktop.

Select an option

Save aconbere/721169 to your computer and use it in GitHub Desktop.
// Which files to traverse while finding id? Returns generator function.
function traverser (id, dirs) {
var head = [],
inDir = [],
dirs = dirs.slice(), // a copy of the original array
exts = Object.keys(extensions);
return function next () {
var result = head.shift();
if (result) { return result; }
var gen = inDir.shift();
if (gen) { head = gen(); return next(); }
var dir = dirs.shift();
if (dir !== undefined) {
function direct (ext) { return path.join(dir, id + ext); }
function index (ext) { return path.join(dir, id, 'index' + ext); }
inDir = [
function () { return exts.map(direct); },
function () { return exts.map(index); }
];
head = [path.join(dir, id)];
return next();
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment