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.3.0 to 0.3.1

53

index.js

@@ -13,24 +13,25 @@ /*!

/**
* Expose `isDir`
*/
module.exports = isDir;
/**
* async
*/
function isDir(fp, cb) {
if (typeof fp !== 'string') {
throw new Error('is-directory async expects filepath to be a string.');
function isDirectory(filepath, cb) {
if (typeof cb !== 'function') {
throw new Error('expected a callback function');
}
if (typeof cb !== 'function') {
throw new Error('is-directory async expects a callback function.');
if (typeof filepath !== 'string') {
cb(new Error('expected filepath to be a string'));
return;
}
fs.stat(fp, function(err, stats) {
if (err) return cb(err);
fs.stat(filepath, function(err, stats) {
if (err) {
if (err.code === 'ENOENT') {
cb(null, false);
return;
}
cb(err);
return;
}
cb(null, stats.isDirectory());
return;
});

@@ -43,10 +44,24 @@ }

isDir.sync = function isDirSync(fp) {
if (typeof fp !== 'string') {
throw new Error('is-directory sync expects filepath to be a string.');
isDirectory.sync = function isDirectorySync(filepath) {
if (typeof filepath !== 'string') {
throw new Error('expected filepath to be a string');
}
try {
return fs.statSync(fp).isDirectory();
} catch(err) {}
var stat = fs.statSync(filepath);
return stat.isDirectory();
} catch (err) {
if (err.code === 'ENOENT') {
return false;
} else {
throw err;
}
}
return false;
};
/**
* Expose `isDirectory`
*/
module.exports = isDirectory;
{
"name": "is-directory",
"description": "Returns `true` if a filepath is a directory. Basically `fs.statSync().isDirectory()` with extra error handling.",
"version": "0.3.0",
"description": "Returns true if a filepath exists on the file system and it's directory.",
"version": "0.3.1",
"homepage": "https://github.com/jonschlinkert/is-directory",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "git://github.com/jonschlinkert/is-directory.git"
},
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/is-directory",
"bugs": {
"url": "https://github.com/jonschlinkert/is-directory/issues"
},
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/is-directory/blob/master/LICENSE"
},
"license": "MIT",
"files": [

@@ -32,4 +23,4 @@ "index.js"

"devDependencies": {
"mocha": "*",
"should": "^4.0.4"
"gulp-format-md": "^0.1.9",
"mocha": "^2.4.5"
},

@@ -51,3 +42,26 @@ "keywords": [

"system"
]
}
],
"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"is-glob",
"is-relative",
"is-absolute"
]
},
"lint": {
"reflinks": true
},
"reflinks": [
"verb"
]
}
}

@@ -1,16 +0,11 @@

# is-directory [![NPM version](https://badge.fury.io/js/is-directory.svg)](http://badge.fury.io/js/is-directory) [![Build Status](https://travis-ci.org/jonschlinkert/is-directory.svg)](https://travis-ci.org/jonschlinkert/is-directory)
# is-directory [![NPM version](https://img.shields.io/npm/v/is-directory.svg?style=flat)](https://www.npmjs.com/package/is-directory) [![NPM downloads](https://img.shields.io/npm/dm/is-directory.svg?style=flat)](https://npmjs.org/package/is-directory) [![Build Status](https://img.shields.io/travis/jonschlinkert/is-directory.svg?style=flat)](https://travis-ci.org/jonschlinkert/is-directory)
> Returns `true` if a filepath is a directory. Basically `fs.statSync().isDirectory()` with extra error handling.
Returns true if a filepath exists on the file system and it's directory.
## Install with [npm](npmjs.org)
## Install
```bash
npm i is-directory --save
```
Install with [npm](https://www.npmjs.com/):
## Running tests
Install dev dependencies.
```bash
npm i -d && npm test
```sh
$ npm install is-directory --save
```

@@ -21,27 +16,62 @@

```js
var isdir = require('is-directory');
var isDirectory = require('is-directory');
isdir('README.md', function(err, dir) {
if (dir) {
// do stuff
}
isDirectory('node_modules', function(err, dir) {
if (err) throw err;
console.log(dir);
//=> true
});
isdir.sync('test');
//=> 'true'
isDirectory.sync('README.md');
//=> false
```
## Related projects
You might also be interested in these projects:
* [is-absolute](https://www.npmjs.com/package/is-absolute): Polyfill for node.js `path.isAbolute`. Returns true if a file path is absolute. | [homepage](https://github.com/jonschlinkert/is-absolute)
* [is-glob](https://www.npmjs.com/package/is-glob): Returns `true` if the given string looks like a glob pattern or an extglob pattern.… [more](https://www.npmjs.com/package/is-glob) | [homepage](https://github.com/jonschlinkert/is-glob)
* [is-relative](https://www.npmjs.com/package/is-relative): Returns `true` if the path appears to be relative. | [homepage](https://github.com/jonschlinkert/is-relative)
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-directory/issues/new).
## Building docs
Generate readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install verb && npm run docs
```
Or, if [verb](https://github.com/verbose/verb) is installed globally:
```sh
$ verb
```
## Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
## Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT license](https://github.com/jonschlinkert/is-directory/blob/master/LICENSE).
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 21, 2015._
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 21, 2016._

Sorry, the diff of this file is not supported yet

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