path-exists
Advanced tools
Comparing version 3.0.0 to 4.0.0
22
index.js
'use strict'; | ||
const fs = require('fs'); | ||
const {promisify} = require('util'); | ||
module.exports = fp => new Promise(resolve => { | ||
fs.access(fp, err => { | ||
resolve(!err); | ||
}); | ||
}); | ||
const pAccess = promisify(fs.access); | ||
module.exports.sync = fp => { | ||
module.exports = async path => { | ||
try { | ||
fs.accessSync(fp); | ||
await pAccess(path); | ||
return true; | ||
} catch (err) { | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
module.exports.sync = path => { | ||
try { | ||
fs.accessSync(path); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
}; |
{ | ||
"name": "path-exists", | ||
"version": "3.0.0", | ||
"description": "Check if a path exists", | ||
"license": "MIT", | ||
"repository": "sindresorhus/path-exists", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"path", | ||
"exists", | ||
"exist", | ||
"file", | ||
"filepath", | ||
"fs", | ||
"filesystem", | ||
"file-system", | ||
"access", | ||
"stat" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "path-exists", | ||
"version": "4.0.0", | ||
"description": "Check if a path exists", | ||
"license": "MIT", | ||
"repository": "sindresorhus/path-exists", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"path", | ||
"exists", | ||
"exist", | ||
"file", | ||
"filepath", | ||
"fs", | ||
"filesystem", | ||
"file-system", | ||
"access", | ||
"stat" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -5,4 +5,6 @@ # path-exists [![Build Status](https://travis-ci.org/sindresorhus/path-exists.svg?branch=master)](https://travis-ci.org/sindresorhus/path-exists) | ||
Because [`fs.exists()`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback) is being [deprecated](https://github.com/iojs/io.js/issues/103), but there's still a genuine use-case of being able to check if a path exists for other purposes than doing IO with it. | ||
NOTE: `fs.existsSync` has been un-deprecated in Node.js since 6.8.0. If you only need to check synchronously, this module is not needed. | ||
While [`fs.exists()`](https://nodejs.org/api/fs.html#fs_fs_exists_path_callback) is being [deprecated](https://github.com/iojs/io.js/issues/103), there's still a genuine use-case of being able to check if a path exists for other purposes than doing IO with it. | ||
Never use this before handling a file though: | ||
@@ -16,3 +18,3 @@ | ||
``` | ||
$ npm install --save path-exists | ||
$ npm install path-exists | ||
``` | ||
@@ -27,6 +29,6 @@ | ||
pathExists('foo.js').then(exists => { | ||
console.log(exists); | ||
(async () => { | ||
console.log(await pathExists('foo.js')); | ||
//=> true | ||
}); | ||
})(); | ||
``` | ||
@@ -39,7 +41,7 @@ | ||
Returns a promise for a boolean of whether the path exists. | ||
Returns a `Promise<boolean>` of whether the path exists. | ||
### pathExists.sync(path) | ||
Returns a boolean of whether the path exists. | ||
Returns a `boolean` of whether the path exists. | ||
@@ -46,0 +48,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3919
5
42
53
3