diff --git a/client/edit.js b/client/edit.js index c3475e5a..a0c6375b 100644 --- a/client/edit.js +++ b/client/edit.js @@ -57,7 +57,7 @@ function EditProto(callback) { } function initConfig(config, options) { - Util.copyObj(config, ConfigView); + Object.assign(config, ConfigView); if (!options) return config; diff --git a/client/menu.js b/client/menu.js index 28dd7ad0..d2056dae 100644 --- a/client/menu.js +++ b/client/menu.js @@ -123,13 +123,13 @@ function MenuProto(position) { } function getMenuData(isAuth) { - var menu = { - 'Paste' : Buffer.paste, - 'New' : { - 'File' : DOM.promptNewFile, - 'Directory' : DOM.promptNewDir + const menu = { + 'Paste': Buffer.paste, + 'New': { + 'File': DOM.promptNewFile, + 'Directory': DOM.promptNewDir }, - 'Upload' : function() { + 'Upload': () => { CloudCmd.Upload.show(); }, 'Upload From Cloud': uploadFromCloud, @@ -151,42 +151,42 @@ function MenuProto(position) { } function loadFileMenuData(callback) { - var is = CloudCmd.config('auth'); - var show = function(name) { - CloudCmd[name].show(); - }, - Dialog = DOM.Dialog, - menuData = getMenuData(is), - menu = { - 'View' : curry(show, 'View'), - 'Edit' : curry(show, 'Edit'), - 'Rename' : function() { - setTimeout(DOM.renameCurrent, 100); - }, - 'Delete' : function() { - CloudCmd.Operation.show('delete'); - }, - 'Pack' : function() { - CloudCmd.Operation.show('pack'); - }, - 'Extract' : function() { - CloudCmd.Operation.show('extract'); - }, - 'Download' : preDownload, - 'Upload To Cloud': curry(uploadTo, 'Cloud'), - 'Cut' : function() { - isCurrent(Buffer.cut, function() { - Dialog.alert.noFiles(TITLE); - }); - }, - 'Copy' : function() { - isCurrent(Buffer.copy, function() { - Dialog.alert.noFiles(TITLE); - }); - }, - }; + const is = CloudCmd.config('auth'); + const show = (name) => { + CloudCmd[name].show(); + }; - Util.copyObj(menu, menuData); + const Dialog = DOM.Dialog; + const menuData = getMenuData(is); + + const menu = Object.assign({}, menuData, { + 'View' : curry(show, 'View'), + 'Edit' : curry(show, 'Edit'), + 'Rename' : () => { + setTimeout(DOM.renameCurrent, 100); + }, + 'Delete' : () => { + CloudCmd.Operation.show('delete'); + }, + 'Pack' : () => { + CloudCmd.Operation.show('pack'); + }, + 'Extract' : () => { + CloudCmd.Operation.show('extract'); + }, + 'Download' : preDownload, + 'Upload To Cloud': curry(uploadTo, 'Cloud'), + 'Cut' : () => { + isCurrent(Buffer.cut, () => { + Dialog.alert.noFiles(TITLE); + }); + }, + 'Copy' : () => { + isCurrent(Buffer.copy, () => { + Dialog.alert.noFiles(TITLE); + }); + }, + }); callback(is, menu); } diff --git a/common/util.js b/common/util.js index ae8360c9..7a5b5566 100644 --- a/common/util.js +++ b/common/util.js @@ -3,6 +3,7 @@ const exec = require('execon'); const rendy = require('rendy'); const jonny = require('jonny'); +const itype = require('itype/legacy'); module.exports = new UtilProto(exec); @@ -13,43 +14,24 @@ function UtilProto(exec) { this.getStrBigFirst = getStrBigFirst; this.kebabToCamelCase = kebabToCamelCase; - /** - * Copy properties from from to to - * - * @param from - * @param to - */ - this.copyObj = function(to, from) { - if (!from) { - from = to; - to = {}; - } - - if (to) - Object.keys(from).forEach(function(name) { - to[name] = from[name]; - }); - - return to; - }; - /** * copy objFrom properties to target * * @target * @objFrom */ - this.extend = function(target, objFrom) { - var obj; - var keys; - var proto; - var isFunc = typeof objFrom === 'function'; - var isArray = Array.isArray(objFrom); - var isObj = typeof target === 'object'; - var ret = isObj ? target : {}; + this.extend = (target, objFrom) => { + let obj; + let keys; + let proto; + + const isFunc = itype.function(objFrom); + const isArray = Array.isArray(objFrom); + const isObj = itype.object(target); + let ret = isObj ? target : {}; if (isArray) - objFrom.forEach(function(item) { + objFrom.forEach((item) => { ret = Util.extend(target, item); });