bb4bc26f523c6d31eab4fc69999284d68829064b9988363b90366dd74545583975b9ffda5f8400ed4a401b443f93f70e69bcd3be276096e4ec9fc9369a5929 599 B

12345678910111213141516171819202122
  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;