refactor: remove lodash
This commit is contained in:
parent
855ca3cf31
commit
7cf318ff67
11
index.js
11
index.js
|
@ -1,7 +1,6 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
/* global hexo */
|
/* global hexo */
|
||||||
|
|
||||||
const _ = require("lodash");
|
|
||||||
const { JSDOM } = require("jsdom");
|
const { JSDOM } = require("jsdom");
|
||||||
|
|
||||||
const options = Object.assign(
|
const options = Object.assign(
|
||||||
|
@ -71,11 +70,11 @@ function replaceColons(node) {
|
||||||
|
|
||||||
function loadCustomEmojis(customEmojis) {
|
function loadCustomEmojis(customEmojis) {
|
||||||
// JSON string
|
// JSON string
|
||||||
if (_.isString(customEmojis)) {
|
if (typeof customEmojis === "string") {
|
||||||
try {
|
try {
|
||||||
customEmojis = JSON.parse(customEmojis);
|
customEmojis = JSON.parse(customEmojis);
|
||||||
Object.keys(customEmojis).forEach((name) => {
|
Object.keys(customEmojis).forEach((name) => {
|
||||||
if (_.isString(customEmojis[name])) {
|
if (typeof customEmojis[name] === "string") {
|
||||||
customEmojis[name] = {
|
customEmojis[name] = {
|
||||||
src: customEmojis[name],
|
src: customEmojis[name],
|
||||||
};
|
};
|
||||||
|
@ -89,7 +88,7 @@ function loadCustomEmojis(customEmojis) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_.isObject(customEmojis)) {
|
if (typeof customEmojis !== "object" || customEmojis === null) {
|
||||||
customEmojis = {};
|
customEmojis = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +97,7 @@ function loadCustomEmojis(customEmojis) {
|
||||||
emojis[name] = Object.assign(
|
emojis[name] = Object.assign(
|
||||||
{},
|
{},
|
||||||
emoji,
|
emoji,
|
||||||
emoji.codepoints && !_.isArray(emoji.codepoints)
|
emoji.codepoints && !Array.isArray(emoji.codepoints)
|
||||||
? { codepoints: emoji.codepoints.split(" ") }
|
? { codepoints: emoji.codepoints.split(" ") }
|
||||||
: {}
|
: {}
|
||||||
);
|
);
|
||||||
|
@ -109,7 +108,7 @@ function loadCustomEmojis(customEmojis) {
|
||||||
function renderEmoji(name) {
|
function renderEmoji(name) {
|
||||||
if (!emojis[name]) return 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)
|
? ` style="${Object.keys(options.styles)
|
||||||
.map((k) => k + ":" + options.styles[k])
|
.map((k) => k + ":" + options.styles[k])
|
||||||
.join(";")}"`
|
.join(";")}"`
|
||||||
|
|
Loading…
Reference in New Issue