1 |
|
2 | 'use strict';
|
3 |
|
4 | const path = require('path');
|
5 | const isDirectory = require('is-directory');
|
6 |
|
7 | module.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 | };
|