Skip to content
/ isdir Public

📂 Checks if a descriptor is a directory. thin wrapper around node's fs.stat.isDirectory()

Notifications You must be signed in to change notification settings

dwyl/isdir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

isdir

Build Status Test Coverage Code Climate Node.js Version NPM Version Dependency Status

isdir checks if a given file descriptor fd is a directory or not.
(wrapper around node's native fs.stat.isDirectory() method )

Usage

Install from NPM

npm install isdir --save

In your script

var isdir = require('isdir');
var fd    = __dirname; // or what ever you need to check

isdir(fd, function callback(err, dir) { // named callback function
  if(err) { // you will get an error back if fd was not a readable file or dir
    console.log("Oopsy: " + err); // handle errors in your preferred way.
  }
  else if(dir) {
    console.log(fd + " is a directory!"); // do something with the directory
  }
  else {
    console.log(fd + " is NOT a directory!") // its a file
  }
});

About

We needed a fully tested simple call to check if a descriptor is a directory for our faster project.

This module deliberately only exposes a single asynchronous method.

If you prefer to use it sychronously (go for a walk and consider switching programming languages) and if you still want to use it sync just assign the output to varaiable and omit the callback:

var isdir = require('isdir');
var fd    = __dirname;        // or what ever descriptor you need to check
var dir   = isdir(__dirname); // this works but is not encouraged (its blocking)
if(dir) {
  // do what you want with your directory
}

Influenced by: https://github.com/jonschlinkert/is-directory (We wanted lighter error-handling and more tests)

About

📂 Checks if a descriptor is a directory. thin wrapper around node's fs.stat.isDirectory()

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages