Skip to content

Commit

Permalink
Merge pull request #2 from WebReflection/real-dual-module
Browse files Browse the repository at this point in the history
V3 ESM Only Release
  • Loading branch information
WebReflection committed Mar 27, 2020
2 parents 88f420a + 5f74a34 commit 6963b06
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 66 deletions.
14 changes: 10 additions & 4 deletions README.md
Expand Up @@ -2,16 +2,22 @@
A simple module to escape/unescape common problematic entities.


## V3 ESM Only Release

The version 3 of this module ditches entirely legacy browsers and _nodejs_ with broken loaders, such as `v13.0.0` and `v13.1.0`.

As the code is basically identical, simply stick with version 2 if you have any issue with this one 👋


### How
This package is available in npm so `npm install html-escaper` is all you need to do, using eventually the global flag too.

Once the module is present
```js
var html = require('html-escaper');
import {escape, unescape} from 'html-escaper';

// two basic methods
html.escape('string');
html.unescape('escaped string');
escape('string');
unescape('escaped string');
```


Expand Down
36 changes: 15 additions & 21 deletions cjs/index.js
Expand Up @@ -21,19 +21,27 @@
* THE SOFTWARE.
*/

var replace = ''.replace;
const {replace} = '';

var ca = /[&<>'"]/g;
var es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
// escape
const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
const ca = /[&<>'"]/g;

var esca = {
const esca = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;'
};
var unes = {
const pe = m => esca[m];

const escape = es => replace.call(es, ca, pe);
exports.escape = escape;


// unescape
const unes = {
'&amp;': '&',
'&#38;': '&',
'&lt;': '<',
Expand All @@ -45,21 +53,7 @@ var unes = {
'&quot;': '"',
'&#34;': '"'
};
const cape = m => unes[m];

function escape(es) {
return replace.call(es, ca, pe);
}
exports.escape = escape;

function unescape(un) {
return replace.call(un, es, cape);
}
const unescape = un => replace.call(un, es, cape);
exports.unescape = unescape;

function pe(m) {
return esca[m];
}

function cape(m) {
return unes[m];
}
34 changes: 14 additions & 20 deletions esm/index.js
Expand Up @@ -20,19 +20,26 @@
* THE SOFTWARE.
*/

var replace = ''.replace;
const {replace} = '';

var ca = /[&<>'"]/g;
var es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
// escape
const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
const ca = /[&<>'"]/g;

var esca = {
const esca = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;'
};
var unes = {
const pe = m => esca[m];

export const escape = es => replace.call(es, ca, pe);


// unescape
const unes = {
'&amp;': '&',
'&#38;': '&',
'&lt;': '<',
Expand All @@ -44,19 +51,6 @@ var unes = {
'&quot;': '"',
'&#34;': '"'
};
const cape = m => unes[m];

export function escape(es) {
return replace.call(es, ca, pe);
};

export function unescape(un) {
return replace.call(un, es, cape);
};

function pe(m) {
return esca[m];
}

function cape(m) {
return unes[m];
}
export const unescape = un => replace.call(un, es, cape);
32 changes: 14 additions & 18 deletions index.js
Expand Up @@ -23,19 +23,26 @@ var html = (function (exports) {
* THE SOFTWARE.
*/

var replace = ''.replace;
const {replace} = '';

var ca = /[&<>'"]/g;
var es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
// escape
const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
const ca = /[&<>'"]/g;

var esca = {
const esca = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
"'": '&#39;',
'"': '&quot;'
};
var unes = {
const pe = m => esca[m];

const escape = es => replace.call(es, ca, pe);


// unescape
const unes = {
'&amp;': '&',
'&#38;': '&',
'&lt;': '<',
Expand All @@ -47,20 +54,9 @@ var html = (function (exports) {
'&quot;': '"',
'&#34;': '"'
};
const cape = m => unes[m];

function escape(es) {
return replace.call(es, ca, pe);
}
function unescape(un) {
return replace.call(un, es, cape);
}
function pe(m) {
return esca[m];
}

function cape(m) {
return unes[m];
}
const unescape = un => replace.call(un, es, cape);

exports.escape = escape;
exports.unescape = unescape;
Expand Down
2 changes: 1 addition & 1 deletion min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -14,6 +14,11 @@
"test": "istanbul cover ./test/index.js"
},
"module": "./esm/index.js",
"type": "module",
"exports": {
"import": "./esm/index.js",
"default": "./cjs/index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/WebReflection/html-escaper.git"
Expand All @@ -36,7 +41,7 @@
"ascjs": "^3.1.2",
"coveralls": "^3.0.11",
"istanbul": "^0.4.5",
"rollup": "^2.1.0",
"uglify-js": "^3.8.0"
"rollup": "^2.2.0",
"uglify-es": "^3.3.9"
}
}

0 comments on commit 6963b06

Please sign in to comment.