is-directory
Advanced tools
Comparing version 0.2.3 to 0.3.0
36
index.js
/*! | ||
* is-directory <https://github.com/jonschlinkert/is-directory> | ||
* | ||
* Copyright (c) 2014 Jon Schlinkert, contributors. | ||
* Licensed under the MIT License | ||
* Copyright (c) 2014-2015, Jon Schlinkert. | ||
* Licensed under the MIT License. | ||
*/ | ||
@@ -18,13 +18,17 @@ | ||
function isDir(filepath, cb) { | ||
/** | ||
* async | ||
*/ | ||
function isDir(fp, cb) { | ||
if (typeof fp !== 'string') { | ||
throw new Error('is-directory async expects filepath to be a string.'); | ||
} | ||
if (typeof cb !== 'function') { | ||
return isDir.sync(filepath); | ||
throw new Error('is-directory async expects a callback function.'); | ||
} | ||
fs.stat(filepath, function(err, stats) { | ||
if (err) { | ||
cb(err); | ||
return; | ||
} | ||
fs.stat(fp, function(err, stats) { | ||
if (err) return cb(err); | ||
cb(null, stats.isDirectory()); | ||
@@ -35,8 +39,14 @@ return; | ||
isDir.sync = function isDirSync(filepath) { | ||
/** | ||
* sync | ||
*/ | ||
isDir.sync = function isDirSync(fp) { | ||
if (typeof fp !== 'string') { | ||
throw new Error('is-directory sync expects filepath to be a string.'); | ||
} | ||
try { | ||
var stat = fs.statSync(filepath); | ||
return stat.isDirectory(); | ||
return fs.statSync(fp).isDirectory(); | ||
} catch(err) {} | ||
return false; | ||
}; |
{ | ||
"name": "is-directory", | ||
"description": "Extends `stats.isDirectory()`, returns `true` if a filepath is a directory.", | ||
"version": "0.2.3", | ||
"description": "Returns `true` if a filepath is a directory. Basically `fs.statSync().isDirectory()` with extra error handling.", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/jonschlinkert/is-directory", | ||
@@ -17,8 +17,20 @@ "author": { | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/is-directory/blob/master/LICENSE-MIT" | ||
} | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/is-directory/blob/master/LICENSE" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "^4.0.4" | ||
}, | ||
"keywords": [ | ||
@@ -39,14 +51,3 @@ "dir", | ||
"system" | ||
], | ||
"main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha -R spec" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "^4.0.4" | ||
} | ||
} | ||
] | ||
} |
@@ -1,16 +0,16 @@ | ||
# is-directory [![NPM version](https://badge.fury.io/js/is-directory.svg)](http://badge.fury.io/js/is-directory) | ||
# 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) | ||
> Extends `stats.isDirectory()`, returns `true` if a filepath is a directory. | ||
> Returns `true` if a filepath is a directory. Basically `fs.statSync().isDirectory()` with extra error handling. | ||
## Install | ||
### Install with [npm](npmjs.org): | ||
## Install with [npm](npmjs.org) | ||
```bash | ||
npm i is-directory --save-dev | ||
npm i is-directory --save | ||
``` | ||
## Run tests | ||
## Running tests | ||
Install dev dependencies. | ||
```bash | ||
npm test | ||
npm i -d && npm test | ||
``` | ||
@@ -21,15 +21,12 @@ | ||
```js | ||
var isDir = require('is-directory'); | ||
var isdir = require('is-directory'); | ||
isDir('README.md'); | ||
//=> 'false' | ||
isDir('test'); | ||
isdir('README.md', function(err, dir) { | ||
if (dir) { | ||
// do stuff | ||
} | ||
}); | ||
isdir.sync('test'); | ||
//=> 'true' | ||
function isFile(filepath) { | ||
return !isDir(filepath); | ||
} | ||
isFile('README.md'); | ||
//=> true | ||
``` | ||
@@ -45,3 +42,3 @@ | ||
## License | ||
Copyright (c) 2014 Jon Schlinkert | ||
Copyright (c) 2015 Jon Schlinkert | ||
Released under the MIT license | ||
@@ -51,2 +48,2 @@ | ||
_This file was generated by [verb](https://github.com/assemble/verb) on November 17, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 21, 2015._ |
4040
4
40
46