index.js 466 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var fs = require('fs');
  3. var Promise = require('pinkie-promise');
  4. module.exports = function (fp) {
  5. var fn = typeof fs.access === 'function' ? fs.access : fs.stat;
  6. return new Promise(function (resolve) {
  7. fn(fp, function (err) {
  8. resolve(!err);
  9. });
  10. });
  11. };
  12. module.exports.sync = function (fp) {
  13. var fn = typeof fs.accessSync === 'function' ? fs.accessSync : fs.statSync;
  14. try {
  15. fn(fp);
  16. return true;
  17. } catch (err) {
  18. return false;
  19. }
  20. };