diff --git a/client/client.js b/client/client.js index da0b5d95..0e9938fb 100644 --- a/client/client.js +++ b/client/client.js @@ -278,7 +278,7 @@ function CloudCmdProto(DOM) { const isRefresh = true; const history = false; - const noCurrent = options ? options.noCurrent : false; + const noCurrent = options?.noCurrent; await CloudCmd.changeDir(path, { isRefresh, diff --git a/client/dom/buffer.js b/client/dom/buffer.js index 189f6423..8c4be473 100644 --- a/client/dom/buffer.js +++ b/client/dom/buffer.js @@ -26,9 +26,8 @@ function BufferProto() { function getNames() { const files = DOM.getActiveFiles(); - const names = DOM.getFilenames(files); - return names; + return DOM.getFilenames(files); } function addCutClass() { diff --git a/client/dom/current-file.js b/client/dom/current-file.js index 2ab0ab51..1785a4c8 100644 --- a/client/dom/current-file.js +++ b/client/dom/current-file.js @@ -109,9 +109,8 @@ module.exports.getCurrentDirName = () => { .replace(/\/$/, ''); const substr = href.substr(href, href.lastIndexOf('/')); - const ret = href.replace(`${substr}/`, '') || '/'; - return ret; + return href.replace(`${substr}/`, '') || '/'; }; /** @@ -266,7 +265,7 @@ module.exports.getCurrentByPosition = ({x, y}) => { module.exports.isCurrentFile = (currentFile) => { if (!currentFile) return false; - + return DOM.isContainClass(currentFile, CURRENT_FILE); }; diff --git a/client/dom/index.js b/client/dom/index.js index adf2abc9..acefb5b9 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -1,5 +1,6 @@ 'use strict'; +const isString = (a) => typeof a === 'string'; /* global CloudCmd */ const Util = require('../../common/util'); @@ -116,9 +117,8 @@ module.exports.getCurrentDirName = () => { .replace(/\/$/, ''); const substr = href.substr(href, href.lastIndexOf('/')); - const ret = href.replace(`${substr}/`, '') || '/'; - return ret; + return href.replace(`${substr}/`, '') || '/'; }; /** @@ -143,9 +143,7 @@ module.exports.getNotCurrentDirPath = () => { active: false, }); - const path = DOM.getCurrentDirPath(panel); - - return path; + return DOM.getCurrentDirPath(panel); }; /** @@ -189,9 +187,8 @@ module.exports.getActiveFiles = () => { module.exports.getCurrentDate = (currentFile) => { const current = currentFile || DOM.getCurrentFile(); - const date = DOM.getByDataName('js-date', current).textContent; - return date; + return DOM.getByDataName('js-date', current).textContent; }; /** @@ -438,7 +435,7 @@ module.exports.setHistory = (data, title, url) => { module.exports.isSelected = (selected) => { if (!selected) return false; - + return DOM.isContainClass(selected, SELECTED_FILE); }; @@ -479,7 +476,7 @@ module.exports.getFilenames = (files) => { module.exports.checkStorageHash = async (name) => { const nameHash = `${name}-hash`; - if (typeof name !== 'string') + if (!isString(name)) throw Error('name should be a string!'); const [loadHash, storeHash] = await Promise.all([ @@ -723,7 +720,7 @@ module.exports.changePanel = () => { module.exports.getPackerExt = (type) => { if (type === 'zip') return '.zip'; - + return '.tar.gz'; }; @@ -749,7 +746,7 @@ module.exports.duplicatePanel = async () => { const getPath = (isDir) => { if (isDir) return Info.path; - + return Info.dirPath; }; diff --git a/client/key/index.js b/client/key/index.js index 094d4e75..6fe55307 100644 --- a/client/key/index.js +++ b/client/key/index.js @@ -111,9 +111,8 @@ function getSymbol(shift, keyCode) { function fromCharCode(keyIdentifier) { const code = keyIdentifier.substring(2); const hex = parseInt(code, 16); - const char = String.fromCharCode(hex); - return char; + return String.fromCharCode(hex); } async function switchKey(event) { diff --git a/client/listeners/index.js b/client/listeners/index.js index 02038407..dab178e3 100644 --- a/client/listeners/index.js +++ b/client/listeners/index.js @@ -94,7 +94,7 @@ function header() { function getPath(el, path = []) { if (!el) return path; - + return getPath(el.parentElement, path.concat(el)); } @@ -115,9 +115,8 @@ module.exports.initKeysPanel = () => { const {id} = target; const operation = (name) => { const {Operation} = CloudCmd; - const fn = Operation.show.bind(null, name); - return fn; + return Operation.show.bind(null, name); }; const clickFuncs = { @@ -143,7 +142,7 @@ module.exports.initKeysPanel = () => { const getPanel = (side) => { if (!itype.string(side)) return side; - + return DOM.getByDataName(`js-${side}`); }; diff --git a/client/modules/config/index.js b/client/modules/config/index.js index 5c586c48..76fed60b 100644 --- a/client/modules/config/index.js +++ b/client/modules/config/index.js @@ -75,9 +75,7 @@ function getHost() { protocol, } = location; - const href = origin || `${protocol}//${host}`; - - return href; + return origin || `${protocol}//${host}`; } function initSocket() { diff --git a/client/modules/edit.js b/client/modules/edit.js index ce8848af..44392dcb 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.js @@ -2,6 +2,7 @@ 'use strict'; +const isFn = (a) => typeof a === 'function'; const montag = require('montag'); const {promisify} = require('es6-promisify'); @@ -54,7 +55,7 @@ function create() { } function checkFn(name, fn) { - if (typeof fn !== 'function') + if (!isFn(fn)) throw Error(`${name} should be a function!`); } diff --git a/client/modules/menu.js b/client/modules/menu.js index c0dc664f..4a82d8bb 100644 --- a/client/modules/menu.js +++ b/client/modules/menu.js @@ -77,7 +77,7 @@ function getPosition(position) { x: position.x, y: position.y, }; - + return getCurrentPosition(); } @@ -196,9 +196,8 @@ function isPath(x, y) { const el = document.elementFromPoint(x, y); const elements = panel.querySelectorAll('[data-name="js-path"] *'); - const is = ~[].indexOf.call(elements, el); - return is; + return ~[].indexOf.call(elements, el); } function beforeShow(callback, params) { diff --git a/client/modules/view/index.js b/client/modules/view/index.js index 377c5e7f..893e9df1 100644 --- a/client/modules/view/index.js +++ b/client/modules/view/index.js @@ -2,6 +2,7 @@ 'use strict'; +const isString = (a) => typeof a === 'string'; require('../../../css/view.css'); const rendy = require('rendy'); @@ -317,7 +318,7 @@ async function getMediaElement(src) { } function check(src) { - if (typeof src !== 'string') + if (!isString(src)) throw Error('src should be a string!'); }