diff --git a/client/key/index.js b/client/key/index.js index dfb5d96c..3f04fb40 100644 --- a/client/key/index.js +++ b/client/key/index.js @@ -25,6 +25,8 @@ const toggleVim = (keyCode) => { } }; +const isUndefined = (a) => typeof a === 'undefined'; + Chars([]); const {assign} = Object; @@ -61,7 +63,7 @@ async function listener(event) { // strange chrome bug calles listener twice // in second time event misses a lot fields - if (typeof event.altKey === 'undefined') + if (isUndefined(event.altKey)) return; const alt = event.altKey; diff --git a/common/base64.js b/common/base64.js index bc73b7f3..4d09b256 100644 --- a/common/base64.js +++ b/common/base64.js @@ -1,7 +1,9 @@ 'use strict'; +const isFn = (a) => typeof a === 'function'; + module.exports.btoa = (str) => { - if (typeof btoa === 'function') + if (isFn(btoa)) return btoa(str); return Buffer @@ -10,7 +12,7 @@ module.exports.btoa = (str) => { }; module.exports.atob = (str) => { - if (typeof atob === 'function') + if (isFn(atob)) return atob(str); return Buffer diff --git a/server/cloudcmd.js b/server/cloudcmd.js index 6faa6ed0..527fc633 100644 --- a/server/cloudcmd.js +++ b/server/cloudcmd.js @@ -45,6 +45,9 @@ const initAuth = currify(_initAuth); const notEmpty = (a) => a; const clean = (a) => a.filter(notEmpty); +const isUndefined = (a) => typeof a === 'undefined'; +const isFn = (a) => typeof a === 'function'; + module.exports = (params) => { const p = params || {}; const options = p.config || {}; @@ -98,7 +101,7 @@ function defaultValue(config, name, options) { const value = options[name]; const previous = config(name); - if (typeof value === 'undefined') + if (isUndefined(value)) return previous; return value; @@ -106,7 +109,7 @@ function defaultValue(config, name, options) { module.exports._getPrefix = getPrefix; function getPrefix(prefix) { - if (typeof prefix === 'function') + if (isFn(prefix)) return prefix() || ''; return prefix || '';