odin-default-js-exercises/node_modules/path-exists/index.js

24 lines
347 B
JavaScript
Raw Normal View History

2017-12-15 18:56:14 +00:00
'use strict';
const fs = require('fs');
const {promisify} = require('util');
2017-12-15 18:56:14 +00:00
const pAccess = promisify(fs.access);
2017-12-15 18:56:14 +00:00
module.exports = async path => {
try {
await pAccess(path);
return true;
} catch (_) {
return false;
}
2017-12-15 18:56:14 +00:00
};
module.exports.sync = path => {
2017-12-15 18:56:14 +00:00
try {
fs.accessSync(path);
2017-12-15 18:56:14 +00:00
return true;
} catch (_) {
2017-12-15 18:56:14 +00:00
return false;
}
};