escape-html
escape-html copied to clipboard
ESM support
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.
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 = '"';
+ escape = '"'
break
case 38: // &
- escape = '&';
+ escape = '&'
break
case 39: // '
- escape = ''';
+ escape = '''
break
case 60: // <
- escape = '<';
+ escape = '<'
break
case 62: // >
- escape = '>';
+ escape = '>'
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