function encodeRelativeURL(startPath, relative, callerPath) {

  // ensure we are at a valid start path that is not process working directory
  var absStart  = path.resolve(startPath);
  var parentDir = path.resolve(path.join(absStart, '..'));
  if (fs.existsSync(absStart)) {
    var fullPath = path.resolve(path.join(startPath, relative));
    if (fs.existsSync(fullPath)) {

      // file exists so get the dataURI
      var type     = mime.lookup(fullPath);
      var contents = fs.readFileSync(fullPath);
      var base64   = new Buffer(contents).toString('base64');
      return 'url(data:' + type + ';base64,' + base64 + ')';

    } else if (parentDir !== process.cwd()) { // will not jump across bower or npm packages

      // find parent and child directories
      var childDirs = fs.readdirSync(absStart)
        .map(function toAbsolute(filename) {
          return path.join(absStart, filename);
        }).filter(function directoriesOnly(absolute) {
          return fs.statSync(absolute).isDirectory();
        });

      // recurse paths down and up except the caller path
      //  return the first success
      var result;
      childDirs.concat(parentDir)
        .filter(function excludeCallerDir(absoluteDir) {
          return (absoluteDir !== callerPath);
        })
        .some(function encode(absoluteDir) {
          result = encodeRelativeURL(absoluteDir, relative, absStart);
          return result;
        });

      // may be undefined
      return result;
    }
  } else {
    return;
  }
}
/**
 * Search for the relative file reference from the <code>startPath</code> up to, but not including, the process
 * working directory.
 * @param {string} startPath The path to which the <code>relative</code> path might be specified
 * @param {string} relative A possibly relative file path
 * @param {string} [callerPath] The full path of the invoking function instance where recursion has occured
 * @returns {string} dataURI of the file where found or <code>undefined</code> otherwise
 */
Search for the relative file reference from the startPath up to, but not including, the process
working directory.
@param {string} startPath The path to which the relative path might be specified
@param {string} relative A possibly relative file path
@param {string} [callerPath] The full path of the invoking function instance where recursion has occured
@returns {string} dataURI of the file where found or undefined otherwise
Search for the relative file reference from the startPath up to but not including the process working directory . @param { string } startPath The path to which the relative path might be specified @param { string } relative A possibly relative file path @param { string } [ callerPath ] The full path of the invoking function instance where recursion has occured @returns { string } dataURI of the file where found or undefined otherwise
function encodeRelativeURL(startPath, relative, callerPath) {
  var absStart  = path.resolve(startPath);
  var parentDir = path.resolve(path.join(absStart, '..'));
  if (fs.existsSync(absStart)) {
    var fullPath = path.resolve(path.join(startPath, relative));
    if (fs.existsSync(fullPath)) {
      var type     = mime.lookup(fullPath);
      var contents = fs.readFileSync(fullPath);
      var base64   = new Buffer(contents).toString('base64');
      return 'url(data:' + type + ';base64,' + base64 + ')';
    } else if (parentDir !== process.cwd()) { 
      var childDirs = fs.readdirSync(absStart)
        .map(function toAbsolute(filename) {
          return path.join(absStart, filename);
        }).filter(function directoriesOnly(absolute) {
          return fs.statSync(absolute).isDirectory();
        });
      var result;
      childDirs.concat(parentDir)
        .filter(function excludeCallerDir(absoluteDir) {
          return (absoluteDir !== callerPath);
        })
        .some(function encode(absoluteDir) {
          result = encodeRelativeURL(absoluteDir, relative, absStart);
          return result;
        });
      return result;
    }
  } else {
    return;
  }
}
function encodeRelativeURL ( startPath , relative , callerPath ) { var absStart = path . resolve ( startPath ) ; var parentDir = path . resolve ( path . join ( absStart , '..' ) ) ; if ( fs . existsSync ( absStart ) ) { var fullPath = path . resolve ( path . join ( startPath , relative ) ) ; if ( fs . existsSync ( fullPath ) ) { var type = mime . lookup ( fullPath ) ; var contents = fs . readFileSync ( fullPath ) ; var base64 = new Buffer ( contents ) . toString ( 'base64' ) ; return 'url(data:' + type + ';base64,' + base64 + ')' ; } else if ( parentDir !== process . cwd ( ) ) { var childDirs = fs . readdirSync ( absStart ) . map ( function toAbsolute ( filename ) { return path . join ( absStart , filename ) ; } ) . filter ( function directoriesOnly ( absolute ) { return fs . statSync ( absolute ) . isDirectory ( ) ; } ) ; var result ; childDirs . concat ( parentDir ) . filter ( function excludeCallerDir ( absoluteDir ) { return ( absoluteDir !== callerPath ) ; } ) . some ( function encode ( absoluteDir ) { result = encodeRelativeURL ( absoluteDir , relative , absStart ) ; return result ; } ) ; return result ; } } else { return ; } }
Search for the relative file reference from the <code>startPath</code> up to, but not including, the process
 working directory.
Search for the relative file reference from the <code > startPath< / code > up to but not including the process working directory .
// ensure we are at a valid start path that is not process working directory // file exists so get the dataURI // will not jump across bower or npm packages // find parent and child directories // recurse paths down and up except the caller path //  return the first success // may be undefined