1.0.0 • Published 6 years ago

isdir-async v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

isdir-async

A no-deps async version of isDirectory, to use with or without await.

At its core, it just util.promisifyies a function that uses stat and some callbacks to operate. Promisify the whole gives the ability to use the async and await keywords of Node >7.6.0

usage

// import * as isDirectory from 'isdir-async'
var isDirectory = require('isdir-async');


/**
 * SYNC method
 */
if (await isDirectory('path/to/dir')) {
    // ...
}
else {}
/**
 * ASYNC method
 */
isDirectory('path/to/dir').then(isdir => {
    if (isdir) {
        // ...
    }
    else {}
});

Handle the errors

/**
 * SYNC method
 */
let isdir;
try {
    isdir = await isDirectory('path/to/dir');
} catch (err) {}


if (isdir) {
    // ...
}
else {}
/**
 * ASYNC method
 */
isDirectory('path/to/dir')
    .then(isdir => {
        if (isdir) {
            // ...
        }
        else {}
    })
    .catch (err => {})