@excofy/utils 1.0.5 → 1.0.6
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 +13 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -0
- package/package.json +1 -1
- package/src/helpers/validator.ts +27 -0
package/dist/index.cjs
CHANGED
|
@@ -313,6 +313,19 @@ function createValidator() {
|
|
|
313
313
|
}
|
|
314
314
|
return validator;
|
|
315
315
|
},
|
|
316
|
+
sanitizePreservingNewlines() {
|
|
317
|
+
if (shouldSkipValidation()) {
|
|
318
|
+
return validator;
|
|
319
|
+
}
|
|
320
|
+
if (typeof current.value === "string") {
|
|
321
|
+
const withBrs = current.value.replace(/\n/g, "<br>");
|
|
322
|
+
const sanitized = sanitizeValue(withBrs, ["br"]);
|
|
323
|
+
const cleaned = sanitized.trim().replace(/\s{2,}/g, " ").replace(/<br>/g, "\n");
|
|
324
|
+
current.value = cleaned;
|
|
325
|
+
current.inputs[current.field] = cleaned;
|
|
326
|
+
}
|
|
327
|
+
return validator;
|
|
328
|
+
},
|
|
316
329
|
sanitizeHTML(tags) {
|
|
317
330
|
if (shouldSkipValidation()) {
|
|
318
331
|
return validator;
|
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,7 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
|
|
|
54
54
|
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
55
55
|
slug(message: string): /*elided*/ any;
|
|
56
56
|
sanitize(): /*elided*/ any;
|
|
57
|
+
sanitizePreservingNewlines(): /*elided*/ any;
|
|
57
58
|
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
58
59
|
url(message: string): /*elided*/ any;
|
|
59
60
|
uuid(message: string): /*elided*/ any;
|
|
@@ -81,6 +82,7 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
|
|
|
81
82
|
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
82
83
|
slug(message: string): /*elided*/ any;
|
|
83
84
|
sanitize(): /*elided*/ any;
|
|
85
|
+
sanitizePreservingNewlines(): /*elided*/ any;
|
|
84
86
|
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
85
87
|
url(message: string): /*elided*/ any;
|
|
86
88
|
uuid(message: string): /*elided*/ any;
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
|
|
|
54
54
|
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
55
55
|
slug(message: string): /*elided*/ any;
|
|
56
56
|
sanitize(): /*elided*/ any;
|
|
57
|
+
sanitizePreservingNewlines(): /*elided*/ any;
|
|
57
58
|
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
58
59
|
url(message: string): /*elided*/ any;
|
|
59
60
|
uuid(message: string): /*elided*/ any;
|
|
@@ -81,6 +82,7 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
|
|
|
81
82
|
transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
|
|
82
83
|
slug(message: string): /*elided*/ any;
|
|
83
84
|
sanitize(): /*elided*/ any;
|
|
85
|
+
sanitizePreservingNewlines(): /*elided*/ any;
|
|
84
86
|
sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
|
|
85
87
|
url(message: string): /*elided*/ any;
|
|
86
88
|
uuid(message: string): /*elided*/ any;
|
package/dist/index.js
CHANGED
|
@@ -279,6 +279,19 @@ function createValidator() {
|
|
|
279
279
|
}
|
|
280
280
|
return validator;
|
|
281
281
|
},
|
|
282
|
+
sanitizePreservingNewlines() {
|
|
283
|
+
if (shouldSkipValidation()) {
|
|
284
|
+
return validator;
|
|
285
|
+
}
|
|
286
|
+
if (typeof current.value === "string") {
|
|
287
|
+
const withBrs = current.value.replace(/\n/g, "<br>");
|
|
288
|
+
const sanitized = sanitizeValue(withBrs, ["br"]);
|
|
289
|
+
const cleaned = sanitized.trim().replace(/\s{2,}/g, " ").replace(/<br>/g, "\n");
|
|
290
|
+
current.value = cleaned;
|
|
291
|
+
current.inputs[current.field] = cleaned;
|
|
292
|
+
}
|
|
293
|
+
return validator;
|
|
294
|
+
},
|
|
282
295
|
sanitizeHTML(tags) {
|
|
283
296
|
if (shouldSkipValidation()) {
|
|
284
297
|
return validator;
|
package/package.json
CHANGED
package/src/helpers/validator.ts
CHANGED
|
@@ -264,6 +264,7 @@ export function createValidator<
|
|
|
264
264
|
}
|
|
265
265
|
return validator;
|
|
266
266
|
},
|
|
267
|
+
|
|
267
268
|
sanitize() {
|
|
268
269
|
if (shouldSkipValidation()) {
|
|
269
270
|
return validator;
|
|
@@ -279,6 +280,32 @@ export function createValidator<
|
|
|
279
280
|
return validator;
|
|
280
281
|
},
|
|
281
282
|
|
|
283
|
+
sanitizePreservingNewlines() {
|
|
284
|
+
if (shouldSkipValidation()) {
|
|
285
|
+
return validator;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (typeof current.value === 'string') {
|
|
289
|
+
// Passo 1: substitui quebras de linha por <br> para preservar no HTML
|
|
290
|
+
const withBrs = current.value.replace(/\n/g, '<br>');
|
|
291
|
+
|
|
292
|
+
// Passo 2: sanitiza permitindo a tag 'br'
|
|
293
|
+
const sanitized = sanitizeValue(withBrs, ['br']);
|
|
294
|
+
|
|
295
|
+
// Passo 3: opcional, limpa espaços extras, mas sem remover \n, porque já substituímos
|
|
296
|
+
const cleaned = sanitized
|
|
297
|
+
.trim()
|
|
298
|
+
.replace(/\s{2,}/g, ' ')
|
|
299
|
+
.replace(/<br>/g, '\n');
|
|
300
|
+
|
|
301
|
+
// Atualiza os valores
|
|
302
|
+
current.value = cleaned;
|
|
303
|
+
current.inputs[current.field] = cleaned as TRaw[keyof TRaw];
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return validator;
|
|
307
|
+
},
|
|
308
|
+
|
|
282
309
|
sanitizeHTML(tags?: AllowedTag[]) {
|
|
283
310
|
if (shouldSkipValidation()) {
|
|
284
311
|
return validator;
|