From b213e1073bac1478649f26e3c0dad50ad0eb2a49 Mon Sep 17 00:00:00 2001 From: Zihua Li <635902+luin@users.noreply.github.com> Date: Fri, 19 Jul 2024 10:26:42 +0800 Subject: [PATCH] Avoid unnecessary local map creations --- .github/workflows/label.yml | 1 + packages/quill/src/blots/text.ts | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml index 26ee060b16..6a683b2057 100644 --- a/.github/workflows/label.yml +++ b/.github/workflows/label.yml @@ -20,4 +20,5 @@ jobs: change:feature change:documentation change:chore + change:refactor add_comment: false diff --git a/packages/quill/src/blots/text.ts b/packages/quill/src/blots/text.ts index e00fd16ade..272fd11733 100644 --- a/packages/quill/src/blots/text.ts +++ b/packages/quill/src/blots/text.ts @@ -2,18 +2,17 @@ import { TextBlot } from 'parchment'; class Text extends TextBlot {} +// https://lodash.com/docs#escape +const entityMap: Record = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', +}; + function escapeText(text: string) { - return text.replace(/[&<>"']/g, (s) => { - // https://lodash.com/docs#escape - const entityMap: Record = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', - }; - return entityMap[s]; - }); + return text.replace(/[&<>"']/g, (s) => entityMap[s]); } export { Text as default, escapeText };