@web-widget/purify 1.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/purify.d.ts +16 -0
- package/dist/purify.js +57 -0
- package/package.json +49 -0
package/README.md
ADDED
package/dist/purify.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* escape-html
|
|
3
|
+
* https://github.com/component/escape-html/blob/master/index.js
|
|
4
|
+
* Copyright(c) 2012-2013 TJ Holowaychuk
|
|
5
|
+
* Copyright(c) 2015 Andreas Lubbe
|
|
6
|
+
* Copyright(c) 2015 Tiancheng "Timothy" Gu
|
|
7
|
+
* MIT Licensed
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Escape special characters in the given string of text.
|
|
11
|
+
*/
|
|
12
|
+
declare function escapeHtml(string: string): string;
|
|
13
|
+
|
|
14
|
+
declare function escapeJson(str: string): string;
|
|
15
|
+
|
|
16
|
+
export { escapeHtml, escapeJson };
|
package/dist/purify.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/html.ts
|
|
2
|
+
var matchHtmlRegExp = /["'&<>]/;
|
|
3
|
+
function escapeHtml(string) {
|
|
4
|
+
const str = "" + string;
|
|
5
|
+
const match = matchHtmlRegExp.exec(str);
|
|
6
|
+
if (!match) {
|
|
7
|
+
return str;
|
|
8
|
+
}
|
|
9
|
+
let escape;
|
|
10
|
+
let html = "";
|
|
11
|
+
let index = 0;
|
|
12
|
+
let lastIndex = 0;
|
|
13
|
+
for (index = match.index; index < str.length; index++) {
|
|
14
|
+
switch (str.charCodeAt(index)) {
|
|
15
|
+
case 34:
|
|
16
|
+
escape = """;
|
|
17
|
+
break;
|
|
18
|
+
case 38:
|
|
19
|
+
escape = "&";
|
|
20
|
+
break;
|
|
21
|
+
case 39:
|
|
22
|
+
escape = "'";
|
|
23
|
+
break;
|
|
24
|
+
case 60:
|
|
25
|
+
escape = "<";
|
|
26
|
+
break;
|
|
27
|
+
case 62:
|
|
28
|
+
escape = ">";
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (lastIndex !== index) {
|
|
34
|
+
html += str.substring(lastIndex, index);
|
|
35
|
+
}
|
|
36
|
+
lastIndex = index + 1;
|
|
37
|
+
html += escape;
|
|
38
|
+
}
|
|
39
|
+
return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/json.ts
|
|
43
|
+
var ESCAPE_LOOKUP = {
|
|
44
|
+
"&": "\\u0026",
|
|
45
|
+
">": "\\u003e",
|
|
46
|
+
"<": "\\u003c",
|
|
47
|
+
"\u2028": "\\u2028",
|
|
48
|
+
"\u2029": "\\u2029"
|
|
49
|
+
};
|
|
50
|
+
var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
51
|
+
function escapeJson(str) {
|
|
52
|
+
return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
escapeHtml,
|
|
56
|
+
escapeJson
|
|
57
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@web-widget/purify",
|
|
3
|
+
"description": "HTML purify",
|
|
4
|
+
"version": "1.35.0",
|
|
5
|
+
"homepage": "https://github.com/web-widget/web-widget#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/web-widget/web-widget.git",
|
|
9
|
+
"directory": "packages/purify"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/web-widget/web-widget/issues"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"dependencies": {},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@jest/globals": "^29.7.0",
|
|
18
|
+
"@types/jest": "^29.5.12",
|
|
19
|
+
"jest": "^29.7.0",
|
|
20
|
+
"jest-environment-miniflare": "^2.14.2",
|
|
21
|
+
"miniflare": "^3.20240806.0",
|
|
22
|
+
"ts-jest": "29.2.1",
|
|
23
|
+
"tsup": "^8.2.4",
|
|
24
|
+
"typescript": "^5.5.4"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/purify.d.ts",
|
|
29
|
+
"default": "./dist/purify.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"type": "module",
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "pnpm exec tsup",
|
|
41
|
+
"clean:build": "rm -rf dist",
|
|
42
|
+
"clean:node": "rm -rf node_modules",
|
|
43
|
+
"dev": "pnpm exec tsup --watch",
|
|
44
|
+
"lint": "eslint src",
|
|
45
|
+
"prebuild": "pnpm run clean:build",
|
|
46
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest --passWithNoTests",
|
|
47
|
+
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules pnpm exec jest --coverage"
|
|
48
|
+
}
|
|
49
|
+
}
|