Browse Source

Avoid unnecessary local map creations

Zihua Li 7 months ago
parent
commit
b213e1073b
2 changed files with 11 additions and 11 deletions
  1. 1 0
      .github/workflows/label.yml
  2. 10 11
      packages/quill/src/blots/text.ts

+ 1 - 0
.github/workflows/label.yml

@@ -20,4 +20,5 @@ jobs:
             change:feature
             change:documentation
             change:chore
+            change:refactor
           add_comment: false

+ 10 - 11
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<string, string> = {
+  '&': '&amp;',
+  '<': '&lt;',
+  '>': '&gt;',
+  '"': '&quot;',
+  "'": '&#39;',
+};
+
 function escapeText(text: string) {
-  return text.replace(/[&<>"']/g, (s) => {
-    // https://lodash.com/docs#escape
-    const entityMap: Record<string, string> = {
-      '&': '&amp;',
-      '<': '&lt;',
-      '>': '&gt;',
-      '"': '&quot;',
-      "'": '&#39;',
-    };
-    return entityMap[s];
-  });
+  return text.replace(/[&<>"']/g, (s) => entityMap[s]);
 }
 
 export { Text as default, escapeText };