@excofy/utils 2.3.1 → 2.3.3
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/dist/index.cjs +6 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -3
- package/package.json +1 -1
- package/src/helpers/sanitize.ts +10 -6
package/dist/index.cjs
CHANGED
|
@@ -154,11 +154,14 @@ function sanitizeValue(value, allowedTags) {
|
|
|
154
154
|
});
|
|
155
155
|
return filter.process(value);
|
|
156
156
|
}
|
|
157
|
-
function htmlEntityDecode(
|
|
158
|
-
if (!
|
|
157
|
+
function htmlEntityDecode(str = "") {
|
|
158
|
+
if (!str || typeof str !== "string" || str.length === 0) {
|
|
159
159
|
return "";
|
|
160
160
|
}
|
|
161
|
-
return
|
|
161
|
+
return str.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)).replace(
|
|
162
|
+
/&#x([0-9a-f]+);/gi,
|
|
163
|
+
(_, code) => String.fromCharCode(Number.parseInt(code, 16))
|
|
164
|
+
).replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
162
165
|
}
|
|
163
166
|
|
|
164
167
|
// src/helpers/video.ts
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -116,11 +116,14 @@ function sanitizeValue(value, allowedTags) {
|
|
|
116
116
|
});
|
|
117
117
|
return filter.process(value);
|
|
118
118
|
}
|
|
119
|
-
function htmlEntityDecode(
|
|
120
|
-
if (!
|
|
119
|
+
function htmlEntityDecode(str = "") {
|
|
120
|
+
if (!str || typeof str !== "string" || str.length === 0) {
|
|
121
121
|
return "";
|
|
122
122
|
}
|
|
123
|
-
return
|
|
123
|
+
return str.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)).replace(
|
|
124
|
+
/&#x([0-9a-f]+);/gi,
|
|
125
|
+
(_, code) => String.fromCharCode(Number.parseInt(code, 16))
|
|
126
|
+
).replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
// src/helpers/video.ts
|
package/package.json
CHANGED
package/src/helpers/sanitize.ts
CHANGED
|
@@ -101,15 +101,19 @@ export function sanitizeValue(
|
|
|
101
101
|
return filter.process(value);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export function htmlEntityDecode(
|
|
105
|
-
if (!
|
|
104
|
+
export function htmlEntityDecode(str = ''): string {
|
|
105
|
+
if (!str || typeof str !== 'string' || str.length === 0) {
|
|
106
106
|
return '';
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
return
|
|
110
|
-
.replace(
|
|
111
|
-
.replace(
|
|
109
|
+
return str
|
|
110
|
+
.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code))
|
|
111
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, code) =>
|
|
112
|
+
String.fromCharCode(Number.parseInt(code, 16))
|
|
113
|
+
)
|
|
112
114
|
.replace(/&/g, '&')
|
|
113
115
|
.replace(/"/g, '"')
|
|
114
|
-
.replace(
|
|
116
|
+
.replace(/'/g, "'")
|
|
117
|
+
.replace(/</g, '<')
|
|
118
|
+
.replace(/>/g, '>');
|
|
115
119
|
}
|