From 92123e17615eefaf24465d7b200290cc6f20df6b Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 29 Jan 2025 19:39:26 +0100 Subject: [PATCH] refactor(server/utils): get rid of isString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit let's use typeof x === "string" → works exactly the same and at the same speed as this custom isString fn --- src/services/notes.ts | 4 ++-- src/services/utils.spec.ts | 2 -- src/services/utils.ts | 5 ----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/services/notes.ts b/src/services/notes.ts index d0a699984..0faf08d74 100644 --- a/src/services/notes.ts +++ b/src/services/notes.ts @@ -6,7 +6,7 @@ import eventService from "./events.js"; import cls from "../services/cls.js"; import protectedSessionService from "../services/protected_session.js"; import log from "../services/log.js"; -import { newEntityId, isString, unescapeHtml, quoteRegex, toMap } from "../services/utils.js"; +import { newEntityId, unescapeHtml, quoteRegex, toMap } from "../services/utils.js"; import revisionService from "./revisions.js"; import request from "./request.js"; import path from "path"; @@ -884,7 +884,7 @@ async function asyncPostProcessContent(note: BNote, content: string | Buffer) { return; } - if (note.hasStringContent() && !isString(content)) { + if (note.hasStringContent() && typeof content !== "string") { content = content.toString(); } diff --git a/src/services/utils.spec.ts b/src/services/utils.spec.ts index 190bfabf4..3ede44aa5 100644 --- a/src/services/utils.spec.ts +++ b/src/services/utils.spec.ts @@ -143,8 +143,6 @@ describe.todo("#normalize", () => {}); describe.todo("#toMap", () => {}); -describe.todo("#isString", () => {}); - describe("#envToBoolean", () => { const testCases: TestCase[] = [ ["w/ 'true' it should return boolean 'true'", ["true"], true], diff --git a/src/services/utils.ts b/src/services/utils.ts index f101f6064..a1a7cc05c 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -295,10 +295,6 @@ export function toMap>(list: T[], key: keyof T): R return map; } -export function isString(x: any) { - return Object.prototype.toString.call(x) === "[object String]"; -} - // try to turn 'true' and 'false' strings from process.env variables into boolean values or undefined export function envToBoolean(val: string | undefined) { if (val === undefined || typeof val !== "string") return undefined; @@ -357,7 +353,6 @@ export default { normalize, hashedBlobId, toMap, - isString, getResourceDir, isMac, isWindows,