UNPKG

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