├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── fixtures └── foo.txt ├── index.d.ts ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.json] 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.yml] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.md] 21 | indent_style = space 22 | indent_size = 2 23 | trim_trailing_whitespace = false 24 | 25 | [test/fixtures/*] 26 | trim_trailing_whitespace = false 27 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | "env": { 7 | "browser": false, 8 | "es6": true, 9 | "node": true, 10 | "mocha": true 11 | }, 12 | "globals": { 13 | "document": false, 14 | "navigator": false, 15 | "window": false 16 | }, 17 | "rules": { 18 | "accessor-pairs": 2, 19 | "arrow-spacing": [ 20 | 2, 21 | { 22 | "before": true, 23 | "after": true 24 | } 25 | ], 26 | "block-spacing": [ 27 | 2, 28 | "always" 29 | ], 30 | "brace-style": [ 31 | 2, 32 | "1tbs", 33 | { 34 | "allowSingleLine": true 35 | } 36 | ], 37 | "comma-dangle": [ 38 | 2, 39 | "never" 40 | ], 41 | "comma-spacing": [ 42 | 2, 43 | { 44 | "before": false, 45 | "after": true 46 | } 47 | ], 48 | "comma-style": [ 49 | 2, 50 | "last" 51 | ], 52 | "constructor-super": 2, 53 | "curly": [ 54 | 2, 55 | "multi-line" 56 | ], 57 | "dot-location": [ 58 | 2, 59 | "property" 60 | ], 61 | "eol-last": 2, 62 | "eqeqeq": [ 63 | 2, 64 | "allow-null" 65 | ], 66 | "generator-star-spacing": [ 67 | 2, 68 | { 69 | "before": true, 70 | "after": true 71 | } 72 | ], 73 | "handle-callback-err": [ 74 | 2, 75 | "^(err|error)$" 76 | ], 77 | "indent": [ 78 | 2, 79 | 2, 80 | { 81 | "SwitchCase": 1 82 | } 83 | ], 84 | "key-spacing": [ 85 | 2, 86 | { 87 | "beforeColon": false, 88 | "afterColon": true 89 | } 90 | ], 91 | "keyword-spacing": [ 92 | 2, 93 | { 94 | "before": true, 95 | "after": true 96 | } 97 | ], 98 | "new-cap": [ 99 | 2, 100 | { 101 | "newIsCap": true, 102 | "capIsNew": false 103 | } 104 | ], 105 | "new-parens": 2, 106 | "no-array-constructor": 2, 107 | "no-caller": 2, 108 | "no-class-assign": 2, 109 | "no-cond-assign": 2, 110 | "no-const-assign": 2, 111 | "no-control-regex": 2, 112 | "no-debugger": 2, 113 | "no-delete-var": 2, 114 | "no-dupe-args": 2, 115 | "no-dupe-class-members": 2, 116 | "no-dupe-keys": 2, 117 | "no-duplicate-case": 2, 118 | "no-empty-character-class": 2, 119 | "no-eval": 2, 120 | "no-ex-assign": 2, 121 | "no-extend-native": 2, 122 | "no-extra-bind": 2, 123 | "no-extra-boolean-cast": 2, 124 | "no-extra-parens": [ 125 | 2, 126 | "functions" 127 | ], 128 | "no-fallthrough": 2, 129 | "no-floating-decimal": 2, 130 | "no-func-assign": 2, 131 | "no-implied-eval": 2, 132 | "no-inner-declarations": [ 133 | 2, 134 | "functions" 135 | ], 136 | "no-invalid-regexp": 2, 137 | "no-irregular-whitespace": 2, 138 | "no-iterator": 2, 139 | "no-label-var": 2, 140 | "no-labels": 2, 141 | "no-lone-blocks": 2, 142 | "no-mixed-spaces-and-tabs": 2, 143 | "no-multi-spaces": 2, 144 | "no-multi-str": 2, 145 | "no-multiple-empty-lines": [ 146 | 2, 147 | { 148 | "max": 1 149 | } 150 | ], 151 | "no-native-reassign": 0, 152 | "no-negated-in-lhs": 2, 153 | "no-new": 2, 154 | "no-new-func": 2, 155 | "no-new-object": 2, 156 | "no-new-require": 2, 157 | "no-new-wrappers": 2, 158 | "no-obj-calls": 2, 159 | "no-octal": 2, 160 | "no-octal-escape": 2, 161 | "no-proto": 0, 162 | "no-redeclare": 2, 163 | "no-regex-spaces": 2, 164 | "no-return-assign": 2, 165 | "no-self-compare": 2, 166 | "no-sequences": 2, 167 | "no-shadow-restricted-names": 2, 168 | "no-spaced-func": 2, 169 | "no-sparse-arrays": 2, 170 | "no-this-before-super": 2, 171 | "no-throw-literal": 2, 172 | "no-trailing-spaces": 0, 173 | "no-undef": 2, 174 | "no-undef-init": 2, 175 | "no-unexpected-multiline": 2, 176 | "no-unneeded-ternary": [ 177 | 2, 178 | { 179 | "defaultAssignment": false 180 | } 181 | ], 182 | "no-unreachable": 2, 183 | "no-unused-vars": [ 184 | 2, 185 | { 186 | "vars": "all", 187 | "args": "none" 188 | } 189 | ], 190 | "no-useless-call": 0, 191 | "no-with": 2, 192 | "one-var": [ 193 | 0, 194 | { 195 | "initialized": "never" 196 | } 197 | ], 198 | "operator-linebreak": [ 199 | 0, 200 | "after", 201 | { 202 | "overrides": { 203 | "?": "before", 204 | ":": "before" 205 | } 206 | } 207 | ], 208 | "padded-blocks": [ 209 | 0, 210 | "never" 211 | ], 212 | "quotes": [ 213 | 2, 214 | "single", 215 | "avoid-escape" 216 | ], 217 | "radix": 2, 218 | "semi": [ 219 | 2, 220 | "always" 221 | ], 222 | "semi-spacing": [ 223 | 2, 224 | { 225 | "before": false, 226 | "after": true 227 | } 228 | ], 229 | "space-before-blocks": [ 230 | 2, 231 | "always" 232 | ], 233 | "space-before-function-paren": [ 234 | 2, 235 | "never" 236 | ], 237 | "space-in-parens": [ 238 | 2, 239 | "never" 240 | ], 241 | "space-infix-ops": 2, 242 | "space-unary-ops": [ 243 | 2, 244 | { 245 | "words": true, 246 | "nonwords": false 247 | } 248 | ], 249 | "spaced-comment": [ 250 | 0, 251 | "always", 252 | { 253 | "markers": [ 254 | "global", 255 | "globals", 256 | "eslint", 257 | "eslint-disable", 258 | "*package", 259 | "!", 260 | "," 261 | ] 262 | } 263 | ], 264 | "use-isnan": 2, 265 | "valid-typeof": 2, 266 | "wrap-iife": [ 267 | 2, 268 | "any" 269 | ], 270 | "yoda": [ 271 | 2, 272 | "never" 273 | ] 274 | } 275 | } 276 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.DS_Store 3 | *.csv 4 | *.dat 5 | *.diff 6 | *.err 7 | *.gz 8 | *.log 9 | *.orig 10 | *.out 11 | *.pid 12 | *.rar 13 | *.rej 14 | *.seed 15 | *.swo 16 | *.swp 17 | *.vi 18 | *.yo-rc.json 19 | *.zip 20 | *~ 21 | .ruby-version 22 | lib-cov 23 | npm-debug.log 24 | 25 | # Always-ignore dirs 26 | /bower_components/ 27 | /node_modules/ 28 | /temp/ 29 | /tmp/ 30 | /vendor/ 31 | _gh_pages 32 | 33 | # OS or Editor folders 34 | *.esproj 35 | *.komodoproject 36 | .komodotools 37 | *.sublime-* 38 | ._* 39 | .cache 40 | .DS_Store 41 | .idea 42 | .project 43 | .settings 44 | .tmproj 45 | nbproject 46 | Thumbs.db 47 | 48 | # grunt-html-validation 49 | validation-status.json 50 | validation-report.json 51 | 52 | # misc 53 | TODO.md -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '5' 5 | - '4' 6 | - '0.12' 7 | - '0.10' 8 | matrix: 9 | fast_finish: true 10 | allow_failures: 11 | - node_js: '0.10' 12 | - node_js: '0.12' 13 | git: 14 | depth: 10 15 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | ## Usage 2 | 3 | ```js 4 | var isDirectory = require('{%= name %}'); 5 | 6 | isDirectory('node_modules', function(err, dir) { 7 | if (err) throw err; 8 | console.log(dir); 9 | //=> true 10 | }); 11 | 12 | isDirectory.sync('README.md'); 13 | //=> false 14 | ``` 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2016, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 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) 2 | 3 | Returns true if a filepath exists on the file system and it's directory. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install is-directory --save 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | var isDirectory = require('is-directory'); 17 | 18 | isDirectory('node_modules', function(err, dir) { 19 | if (err) throw err; 20 | console.log(dir); 21 | //=> true 22 | }); 23 | 24 | isDirectory.sync('README.md'); 25 | //=> false 26 | ``` 27 | 28 | ## Related projects 29 | 30 | You might also be interested in these projects: 31 | 32 | * [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) 33 | * [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) 34 | * [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) 35 | 36 | ## Contributing 37 | 38 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/is-directory/issues/new). 39 | 40 | ## Building docs 41 | 42 | Generate readme and API documentation with [verb](https://github.com/verbose/verb): 43 | 44 | ```sh 45 | $ npm install verb && npm run docs 46 | ``` 47 | 48 | Or, if [verb](https://github.com/verbose/verb) is installed globally: 49 | 50 | ```sh 51 | $ verb 52 | ``` 53 | 54 | ## Running tests 55 | 56 | Install dev dependencies: 57 | 58 | ```sh 59 | $ npm install -d && npm test 60 | ``` 61 | 62 | ## Author 63 | 64 | **Jon Schlinkert** 65 | 66 | * [github/jonschlinkert](https://github.com/jonschlinkert) 67 | * [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 68 | 69 | ## License 70 | 71 | Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert). 72 | Released under the [MIT license](https://github.com/jonschlinkert/is-directory/blob/master/LICENSE). 73 | 74 | *** 75 | 76 | _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 21, 2016._ -------------------------------------------------------------------------------- /fixtures/foo.txt: -------------------------------------------------------------------------------- 1 | nothing to see 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | interface IsDirectory { 2 | (path: string, cb: (err: any, dir: boolean) => void): string; 3 | sync(path: string): boolean; 4 | } 5 | 6 | declare const isDirectory: IsDirectory; 7 | export = isDirectory; 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-directory 3 | * 4 | * Copyright (c) 2014-2015, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var fs = require('fs'); 11 | 12 | /** 13 | * async 14 | */ 15 | 16 | function isDirectory(filepath, cb) { 17 | if (typeof cb !== 'function') { 18 | throw new Error('expected a callback function'); 19 | } 20 | 21 | if (typeof filepath !== 'string') { 22 | cb(new Error('expected filepath to be a string')); 23 | return; 24 | } 25 | 26 | fs.stat(filepath, function(err, stats) { 27 | if (err) { 28 | if (err.code === 'ENOENT') { 29 | cb(null, false); 30 | return; 31 | } 32 | cb(err); 33 | return; 34 | } 35 | cb(null, stats.isDirectory()); 36 | }); 37 | } 38 | 39 | /** 40 | * sync 41 | */ 42 | 43 | isDirectory.sync = function isDirectorySync(filepath) { 44 | if (typeof filepath !== 'string') { 45 | throw new Error('expected filepath to be a string'); 46 | } 47 | 48 | try { 49 | var stat = fs.statSync(filepath); 50 | return stat.isDirectory(); 51 | } catch (err) { 52 | if (err.code === 'ENOENT') { 53 | return false; 54 | } else { 55 | throw err; 56 | } 57 | } 58 | return false; 59 | }; 60 | 61 | /** 62 | * Expose `isDirectory` 63 | */ 64 | 65 | module.exports = isDirectory; 66 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-directory", 3 | "description": "Returns true if a filepath exists on the file system and it's directory.", 4 | "version": "0.3.1", 5 | "homepage": "https://github.com/jonschlinkert/is-directory", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/is-directory", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/is-directory/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "index.js", 14 | "index.d.ts" 15 | ], 16 | "main": "index.js", 17 | "typings": "index.d.ts", 18 | "engines": { 19 | "node": ">=0.10.0" 20 | }, 21 | "scripts": { 22 | "test": "mocha" 23 | }, 24 | "devDependencies": { 25 | "gulp-format-md": "^0.1.9", 26 | "mocha": "^2.4.5" 27 | }, 28 | "keywords": [ 29 | "dir", 30 | "directories", 31 | "directory", 32 | "dirs", 33 | "file", 34 | "filepath", 35 | "files", 36 | "fp", 37 | "fs", 38 | "node", 39 | "node.js", 40 | "path", 41 | "paths", 42 | "system" 43 | ], 44 | "verb": { 45 | "toc": false, 46 | "layout": "default", 47 | "tasks": [ 48 | "readme" 49 | ], 50 | "plugins": [ 51 | "gulp-format-md" 52 | ], 53 | "related": { 54 | "list": [ 55 | "is-glob", 56 | "is-relative", 57 | "is-absolute" 58 | ] 59 | }, 60 | "lint": { 61 | "reflinks": true 62 | }, 63 | "reflinks": [ 64 | "verb" 65 | ] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('mocha'); 4 | var assert = require('assert'); 5 | var isDirectory = require('./'); 6 | 7 | describe('isDirectory', function() { 8 | describe('async errors:', function() { 9 | it('should throw an error when the callback is missing:', function(cb) { 10 | try { 11 | isDirectory('foo'); 12 | cb(new Error('expected an error')); 13 | } catch (err) { 14 | assert.equal(err.message, 'expected a callback function'); 15 | cb(); 16 | } 17 | }); 18 | 19 | it('should handle errors for bad args', function(cb) { 20 | isDirectory(null, function(err) { 21 | assert(err); 22 | assert.equal(err.message, 'expected filepath to be a string'); 23 | cb(); 24 | }); 25 | }); 26 | }); 27 | 28 | describe('async', function() { 29 | it('should return `true` if the path is a directory', function(cb) { 30 | isDirectory('node_modules', function(err, dir) { 31 | if (err) return cb(err); 32 | assert(dir); 33 | cb(); 34 | }); 35 | }); 36 | 37 | it('should be true when a path is a directory', function(cb) { 38 | isDirectory('fixtures', function(err, dir) { 39 | if (err) return cb(err); 40 | assert(dir); 41 | cb(); 42 | }); 43 | }); 44 | 45 | it('should be false for files that do not exist', function(cb) { 46 | isDirectory('fee-fie-foe', function(err, dir) { 47 | if (err) return cb(err); 48 | assert(!dir); 49 | cb(); 50 | }); 51 | }); 52 | 53 | it('should be `false` if the path is not a directory', function(cb) { 54 | isDirectory('.eslintrc.json', function(err, dir) { 55 | if (err) return cb(err); 56 | assert(!dir); 57 | 58 | isDirectory('README.md', function(err, dir) { 59 | if (err) return cb(err); 60 | assert(!dir); 61 | cb(); 62 | }); 63 | }); 64 | }); 65 | }); 66 | 67 | describe('sync', function() { 68 | it('should throw when invalid arguments are given', function(cb) { 69 | try { 70 | isDirectory.sync(); 71 | cb(new Error('expected an error')); 72 | } catch (err) { 73 | assert.equal(err.message, 'expected filepath to be a string'); 74 | cb(); 75 | } 76 | }); 77 | 78 | it('should return `true` if the path is a directory', function() { 79 | assert(isDirectory.sync('node_modules')); 80 | }); 81 | 82 | it('should return `false` if the path is not a directory', function() { 83 | assert(!isDirectory.sync('.jshintrc')); 84 | assert(!isDirectory.sync('README.md')); 85 | assert(!isDirectory.sync('LICENSE')); 86 | }); 87 | }); 88 | }); 89 | 90 | --------------------------------------------------------------------------------