Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
win32.js63 linesDownload Raw Back to commonjs
1"use strict";
2/**
3 * This is the Windows implementation of isexe, which uses the file
4 * extension and PATHEXT setting.
5 *
6 * @module
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.sync = exports.isexe = void 0;
10const node_fs_1 = require("node:fs");
11const promises_1 = require("node:fs/promises");
12const node_path_1 = require("node:path");
13/**
14 * Determine whether a path is executable based on the file extension
15 * and PATHEXT environment variable (or specified pathExt option)
16 */
17const isexe = async (path, options = {}) => {
18    const { ignoreErrors = false } = options;
19    try {
20        return checkStat(await (0, promises_1.stat)(path), path, options);
21    }
22    catch (e) {
23        const er = e;
24        if (ignoreErrors || er.code === 'EACCES')
25            return false;
26        throw er;
27    }
28};
29exports.isexe = isexe;
30/**
31 * Synchronously determine whether a path is executable based on the file
32 * extension and PATHEXT environment variable (or specified pathExt option)
33 */
34const sync = (path, options = {}) => {
35    const { ignoreErrors = false } = options;
36    try {
37        return checkStat((0, node_fs_1.statSync)(path), path, options);
38    }
39    catch (e) {
40        const er = e;
41        if (ignoreErrors || er.code === 'EACCES')
42            return false;
43        throw er;
44    }
45};
46exports.sync = sync;
47const checkPathExt = (path, options) => {
48    const { pathExt = process.env.PATHEXT || '' } = options;
49    const peSplit = pathExt.split(node_path_1.delimiter);
50    if (peSplit.indexOf('') !== -1) {
51        return true;
52    }
53    for (const pes of peSplit) {
54        const p = pes.toLowerCase();
55        const ext = path.substring(path.length - p.length).toLowerCase();
56        if (p && ext === p) {
57            return true;
58        }
59    }
60    return false;
61};
62const checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options);
63//# sourceMappingURL=win32.js.map
codekingpro/portable-devtools · Team Ai