isdir-async

1.0.0 • Public • Published

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 => {})

Readme

Keywords

Package Sidebar

Install

npm i isdir-async

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

2.21 kB

Total Files

4

Last publish

Collaborators

  • vdegenne