Skip to content

Conversation

@aderchox
Copy link

Hi, I've added ESM support to this package. Things done in this commit:
- Converts CommonJS module.exports to ESM export using a Rollup plugin
- Adds an ESM import to the example in README.md
- Adds the change in HISTORY.md
- Adds "exports" key in package.json to detect proper export automatically
I don't know Travis CI though, that should probably be updated too so that index.mjs will not be ignored when installing the package using NPM. Thank you.

	- Converts CommonJS module.exports to ESM export using a Rollup plugin
	- Adds an ESM import to the example in README.md
	- Adds the change in HISTORY.md
	- Adds "exports" key in package.json to detect proper export automatically
@WofWca
Copy link

WofWca commented Oct 10, 2025

I have confirmed that the new file only contains gluing and formatting changes (if you add semicolons, the differences go away). This means that the functionality is the same.

diff
@@ -6,19 +6,21 @@
  * MIT Licensed
  */
 
+'use strict'
+
 /**
  * Module variables.
  * @private
  */
 
-var matchHtmlRegExp = /["'&<>]/;
+var matchHtmlRegExp = /["'&<>]/
 
 /**
  * Module exports.
  * @public
  */
 
-var oss = escapeHtml;
+module.exports = escapeHtml
 
 /**
  * Escape special characters in the given string of text.
@@ -29,50 +31,48 @@ var oss = escapeHtml;
  */
 
 function escapeHtml (string) {
-  var str = '' + string;
-  var match = matchHtmlRegExp.exec(str);
+  var str = '' + string
+  var match = matchHtmlRegExp.exec(str)
 
   if (!match) {
     return str
   }
 
-  var escape;
-  var html = '';
-  var index = 0;
-  var lastIndex = 0;
+  var escape
+  var html = ''
+  var index = 0
+  var lastIndex = 0
 
   for (index = match.index; index < str.length; index++) {
     switch (str.charCodeAt(index)) {
       case 34: // "
-        escape = '&quot;';
+        escape = '&quot;'
         break
       case 38: // &
-        escape = '&amp;';
+        escape = '&amp;'
         break
       case 39: // '
-        escape = '&#39;';
+        escape = '&#39;'
         break
       case 60: // <
-        escape = '&lt;';
+        escape = '&lt;'
         break
       case 62: // >
-        escape = '&gt;';
+        escape = '&gt;'
         break
       default:
         continue
     }
 
     if (lastIndex !== index) {
-      html += str.substring(lastIndex, index);
+      html += str.substring(lastIndex, index)
     }
 
-    lastIndex = index + 1;
-    html += escape;
+    lastIndex = index + 1
+    html += escape
   }
 
   return lastIndex !== index
     ? html + str.substring(lastIndex, index)
     : html
-}
-
-export { oss as default };
\ No newline at end of file
+}
\ No newline at end of file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants