UNPKG

599 BJavaScriptView Raw
1//
2'use strict';
3
4const path = require('path');
5const isDirectory = require('is-directory');
6
7function 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
18getDirectory.sync = function getDirectorySync(filepath ) {
19 return isDirectory.sync(filepath) ? filepath : path.dirname(filepath);
20};
21
22module.exports = getDirectory;