@excofy/utils 1.0.6 → 1.0.7

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,6 +154,13 @@ function createValidator() {
154
154
  isNotRequired() {
155
155
  current.required = false;
156
156
  return validatorType;
157
+ },
158
+ conditionallyRequired(isRequired, message) {
159
+ current.required = isRequired;
160
+ if (isRequired && (current.value === void 0 || current.value === null || current.value === "")) {
161
+ current.pushError(message);
162
+ }
163
+ return validatorType;
157
164
  }
158
165
  };
159
166
  const validatorType = {
package/dist/index.d.cts CHANGED
@@ -98,6 +98,34 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
98
98
  asStringArray(message: string): /*elided*/ any;
99
99
  };
100
100
  };
101
+ conditionallyRequired(isRequired: boolean, message: string): {
102
+ type(type: TTypes, message: string): {
103
+ each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
104
+ email: (message: string) => /*elided*/ any;
105
+ fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
106
+ fileType: (validTypes: string[], message: string) => /*elided*/ any;
107
+ length(length: number, message: string): /*elided*/ any;
108
+ min(min: number, message: string): /*elided*/ any;
109
+ max(max: number, message: string): /*elided*/ any;
110
+ transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
111
+ slug(message: string): /*elided*/ any;
112
+ sanitize(): /*elided*/ any;
113
+ sanitizePreservingNewlines(): /*elided*/ any;
114
+ sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
115
+ url(message: string): /*elided*/ any;
116
+ uuid(message: string): /*elided*/ any;
117
+ oneOf: (types: string[], message: string) => /*elided*/ any;
118
+ test(validateFn: (value: TInputValue, context: {
119
+ field: string;
120
+ }) => boolean, message: string): /*elided*/ any;
121
+ videoUrl: {
122
+ youtube(message: string): /*elided*/ any;
123
+ };
124
+ asNumber(message: string): /*elided*/ any;
125
+ asBoolean(message: string): /*elided*/ any;
126
+ asStringArray(message: string): /*elided*/ any;
127
+ };
128
+ };
101
129
  };
102
130
  };
103
131
 
package/dist/index.d.ts CHANGED
@@ -98,6 +98,34 @@ declare function createValidator<TRaw extends Record<string, TInputValue>, TPars
98
98
  asStringArray(message: string): /*elided*/ any;
99
99
  };
100
100
  };
101
+ conditionallyRequired(isRequired: boolean, message: string): {
102
+ type(type: TTypes, message: string): {
103
+ each(callback: <U extends Record<string, TInputValue>>(item: U, index: number, subValidator: ReturnType<typeof createValidator<U>>) => void): /*elided*/ any;
104
+ email: (message: string) => /*elided*/ any;
105
+ fileMaxSize: (maxSize: number, message: string) => /*elided*/ any;
106
+ fileType: (validTypes: string[], message: string) => /*elided*/ any;
107
+ length(length: number, message: string): /*elided*/ any;
108
+ min(min: number, message: string): /*elided*/ any;
109
+ max(max: number, message: string): /*elided*/ any;
110
+ transform<U>(fn: (value: TInputValue) => U): /*elided*/ any;
111
+ slug(message: string): /*elided*/ any;
112
+ sanitize(): /*elided*/ any;
113
+ sanitizePreservingNewlines(): /*elided*/ any;
114
+ sanitizeHTML(tags?: AllowedTag[]): /*elided*/ any;
115
+ url(message: string): /*elided*/ any;
116
+ uuid(message: string): /*elided*/ any;
117
+ oneOf: (types: string[], message: string) => /*elided*/ any;
118
+ test(validateFn: (value: TInputValue, context: {
119
+ field: string;
120
+ }) => boolean, message: string): /*elided*/ any;
121
+ videoUrl: {
122
+ youtube(message: string): /*elided*/ any;
123
+ };
124
+ asNumber(message: string): /*elided*/ any;
125
+ asBoolean(message: string): /*elided*/ any;
126
+ asStringArray(message: string): /*elided*/ any;
127
+ };
128
+ };
101
129
  };
102
130
  };
103
131
 
package/dist/index.js CHANGED
@@ -120,6 +120,13 @@ function createValidator() {
120
120
  isNotRequired() {
121
121
  current.required = false;
122
122
  return validatorType;
123
+ },
124
+ conditionallyRequired(isRequired, message) {
125
+ current.required = isRequired;
126
+ if (isRequired && (current.value === void 0 || current.value === null || current.value === "")) {
127
+ current.pushError(message);
128
+ }
129
+ return validatorType;
123
130
  }
124
131
  };
125
132
  const validatorType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@excofy/utils",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Biblioteca de utilitários para o Excofy",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -68,6 +68,18 @@ export function createValidator<
68
68
  current.required = false;
69
69
  return validatorType;
70
70
  },
71
+ conditionallyRequired(isRequired: boolean, message: string) {
72
+ current.required = isRequired;
73
+ if (
74
+ isRequired &&
75
+ (current.value === undefined ||
76
+ current.value === null ||
77
+ current.value === '')
78
+ ) {
79
+ current.pushError(message);
80
+ }
81
+ return validatorType;
82
+ },
71
83
  };
72
84
 
73
85
  const validatorType = {