@excofy/utils 1.0.4 → 1.0.5

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
@@ -359,6 +359,16 @@ function createValidator() {
359
359
  current.pushError(message);
360
360
  return validator;
361
361
  },
362
+ test(validateFn, message) {
363
+ if (shouldSkipValidation()) return validator;
364
+ const isValid = validateFn(current.value, {
365
+ field: String(current.field)
366
+ });
367
+ if (!isValid) {
368
+ current.pushError(message);
369
+ }
370
+ return validator;
371
+ },
362
372
  videoUrl: {
363
373
  youtube(message) {
364
374
  if (shouldSkipValidation()) {
package/dist/index.d.cts CHANGED
@@ -58,6 +58,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
58
58
  url(message: string): /*elided*/ any;
59
59
  uuid(message: string): /*elided*/ any;
60
60
  oneOf: (types: string[], message: string) => /*elided*/ any;
61
+ test(validateFn: (value: TInputValue, context: {
62
+ field: string;
63
+ }) => boolean, message: string): /*elided*/ any;
61
64
  videoUrl: {
62
65
  youtube(message: string): /*elided*/ any;
63
66
  };
@@ -82,6 +85,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
82
85
  url(message: string): /*elided*/ any;
83
86
  uuid(message: string): /*elided*/ any;
84
87
  oneOf: (types: string[], message: string) => /*elided*/ any;
88
+ test(validateFn: (value: TInputValue, context: {
89
+ field: string;
90
+ }) => boolean, message: string): /*elided*/ any;
85
91
  videoUrl: {
86
92
  youtube(message: string): /*elided*/ any;
87
93
  };
package/dist/index.d.ts CHANGED
@@ -58,6 +58,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
58
58
  url(message: string): /*elided*/ any;
59
59
  uuid(message: string): /*elided*/ any;
60
60
  oneOf: (types: string[], message: string) => /*elided*/ any;
61
+ test(validateFn: (value: TInputValue, context: {
62
+ field: string;
63
+ }) => boolean, message: string): /*elided*/ any;
61
64
  videoUrl: {
62
65
  youtube(message: string): /*elided*/ any;
63
66
  };
@@ -82,6 +85,9 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
82
85
  url(message: string): /*elided*/ any;
83
86
  uuid(message: string): /*elided*/ any;
84
87
  oneOf: (types: string[], message: string) => /*elided*/ any;
88
+ test(validateFn: (value: TInputValue, context: {
89
+ field: string;
90
+ }) => boolean, message: string): /*elided*/ any;
85
91
  videoUrl: {
86
92
  youtube(message: string): /*elided*/ any;
87
93
  };
package/dist/index.js CHANGED
@@ -325,6 +325,16 @@ function createValidator() {
325
325
  current.pushError(message);
326
326
  return validator;
327
327
  },
328
+ test(validateFn, message) {
329
+ if (shouldSkipValidation()) return validator;
330
+ const isValid = validateFn(current.value, {
331
+ field: String(current.field)
332
+ });
333
+ if (!isValid) {
334
+ current.pushError(message);
335
+ }
336
+ return validator;
337
+ },
328
338
  videoUrl: {
329
339
  youtube(message) {
330
340
  if (shouldSkipValidation()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excofy/utils",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Biblioteca de utilitários para o Excofy",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -337,6 +337,23 @@ export function createValidator<
337
337
  return validator;
338
338
  },
339
339
 
340
+ test(
341
+ validateFn: (value: TInputValue, context: { field: string }) => boolean,
342
+ message: string
343
+ ) {
344
+ if (shouldSkipValidation()) return validator;
345
+
346
+ const isValid = validateFn(current.value, {
347
+ field: String(current.field),
348
+ });
349
+
350
+ if (!isValid) {
351
+ current.pushError(message);
352
+ }
353
+
354
+ return validator;
355
+ },
356
+
340
357
  videoUrl: {
341
358
  youtube(message: string) {
342
359
  if (shouldSkipValidation()) {