"use strict";

var fs   = require('fs');
var path = require('path');

module.exports = function(bin){
  var binpath,
      paths = process.env.PATH.split(path.delimiter),
      exts  = process.env.PATHEXT.split(path.delimiter);

    exts = exts.filter(function(val){
      return !!val;
    });
    exts.push(""); //handle direct bin calls

  for(var i = 0; i <paths.length; i++) {
    var ext, _full, full = path.join(paths[i], bin);
    for(ext = 0; ext < exts.length; ext++) {
      _full = full + exts[ext];
      if(fs.existsSync(_full))
        return _full;
    }
  };
  return false;
};

"use strict";

var fs   = require('fs');
var path = require('path');

module.exports = function(bin){
  var binpath,
      paths = process.env.PATH.split(path.delimiter),
      exts  = process.env.PATHEXT ? process.env.PATHEXT.split(path.delimiter) : [];

    exts = exts.filter(function(val){
      return !!val;
    });
    exts.push(""); //handle direct bin calls

  for(var i = 0; i <paths.length; i++) {
    var ext, _full, full = path.join(paths[i], bin);
    for(ext = 0; ext < exts.length; ext++) {
      _full = full + exts[ext];
      if(fs.existsSync(_full))
        return _full;
    }
  };
  return false;
};

Fix nyks/path/which for linux