index.js 841 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var fs = require('graceful-fs');
  3. var Promise = require('pinkie-promise');
  4. var pify = require('pify');
  5. function type(fn, fn2, fp) {
  6. if (typeof fp !== 'string') {
  7. return Promise.reject(new TypeError('Expected a string'));
  8. }
  9. return pify(fs[fn], Promise)(fp).then(function (stats) {
  10. return stats[fn2]();
  11. });
  12. }
  13. function typeSync(fn, fn2, fp) {
  14. if (typeof fp !== 'string') {
  15. throw new TypeError('Expected a string');
  16. }
  17. return fs[fn](fp)[fn2]();
  18. }
  19. exports.file = type.bind(null, 'stat', 'isFile');
  20. exports.dir = type.bind(null, 'stat', 'isDirectory');
  21. exports.symlink = type.bind(null, 'lstat', 'isSymbolicLink');
  22. exports.fileSync = typeSync.bind(null, 'statSync', 'isFile');
  23. exports.dirSync = typeSync.bind(null, 'statSync', 'isDirectory');
  24. exports.symlinkSync = typeSync.bind(null, 'lstatSync', 'isSymbolicLink');