Last change
on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
890 bytes
|
Line | |
---|
1 | module.exports = isexe
|
---|
2 | isexe.sync = sync
|
---|
3 |
|
---|
4 | var fs = require('fs')
|
---|
5 |
|
---|
6 | function checkPathExt (path, options) {
|
---|
7 | var pathext = options.pathExt !== undefined ?
|
---|
8 | options.pathExt : process.env.PATHEXT
|
---|
9 |
|
---|
10 | if (!pathext) {
|
---|
11 | return true
|
---|
12 | }
|
---|
13 |
|
---|
14 | pathext = pathext.split(';')
|
---|
15 | if (pathext.indexOf('') !== -1) {
|
---|
16 | return true
|
---|
17 | }
|
---|
18 | for (var i = 0; i < pathext.length; i++) {
|
---|
19 | var p = pathext[i].toLowerCase()
|
---|
20 | if (p && path.substr(-p.length).toLowerCase() === p) {
|
---|
21 | return true
|
---|
22 | }
|
---|
23 | }
|
---|
24 | return false
|
---|
25 | }
|
---|
26 |
|
---|
27 | function checkStat (stat, path, options) {
|
---|
28 | if (!stat.isSymbolicLink() && !stat.isFile()) {
|
---|
29 | return false
|
---|
30 | }
|
---|
31 | return checkPathExt(path, options)
|
---|
32 | }
|
---|
33 |
|
---|
34 | function isexe (path, options, cb) {
|
---|
35 | fs.stat(path, function (er, stat) {
|
---|
36 | cb(er, er ? false : checkStat(stat, path, options))
|
---|
37 | })
|
---|
38 | }
|
---|
39 |
|
---|
40 | function sync (path, options) {
|
---|
41 | return checkStat(fs.statSync(path), path, options)
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.