diff --git a/client/dom/current-file.spec.js b/client/dom/current-file.spec.js index 3d822206..de1ba2af 100644 --- a/client/dom/current-file.spec.js +++ b/client/dom/current-file.spec.js @@ -261,12 +261,10 @@ test('current-file: isCurrentIsDir: file', (t) => { t.end(); }); -function getCloudCmd({emit} = {}) { - return { - prefix: '', - emit: emit || stub(), - }; -} +const getCloudCmd = ({emit} = {}) => ({ + prefix: '', + emit: emit || stub(), +}); test('current-file: parseNameAttribute', (t) => { const result = currentFile._parseNameAttribute('js-file-aGVsbG8mbmJzcDt3b3JsZA=='); diff --git a/client/dom/directory.js b/client/dom/directory.js index 88802d40..c7cfa386 100644 --- a/client/dom/directory.js +++ b/client/dom/directory.js @@ -63,14 +63,8 @@ module.exports = (items) => { uploader.on('end', CloudCmd.refresh); }; -function percent(i, n, per = 100) { - return Math.round(i * per / n); -} +const percent = (i, n, per = 100) => Math.round(i * per / n); -function uploadFile(url, data) { - return DOM.load.put(url, data); -} +const uploadFile = (url, data) => DOM.load.put(url, data); -function uploadDir(url) { - return DOM.load.put(`${url}?dir`); -} +const uploadDir = (url) => DOM.load.put(`${url}?dir`); diff --git a/client/dom/images.js b/client/dom/images.js index 382da9e8..bb5579c1 100644 --- a/client/dom/images.js +++ b/client/dom/images.js @@ -10,9 +10,7 @@ const LOADING = 'loading'; const HIDDEN = 'hidden'; const ERROR = 'error'; -function getLoadingType() { - return isSVG() ? '-svg' : '-gif'; -} +const getLoadingType = () => isSVG() ? '-svg' : '-gif'; module.exports.get = getElement; /** diff --git a/client/dom/load-remote.js b/client/dom/load-remote.js index 0def5f00..72fb9db9 100644 --- a/client/dom/load-remote.js +++ b/client/dom/load-remote.js @@ -17,42 +17,40 @@ module.exports = (name, options, callback = options) => { if (o.name && window[o.name]) return callback(); - Files - .get('modules') - .then(async (modules) => { - const online = config('online') && navigator.onLine; - const module = findObjByNameInArr(modules.remote, name); - - const isArray = itype.array(module.local); - const {version} = module; - - let remoteTmpls; - let local; - - if (isArray) { - remoteTmpls = module.remote; - local = module.local; - } else { - remoteTmpls = [module.remote]; - local = [module.local]; - } - - const localURL = local.map((url) => prefix + url); - - const remoteURL = remoteTmpls.map((tmpl) => { - return rendy(tmpl, { - version, - }); + Files.get('modules').then(async (modules) => { + const online = config('online') && navigator.onLine; + const module = findObjByNameInArr(modules.remote, name); + + const isArray = itype.array(module.local); + const {version} = module; + + let remoteTmpls; + let local; + + if (isArray) { + remoteTmpls = module.remote; + local = module.local; + } else { + remoteTmpls = [module.remote]; + local = [module.local]; + } + + const localURL = local.map((url) => prefix + url); + + const remoteURL = remoteTmpls.map((tmpl) => { + return rendy(tmpl, { + version, }); - - if (online) { - const [e] = await tryToCatch(load.parallel, remoteURL); - - if (!e) - return callback(); - } - - const [e] = await tryToCatch(load.parallel, localURL); - callback(e); }); + + if (online) { + const [e] = await tryToCatch(load.parallel, remoteURL); + + if (!e) + return callback(); + } + + const [e] = await tryToCatch(load.parallel, localURL); + callback(e); + }); }; diff --git a/client/modules/edit.js b/client/modules/edit.js index a62535b7..441aaf62 100644 --- a/client/modules/edit.js +++ b/client/modules/edit.js @@ -11,6 +11,7 @@ const load = require('load.js'); const {MAX_FILE_SIZE: maxSize} = require('../../common/cloudfunc'); const {time, timeEnd} = require('../../common/util'); +const getEditor = () => editor; const isFn = (a) => typeof a === 'function'; const loadJS = load.js; @@ -91,10 +92,6 @@ module.exports.show = (options) => { module.exports.getEditor = getEditor; -function getEditor() { - return editor; -} - module.exports.getElement = () => Element; module.exports.hide = () => { diff --git a/client/modules/konsole.js b/client/modules/konsole.js index 41936486..6993380d 100644 --- a/client/modules/konsole.js +++ b/client/modules/konsole.js @@ -46,22 +46,18 @@ module.exports.clear = () => { konsole.clear(); }; -function getPrefix() { - return CloudCmd.prefix + '/console'; -} +const getPrefix = () => CloudCmd.prefix + '/console'; function getPrefixSocket() { return CloudCmd.prefixSocket + '/console'; } -function getEnv() { - return { - ACTIVE_DIR: DOM.getCurrentDirPath.bind(DOM), - PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM), - CURRENT_NAME: DOM.getCurrentName.bind(DOM), - CURRENT_PATH: () => Info.path, - }; -} +const getEnv = () => ({ + ACTIVE_DIR: DOM.getCurrentDirPath.bind(DOM), + PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM), + CURRENT_NAME: DOM.getCurrentName.bind(DOM), + CURRENT_PATH: () => Info.path, +}); async function onPath(path) { if (Info.dirPath === path) diff --git a/client/modules/menu.js b/client/modules/menu.js index 150bb186..8f739164 100644 --- a/client/modules/menu.js +++ b/client/modules/menu.js @@ -226,9 +226,7 @@ function beforeShow(callback, params) { return isShow; } -function beforeClick(name) { - return MenuShowedName !== name; -} +const beforeClick = (name) => MenuShowedName !== name; async function _uploadTo(nameModule) { const [error, data] = await Info.getData(); diff --git a/client/modules/terminal-run.js b/client/modules/terminal-run.js index 01bd30a9..3e4b857d 100644 --- a/client/modules/terminal-run.js +++ b/client/modules/terminal-run.js @@ -75,22 +75,18 @@ function hide() { CloudCmd.View.hide(); } -function getPrefix() { - return CloudCmd.prefix + '/gritty'; -} +const getPrefix = () => CloudCmd.prefix + '/gritty'; function getPrefixSocket() { return CloudCmd.prefixSocket + '/gritty'; } -function getEnv() { - return { - ACTIVE_DIR: DOM.getCurrentDirPath, - PASSIVE_DIR: DOM.getNotCurrentDirPath, - CURRENT_NAME: DOM.getCurrentName, - CURRENT_PATH: DOM.getCurrentPath, - }; -} +const getEnv = () => ({ + ACTIVE_DIR: DOM.getCurrentDirPath, + PASSIVE_DIR: DOM.getNotCurrentDirPath, + CURRENT_NAME: DOM.getCurrentName, + CURRENT_PATH: DOM.getCurrentPath, +}); function create(createOptions) { const { diff --git a/client/modules/terminal.js b/client/modules/terminal.js index f94024d4..d36b700a 100644 --- a/client/modules/terminal.js +++ b/client/modules/terminal.js @@ -57,22 +57,18 @@ function hide() { CloudCmd.View.hide(); } -function getPrefix() { - return CloudCmd.prefix + '/gritty'; -} +const getPrefix = () => CloudCmd.prefix + '/gritty'; function getPrefixSocket() { return CloudCmd.prefixSocket + '/gritty'; } -function getEnv() { - return { - ACTIVE_DIR: DOM.getCurrentDirPath, - PASSIVE_DIR: DOM.getNotCurrentDirPath, - CURRENT_NAME: DOM.getCurrentName, - CURRENT_PATH: DOM.getCurrentPath, - }; -} +const getEnv = () => ({ + ACTIVE_DIR: DOM.getCurrentDirPath, + PASSIVE_DIR: DOM.getNotCurrentDirPath, + CURRENT_NAME: DOM.getCurrentName, + CURRENT_PATH: DOM.getCurrentPath, +}); function create() { const options = { diff --git a/client/modules/view/get-type.js b/client/modules/view/get-type.js index 80252aa1..3ac092e0 100644 --- a/client/modules/view/get-type.js +++ b/client/modules/view/get-type.js @@ -45,9 +45,7 @@ function isMedia(name) { return isAudio(name) || isVideo(name); } -function isAudio(name) { - return /\.(mp3|ogg|m4a)$/i.test(name); -} +const isAudio = (name) => /\.(mp3|ogg|m4a)$/i.test(name); function isVideo(name) { return /\.(mp4|avi|webm)$/i.test(name); diff --git a/client/modules/view/index.js b/client/modules/view/index.js index 0e79ab4e..17a3b1fa 100644 --- a/client/modules/view/index.js +++ b/client/modules/view/index.js @@ -55,7 +55,10 @@ CloudCmd[Name] = module.exports; const Info = DOM.CurrentInfo; const {Key} = CloudCmd; -const basename = (a) => a.split('/').pop(); + +const basename = (a) => a + .split('/') + .pop(); let El; let TemplateAudio; diff --git a/client/modules/view/types.js b/client/modules/view/types.js index 0ea9aef9..e36fec4d 100644 --- a/client/modules/view/types.js +++ b/client/modules/view/types.js @@ -2,6 +2,7 @@ const {extname} = require('node:path'); const currify = require('currify'); +const isAudio = (name) => /\.(mp3|ogg|m4a)$/i.test(name); const testRegExp = currify((name, reg) => reg.test(name)); const getRegExp = (ext) => RegExp(`\\.${ext}$`, 'i'); @@ -53,9 +54,6 @@ function isMedia(name) { } module.exports.isAudio = isAudio; -function isAudio(name) { - return /\.(mp3|ogg|m4a)$/i.test(name); -} function isVideo(name) { return /\.(mp4|avi|webm)$/i.test(name);