Merge pull request #2737 from PR0M3TH3AN/refactor-delete-modal-truncate-middle-16500239099294325231

🧹 Refactor: Remove duplicated string truncation logic in DeleteModal.js
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-26 14:40:38 -05:00
commit 589925f1fe
1 file changed
+2 -16
+2 -16
View File
@@ -1,3 +1,4 @@
import { truncateMiddle as defaultTruncateMiddle } from "../../utils/formatters.js";
import { createModalAccessibility } from "./modalAccessibility.js";
function extractDTagValue(tags) {
@@ -28,22 +29,7 @@ export class DeleteModal {
this.setGlobalModalState =
typeof setGlobalModalState === "function" ? setGlobalModalState : () => {};
this.truncateMiddle =
typeof truncateMiddle === "function" ? truncateMiddle : (value, maxLength = 48) => {
if (typeof value !== "string") {
return "";
}
if (value.length <= maxLength) {
return value;
}
if (maxLength <= 1) {
return value.slice(0, maxLength);
}
const ellipsis = "…";
const charsToShow = maxLength - ellipsis.length;
const front = Math.ceil(charsToShow / 2);
const back = Math.floor(charsToShow / 2);
return `${value.slice(0, front)}${ellipsis}${value.slice(value.length - back)}`;
};
typeof truncateMiddle === "function" ? truncateMiddle : defaultTruncateMiddle;
this.eventTarget = eventTarget instanceof EventTarget ? eventTarget : new EventTarget();
this.container = container || document.getElementById("modalContainer") || null;