Minor refactor to Util methods (#2213)

* Minor refactor to Util methods

* Fix derp
This commit is contained in:
Alex
2018-01-04 02:18:56 +02:00
committed by Crawl
parent 01f1f1b58e
commit 780a311c0a

View File

@@ -77,15 +77,10 @@ class Util {
*/ */
static parseEmoji(text) { static parseEmoji(text) {
if (text.includes('%')) text = decodeURIComponent(text); if (text.includes('%')) text = decodeURIComponent(text);
if (text.includes(':')) { if (!text.includes(':')) return { animated: false, name: text, id: null };
const m = text.match(/<?(a)?:(\w{2,32}):(\d{17,19})>?/); const m = text.match(/<?(a)?:(\w{2,32}):(\d{17,19})>?/);
if (!m) { if (!m) return null;
return null; return { animated: Boolean(m[1]), name: m[2], id: m[3] };
}
return { animated: Boolean(m[1]), name: m[2], id: m[3] };
} else {
return { animated: false, name: text, id: null };
}
} }
/** /**
@@ -184,11 +179,11 @@ class Util {
* @private * @private
*/ */
static makePlainError(err) { static makePlainError(err) {
const obj = {}; return {
obj.name = err.name; name: err.name,
obj.message = err.message; message: err.message,
obj.stack = err.stack; stack: err.stack,
return obj; };
} }
/** /**
@@ -318,8 +313,8 @@ class Util {
* @private * @private
*/ */
static basename(path, ext) { static basename(path, ext) {
let f = splitPathRe.exec(path).slice(1)[2]; let f = splitPathRe.exec(path)[3];
if (ext && f.substr(-1 * ext.length) === ext) f = f.substr(0, f.length - ext.length); if (ext && f.endsWith(ext)) f = f.slice(0, -ext.length);
return f; return f;
} }