From f4f7395309bbbcc809df3919634f1f50658ac15d Mon Sep 17 00:00:00 2001 From: sanemat Date: Tue, 4 Aug 2015 03:11:06 +0900 Subject: [PATCH] Remove fs.existsSync() fs.existsSync() will be deprecated. https://nodejs.org/api/fs.html#fs_fs_existssync_path And io.js already deprecated fs.existsSync(). github.com/nodejs/io.js/issues/257 --- index.js | 6 +++++- test/is-file.js | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e71ac00..7cbdb71 100644 --- a/index.js +++ b/index.js @@ -14,5 +14,9 @@ module.exports = function isFile(path, cb){ module.exports.sync = isFileSync; function isFileSync(path){ - return fs.existsSync(path) && fs.statSync(path).isFile(); + try { + return fs.statSync(path).isFile(); + } catch (e) { + return false; + } } diff --git a/test/is-file.js b/test/is-file.js index d22fd1a..20bc2b8 100644 --- a/test/is-file.js +++ b/test/is-file.js @@ -38,5 +38,9 @@ describe('is-file', function(){ it('should return true for files', function(){ sut(__filename).should.be.true; }); + + it('should send back false when the path does not exist', function(){ + sut('asdasdf').should.be.false; + }); }); });