From 7cf318ff6705f57290e1714d176f8bbdf297f987 Mon Sep 17 00:00:00 2001 From: crimx Date: Tue, 26 Apr 2022 01:01:10 +0800 Subject: [PATCH] refactor: remove lodash --- index.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 25a86ab..8d2d25f 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ "use strict"; /* global hexo */ -const _ = require("lodash"); const { JSDOM } = require("jsdom"); const options = Object.assign( @@ -71,11 +70,11 @@ function replaceColons(node) { function loadCustomEmojis(customEmojis) { // JSON string - if (_.isString(customEmojis)) { + if (typeof customEmojis === "string") { try { customEmojis = JSON.parse(customEmojis); Object.keys(customEmojis).forEach((name) => { - if (_.isString(customEmojis[name])) { + if (typeof customEmojis[name] === "string") { customEmojis[name] = { src: customEmojis[name], }; @@ -89,7 +88,7 @@ function loadCustomEmojis(customEmojis) { } } - if (!_.isObject(customEmojis)) { + if (typeof customEmojis !== "object" || customEmojis === null) { customEmojis = {}; } @@ -98,7 +97,7 @@ function loadCustomEmojis(customEmojis) { emojis[name] = Object.assign( {}, emoji, - emoji.codepoints && !_.isArray(emoji.codepoints) + emoji.codepoints && !Array.isArray(emoji.codepoints) ? { codepoints: emoji.codepoints.split(" ") } : {} ); @@ -109,7 +108,7 @@ function loadCustomEmojis(customEmojis) { function renderEmoji(name) { if (!emojis[name]) return name; - const styles = _.isObject(options.styles) + const styles = typeof options.styles === "object" && options.styles !== null ? ` style="${Object.keys(options.styles) .map((k) => k + ":" + options.styles[k]) .join(";")}"`