You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
599 B

4 years ago
  1. //
  2. 'use strict';
  3. const path = require('path');
  4. const isDirectory = require('is-directory');
  5. function getDirectory(filepath ) {
  6. return new Promise((resolve, reject) => {
  7. return isDirectory(filepath, (err, filepathIsDirectory) => {
  8. if (err) {
  9. return reject(err);
  10. }
  11. return resolve(filepathIsDirectory ? filepath : path.dirname(filepath));
  12. });
  13. });
  14. }
  15. getDirectory.sync = function getDirectorySync(filepath ) {
  16. return isDirectory.sync(filepath) ? filepath : path.dirname(filepath);
  17. };
  18. module.exports = getDirectory;