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