Initial commit
[yaffs-website] / node_modules / isexe / index.js
1 var fs = require('fs')
2 var core
3 if (process.platform === 'win32' || global.TESTING_WINDOWS) {
4   core = require('./windows.js')
5 } else if (typeof fs.access === 'function') {
6   core = require('./access.js')
7 } else {
8   core = require('./mode.js')
9 }
10
11 module.exports = isexe
12 isexe.sync = sync
13
14 function isexe (path, options, cb) {
15   if (typeof options === 'function') {
16     cb = options
17     options = {}
18   }
19
20   if (!cb) {
21     if (typeof Promise !== 'function') {
22       throw new TypeError('callback not provided')
23     }
24
25     return new Promise(function (resolve, reject) {
26       isexe(path, options || {}, function (er, is) {
27         if (er) {
28           reject(er)
29         } else {
30           resolve(is)
31         }
32       })
33     })
34   }
35
36   core(path, options || {}, function (er, is) {
37     // ignore EACCES because that just means we aren't allowed to run it
38     if (er) {
39       if (er.code === 'EACCES' || options && options.ignoreErrors) {
40         er = null
41         is = false
42       }
43     }
44     cb(er, is)
45   })
46 }
47
48 function sync (path, options) {
49   // my kingdom for a filtered catch
50   try {
51     return core.sync(path, options || {})
52   } catch (er) {
53     if (options && options.ignoreErrors || er.code === 'EACCES') {
54       return false
55     } else {
56       throw er
57     }
58   }
59 }