wishthis/node_modules/path-exists/index.js

24 lines
347 B
JavaScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
'use strict';
2022-06-08 10:36:39 +00:00
const fs = require('fs');
const {promisify} = require('util');
2022-01-21 08:28:41 +00:00
2022-06-08 10:36:39 +00:00
const pAccess = promisify(fs.access);
2022-01-21 08:28:41 +00:00
2022-06-08 10:36:39 +00:00
module.exports = async path => {
try {
await pAccess(path);
return true;
} catch (_) {
return false;
}
2022-01-21 08:28:41 +00:00
};
2022-06-08 10:36:39 +00:00
module.exports.sync = path => {
2022-01-21 08:28:41 +00:00
try {
2022-06-08 10:36:39 +00:00
fs.accessSync(path);
2022-01-21 08:28:41 +00:00
return true;
2022-06-08 10:36:39 +00:00
} catch (_) {
2022-01-21 08:28:41 +00:00
return false;
}
};