@stryke/fs
Version:
A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.
57 lines (56 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.chmodX = chmodX;
exports.chmodXSync = chmodXSync;
exports.isExecutable = isExecutable;
exports.isExecutableSync = isExecutableSync;
exports.isWritable = isWritable;
exports.isWritableSync = isWritableSync;
var _nodeFs = require("node:fs");
var _promises = require("node:fs/promises");
function chmodXSync(t) {
if (process.platform === "win32") return;
const r = (0, _nodeFs.statSync)(t),
n = r.mode | 64 | 8 | 1;
if (r.mode === n) return;
const o = n.toString(8).slice(-3);
(0, _nodeFs.chmodSync)(t, o);
}
async function chmodX(t) {
if (process.platform === "win32") return;
const r = (0, _nodeFs.statSync)(t),
n = r.mode | 64 | 8 | 1;
if (r.mode === n) return;
const o = n.toString(8).slice(-3);
return (0, _promises.chmod)(t, o);
}
async function isWritable(t) {
try {
return await (0, _promises.access)(t, _nodeFs.constants.W_OK), !0;
} catch {
return !1;
}
}
function isWritableSync(t) {
try {
return (0, _nodeFs.accessSync)(t, _nodeFs.constants.W_OK), !0;
} catch {
return !1;
}
}
async function isExecutable(t) {
try {
return await (0, _promises.access)(t, _nodeFs.constants.X_OK), !0;
} catch {
return !1;
}
}
function isExecutableSync(t) {
try {
return (0, _nodeFs.accessSync)(t, _nodeFs.constants.X_OK), !0;
} catch {
return !1;
}
}