@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 CHANGED
@@ -154,11 +154,14 @@ function sanitizeValue(value, allowedTags) {
154
154
  });
155
155
  return filter.process(value);
156
156
  }
157
- function htmlEntityDecode(value) {
158
- if (!value) {
157
+ function htmlEntityDecode(str = "") {
158
+ if (!str || typeof str !== "string" || str.length === 0) {
159
159
  return "";
160
160
  }
161
- return value.replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'");
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(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
162
165
  }
163
166
 
164
167
  // src/helpers/video.ts
package/dist/index.d.cts CHANGED
@@ -6,7 +6,7 @@ type AllowedTag = Tag | {
6
6
  tag: Tag;
7
7
  attributes?: Attributes[];
8
8
  };
9
- declare function htmlEntityDecode(value?: string): string;
9
+ declare function htmlEntityDecode(str?: string): string;
10
10
 
11
11
  type TMessage = {
12
12
  message: string;
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ type AllowedTag = Tag | {
6
6
  tag: Tag;
7
7
  attributes?: Attributes[];
8
8
  };
9
- declare function htmlEntityDecode(value?: string): string;
9
+ declare function htmlEntityDecode(str?: string): string;
10
10
 
11
11
  type TMessage = {
12
12
  message: string;
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(value) {
120
- if (!value) {
119
+ function htmlEntityDecode(str = "") {
120
+ if (!str || typeof str !== "string" || str.length === 0) {
121
121
  return "";
122
122
  }
123
- return value.replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&#39;/g, "'");
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(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">");
124
127
  }
125
128
 
126
129
  // src/helpers/video.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excofy/utils",
3
- "version": "2.3.1",
3
+ "version": "2.3.3",
4
4
  "description": "Biblioteca de utilitários para o Excofy",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -101,15 +101,19 @@ export function sanitizeValue(
101
101
  return filter.process(value);
102
102
  }
103
103
 
104
- export function htmlEntityDecode(value?: string): string {
105
- if (!value) {
104
+ export function htmlEntityDecode(str = ''): string {
105
+ if (!str || typeof str !== 'string' || str.length === 0) {
106
106
  return '';
107
107
  }
108
108
 
109
- return value
110
- .replace(/&gt;/g, '>')
111
- .replace(/&lt;/g, '<')
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(/&amp;/g, '&')
113
115
  .replace(/&quot;/g, '"')
114
- .replace(/&#39;/g, "'");
116
+ .replace(/&apos;/g, "'")
117
+ .replace(/&lt;/g, '<')
118
+ .replace(/&gt;/g, '>');
115
119
  }