From 780a311c0a63d0e06bb13362ccb546b819cfbff9 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 4 Jan 2018 02:18:56 +0200 Subject: [PATCH] Minor refactor to Util methods (#2213) * Minor refactor to Util methods * Fix derp --- src/util/Util.js | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/util/Util.js b/src/util/Util.js index f1758000d..1d6f2d17b 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -77,15 +77,10 @@ class Util { */ static parseEmoji(text) { if (text.includes('%')) text = decodeURIComponent(text); - if (text.includes(':')) { - const m = text.match(/?/); - if (!m) { - return null; - } - return { animated: Boolean(m[1]), name: m[2], id: m[3] }; - } else { - return { animated: false, name: text, id: null }; - } + if (!text.includes(':')) return { animated: false, name: text, id: null }; + const m = text.match(/?/); + if (!m) return null; + return { animated: Boolean(m[1]), name: m[2], id: m[3] }; } /** @@ -184,11 +179,11 @@ class Util { * @private */ static makePlainError(err) { - const obj = {}; - obj.name = err.name; - obj.message = err.message; - obj.stack = err.stack; - return obj; + return { + name: err.name, + message: err.message, + stack: err.stack, + }; } /** @@ -318,8 +313,8 @@ class Util { * @private */ static basename(path, ext) { - let f = splitPathRe.exec(path).slice(1)[2]; - if (ext && f.substr(-1 * ext.length) === ext) f = f.substr(0, f.length - ext.length); + let f = splitPathRe.exec(path)[3]; + if (ext && f.endsWith(ext)) f = f.slice(0, -ext.length); return f; }