Socket
Socket
Sign inDemoInstall

is-directory

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

24

index.js

@@ -0,1 +1,7 @@

/*!
* is-directory <https://github.com/jonschlinkert/is-directory>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT License
*/

@@ -6,14 +12,14 @@ 'use strict';

var isDir = function isDir(filepath, callback) {
if(typeof callback !== 'function') {
var isDir = function isDir(filepath, cb) {
if (typeof cb !== 'function') {
return isDir.sync(filepath);
}
fs.stat(filepath, function(err, stats){
if(err) {
callback(err);
fs.stat(filepath, function (err, stats) {
if (err) {
cb(err);
return;
}
callback(null, stats.isDirectory());
cb(null, stats.isDirectory());
return;

@@ -25,6 +31,10 @@ });

isDir.sync = function isDirSync(filepath) {
if (!fs.existsSync(filepath)) {
return false;
}
var stat = fs.statSync(filepath);
return stat && stat.isDirectory();
return stat.isDirectory();
};
module.exports = isDir;
{
"name": "is-directory",
"description": "Extends `stats.isDirectory()`, returns `true` if a filepath is a directory.",
"version": "0.2.1",
"version": "0.2.2",
"homepage": "https://github.com/jonschlinkert/is-directory",

@@ -47,5 +47,6 @@ "author": {

"devDependencies": {
"verb": ">= 0.2.6",
"mocha": "*"
"mocha": "*",
"should": "^4.0.4",
"verb": ">= 0.2.6"
}
}
}

@@ -10,10 +10,52 @@ /*!

var should = require('should');
var assert = require('assert');
var isDir = require('./');
function isFile(filepath) {
return !isDir(filepath);
function isFile(filepath, cb) {
return !isDir(filepath, cb);
}
describe('isDir', function () {
it('should return `true` if the path is a directory', function (done) {
isDir('node_modules', function (err, dir) {
if (err) console.log(err);
dir.should.be.true;
});
!isDir('.jshintrc', function (err, dir) {
if (err) console.log(err);
dir.should.be.false;
});
!isDir('README.md', function (err, dir) {
if (err) console.log(err);
dir.should.be.false;
});
!isDir('LICENSE-MIT', function (err, dir) {
if (err) console.log(err);
dir.should.be.false;
});
isFile('.jshintrc', function (err, dir) {
if (err) console.log(err);
dir.should.be.false;
});
isFile('README.md', function (err, dir) {
if (err) console.log(err);
dir.should.be.false;
});
isFile('LICENSE-MIT', function (err, dir) {
if (err) console.log(err);
dir.should.be.false;
});
done();
});
it('should return `false` if the path is not a directory', function () {
assert.equal(isDir('.jshintrc'), false);
assert.equal(isDir('README.md'), false);
assert.equal(isDir('LICENSE-MIT'), false);
});
});
describe('isDir sync', function () {
it('should return `true` if the path is a directory', function () {

@@ -35,2 +77,15 @@ assert(isDir('node_modules'));

});
it('should return `true` if the path is a directory', function () {
assert(isDir.sync('node_modules'));
assert(!isDir.sync('.jshintrc'));
assert(!isDir.sync('README.md'));
assert(!isDir.sync('LICENSE-MIT'));
});
it('should return `false` if the path is not a directory', function () {
assert.equal(isDir.sync('.jshintrc'), false);
assert.equal(isDir.sync('README.md'), false);
assert.equal(isDir.sync('LICENSE-MIT'), false);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc