From 76ae1d149263758af2a48384f3e48d8ccf34bc52 Mon Sep 17 00:00:00 2001 From: Marc Walter Date: Sat, 13 Jun 2020 09:14:37 +0200 Subject: [PATCH] Add isFunction() helper --- index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index fa768fb..d280d54 100644 --- a/index.js +++ b/index.js @@ -44,14 +44,14 @@ function prep(fs, Promise) { return hashElementPromise(basename, dir, options, true); }) .then(result => { - if (typeof callback === 'function') { + if (isFunction(callback)) { return callback(undefined, result); } else { return result; } }) .catch(reason => { - if (typeof callback === 'function') { + if (isFunction(callback)) { return callback(reason); } else { throw reason; @@ -268,6 +268,10 @@ function parseParameters(args) { return Promise.resolve(log.params({ basename, dir, options })); } +function isFunction(any) { + return typeof any === 'function'; +} + function isString(str) { return typeof str === 'string' || str instanceof String; } @@ -281,7 +285,7 @@ function notUndefined(obj) { } function reduceGlobPatterns(globs) { - if (typeof globs === 'function') { + if (isFunction(globs)) { return globs; } else if (!globs || !Array.isArray(globs) || globs.length === 0) {