@excofy/utils 2.3.0 → 2.3.2
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 +8 -8
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -8
- package/package.json +1 -1
- package/src/helpers/sanitize.ts +9 -9
- package/src/helpers/validator.ts +3 -7
package/dist/index.cjs
CHANGED
|
@@ -154,11 +154,11 @@ function sanitizeValue(value, allowedTags) {
|
|
|
154
154
|
});
|
|
155
155
|
return filter.process(value);
|
|
156
156
|
}
|
|
157
|
-
function htmlEntityDecode(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
function htmlEntityDecode(str = "") {
|
|
158
|
+
return str.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)).replace(
|
|
159
|
+
/&#x([0-9a-f]+);/gi,
|
|
160
|
+
(_, code) => String.fromCharCode(Number.parseInt(code, 16))
|
|
161
|
+
).replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
// src/helpers/video.ts
|
|
@@ -234,8 +234,6 @@ function createValidator() {
|
|
|
234
234
|
isValidType = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
235
235
|
} else if (type === "file") {
|
|
236
236
|
isValidType = value instanceof File;
|
|
237
|
-
} else if (type === "base64") {
|
|
238
|
-
isValidType = typeof value === "string" && !!value.match(/^data:([A-Za-z-+\/]+);base64,([A-Za-z0-9+/=]+)$/);
|
|
239
237
|
} else if (type === "date") {
|
|
240
238
|
isValidType = typeof value === "string" && !Number.isNaN(new Date(value).getTime());
|
|
241
239
|
} else {
|
|
@@ -259,7 +257,9 @@ function createValidator() {
|
|
|
259
257
|
current.pushError(message);
|
|
260
258
|
return validator;
|
|
261
259
|
}
|
|
262
|
-
const match = value.match(
|
|
260
|
+
const match = value.match(
|
|
261
|
+
/^data:([A-Za-z-+\/]+);(?:charset=utf-8;)?base64,/
|
|
262
|
+
);
|
|
263
263
|
if (!match) {
|
|
264
264
|
current.pushError(message);
|
|
265
265
|
return validator;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,14 +6,14 @@ type AllowedTag = Tag | {
|
|
|
6
6
|
tag: Tag;
|
|
7
7
|
attributes?: Attributes[];
|
|
8
8
|
};
|
|
9
|
-
declare function htmlEntityDecode(
|
|
9
|
+
declare function htmlEntityDecode(str?: string): string;
|
|
10
10
|
|
|
11
11
|
type TMessage = {
|
|
12
12
|
message: string;
|
|
13
13
|
};
|
|
14
14
|
type TValue = string | number | boolean | File | object | null | undefined;
|
|
15
15
|
type TInputValue = TValue;
|
|
16
|
-
type TTypes = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file' | '
|
|
16
|
+
type TTypes = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file' | 'date';
|
|
17
17
|
interface IInputErrors {
|
|
18
18
|
[key: string]: TMessage[] | IInputErrors[];
|
|
19
19
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,14 +6,14 @@ type AllowedTag = Tag | {
|
|
|
6
6
|
tag: Tag;
|
|
7
7
|
attributes?: Attributes[];
|
|
8
8
|
};
|
|
9
|
-
declare function htmlEntityDecode(
|
|
9
|
+
declare function htmlEntityDecode(str?: string): string;
|
|
10
10
|
|
|
11
11
|
type TMessage = {
|
|
12
12
|
message: string;
|
|
13
13
|
};
|
|
14
14
|
type TValue = string | number | boolean | File | object | null | undefined;
|
|
15
15
|
type TInputValue = TValue;
|
|
16
|
-
type TTypes = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file' | '
|
|
16
|
+
type TTypes = 'string' | 'number' | 'boolean' | 'object' | 'array' | 'file' | 'date';
|
|
17
17
|
interface IInputErrors {
|
|
18
18
|
[key: string]: TMessage[] | IInputErrors[];
|
|
19
19
|
}
|
package/dist/index.js
CHANGED
|
@@ -116,11 +116,11 @@ function sanitizeValue(value, allowedTags) {
|
|
|
116
116
|
});
|
|
117
117
|
return filter.process(value);
|
|
118
118
|
}
|
|
119
|
-
function htmlEntityDecode(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
function htmlEntityDecode(str = "") {
|
|
120
|
+
return str.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code)).replace(
|
|
121
|
+
/&#x([0-9a-f]+);/gi,
|
|
122
|
+
(_, code) => String.fromCharCode(Number.parseInt(code, 16))
|
|
123
|
+
).replace(/&/g, "&").replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// src/helpers/video.ts
|
|
@@ -196,8 +196,6 @@ function createValidator() {
|
|
|
196
196
|
isValidType = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
197
197
|
} else if (type === "file") {
|
|
198
198
|
isValidType = value instanceof File;
|
|
199
|
-
} else if (type === "base64") {
|
|
200
|
-
isValidType = typeof value === "string" && !!value.match(/^data:([A-Za-z-+\/]+);base64,([A-Za-z0-9+/=]+)$/);
|
|
201
199
|
} else if (type === "date") {
|
|
202
200
|
isValidType = typeof value === "string" && !Number.isNaN(new Date(value).getTime());
|
|
203
201
|
} else {
|
|
@@ -221,7 +219,9 @@ function createValidator() {
|
|
|
221
219
|
current.pushError(message);
|
|
222
220
|
return validator;
|
|
223
221
|
}
|
|
224
|
-
const match = value.match(
|
|
222
|
+
const match = value.match(
|
|
223
|
+
/^data:([A-Za-z-+\/]+);(?:charset=utf-8;)?base64,/
|
|
224
|
+
);
|
|
225
225
|
if (!match) {
|
|
226
226
|
current.pushError(message);
|
|
227
227
|
return validator;
|
package/package.json
CHANGED
package/src/helpers/sanitize.ts
CHANGED
|
@@ -101,15 +101,15 @@ export function sanitizeValue(
|
|
|
101
101
|
return filter.process(value);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
export function htmlEntityDecode(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.replace(/>/g, '>')
|
|
111
|
-
.replace(/</g, '<')
|
|
104
|
+
export function htmlEntityDecode(str = ''): string {
|
|
105
|
+
return str
|
|
106
|
+
.replace(/&#(\d+);/g, (_, code) => String.fromCharCode(code))
|
|
107
|
+
.replace(/&#x([0-9a-f]+);/gi, (_, code) =>
|
|
108
|
+
String.fromCharCode(Number.parseInt(code, 16))
|
|
109
|
+
)
|
|
112
110
|
.replace(/&/g, '&')
|
|
113
111
|
.replace(/"/g, '"')
|
|
114
|
-
.replace(
|
|
112
|
+
.replace(/'/g, "'")
|
|
113
|
+
.replace(/</g, '<')
|
|
114
|
+
.replace(/>/g, '>');
|
|
115
115
|
}
|
package/src/helpers/validator.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isValidCNPJ, isValidCPF } from './document';
|
|
2
|
-
import { fileUtils } from './file';
|
|
3
2
|
import { sanitizeValue, type AllowedTag } from './sanitize';
|
|
4
3
|
import { video } from './video';
|
|
5
4
|
|
|
@@ -13,7 +12,6 @@ type TTypes =
|
|
|
13
12
|
| 'object'
|
|
14
13
|
| 'array'
|
|
15
14
|
| 'file'
|
|
16
|
-
| 'base64'
|
|
17
15
|
| 'date';
|
|
18
16
|
|
|
19
17
|
interface IInputErrors {
|
|
@@ -143,10 +141,6 @@ export function createValidator<
|
|
|
143
141
|
typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
144
142
|
} else if (type === 'file') {
|
|
145
143
|
isValidType = value instanceof File;
|
|
146
|
-
} else if (type === 'base64') {
|
|
147
|
-
isValidType =
|
|
148
|
-
typeof value === 'string' &&
|
|
149
|
-
!!value.match(/^data:([A-Za-z-+\/]+);base64,([A-Za-z0-9+/=]+)$/);
|
|
150
144
|
} else if (type === 'date') {
|
|
151
145
|
isValidType =
|
|
152
146
|
typeof value === 'string' && !Number.isNaN(new Date(value).getTime());
|
|
@@ -187,7 +181,9 @@ export function createValidator<
|
|
|
187
181
|
return validator;
|
|
188
182
|
}
|
|
189
183
|
|
|
190
|
-
const match = value.match(
|
|
184
|
+
const match = value.match(
|
|
185
|
+
/^data:([A-Za-z-+\/]+);(?:charset=utf-8;)?base64,/
|
|
186
|
+
);
|
|
191
187
|
if (!match) {
|
|
192
188
|
current.pushError(message);
|
|
193
189
|
return validator;
|