isexe
用于检查文件是否可执行和正常文件的最小模块。
使用 fs.stat 并对 PATHEXT 环境变量on
窗户。
用法
// default export is a minified version that doesn't need to
// load more than one file. Load the 'isexe/raw' export if
// you want the non-minified version for some reason.
import { isexe, sync } from 'isexe'
// or require() works too
// const { isexe } = require('isexe')
isexe('some-file-name').then(
isExe => {
if (isExe) {
console.error('this thing can be run')
} else {
console.error('cannot be run')
}
},
err => {
console.error('probably file doesnt exist or something')
},
)
// same thing but synchronous, throws errors
isExe = sync('some-file-name')
// treat errors as just "not executable"
const isExe = await isexe('maybe-missing-file', { ignoreErrors: true })
const isExe = sync('maybe-missing-file', { ignoreErrors: true })
API
isexe(path, [options]) => Promise<boolean>
检查路径是否可执行。
会引起任何可能引起的错误吗 fs.stat,除非
options.ignoreErrors 设置为true。
sync(path, [options]) => boolean
一样 isexe 但是返回值并抛出引发的任何错误。
平台特定实现
如果出于某种原因你想使用a的实现 特定的平台,你可以这样做。
import { win32, posix } from 'isexe'
win32.isexe(...)
win32.sync(...)
// etc
// or:
import { isexe, sync } from 'isexe/posix'
默认的导出实现将基于以下选择
process.platform。
选项
import type IsexeOptions from 'isexe'
ignoreErrors把所有的错误都当作“不,这不是。 可执行文件”,但不要提高它们。uid在posix上用作用户id的数字gid在posix上用作组id的号码pathExt要使用的路径扩展名列表PATHEXTWindows上的环境变量。