@dolanske/v-valid 2.1.1 → 3.0.0

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/v-valid.d.ts CHANGED
@@ -1,76 +1,38 @@
1
1
  import { ComputedRef } from 'vue-demi';
2
+ import { MaybeRef } from 'vue-demi';
2
3
  import { Ref } from 'vue-demi';
3
4
  import { UnwrapRef } from 'vue-demi';
4
5
 
5
6
  /**
6
- * @rule Value must pass every provided check
7
- * @param rules Single or multiple validation rules
7
+ * @Rule Input must be a date after or at the provided rule
8
+ * @param min Minimum allowed value
8
9
  */
9
- export declare function $and(...rules: ValidationRule[]): ValidationRule;
10
+ export declare function after(min: MaybeRef<Date>): ValidationRule;
10
11
 
11
- export declare namespace $and {
12
+ export declare namespace after {
12
13
  var skip: (..._args: any[]) => ValidationRule;
13
14
  }
14
15
 
15
16
  /**
16
- * @rule Value must fail the check or list of all provided checks
17
+ * @rule Value must pass every provided check
17
18
  * @param rules Single or multiple validation rules
18
19
  */
19
- export declare function $not(...rules: ValidationRule[]): ValidationRule;
20
+ export declare function and(...rules: ValidationRule[]): ValidationRule;
20
21
 
21
- export declare namespace $not {
22
- var skip: ValidationRule;
22
+ export declare namespace and {
23
+ var skip: (..._args: any[]) => ValidationRule;
23
24
  }
24
25
 
25
26
  /**
26
- * @rule Value must pass at least one of the provided checks
27
- * @param rules Single or multiple validation rules
27
+ * @Rule Input must be a date before or at the provided rule
28
+ * @param max maximum allowed value
28
29
  */
29
- export declare function $or(...rules: ValidationRule[]): ValidationRule;
30
+ export declare function before(max: MaybeRef<Date>): ValidationRule;
30
31
 
31
- export declare namespace $or {
32
+ export declare namespace before {
32
33
  var skip: (..._args: any[]) => ValidationRule;
33
34
  }
34
35
 
35
- /**
36
- * Shorthand for calling `rule(...args).validate(value)`
37
- *
38
- * @Rule Execute validation against a provided value outside of the validation
39
- * scope. This helper can be also used within `validateIf` and `validateIfNot`
40
- *
41
- * @param rule Validation rule
42
- * @param value Value to validate
43
- * @returns Wether the provided value passes the provided check
44
- */
45
- export declare function $test(rule: ValidationRule, value: any): Promise<boolean> | boolean;
46
-
47
- /**
48
- * @Rule Perform validation if provided condition is met
49
- * @param condition Boolean or function returning boolean
50
- * @param rule Validation rule
51
- */
52
- export declare function $validateIf(condition: boolean | (() => boolean) | Ref<boolean> | Promise<boolean>, rule: ValidationRule): ValidationRule | Promise<ValidationRule>;
53
-
54
- /**
55
- * @Rule Perform validation if provided condition is not met
56
- * @param condition Boolean or function returning boolean
57
- * @param rule Validation rule
58
- */
59
- export declare function $validateIfNot(condition: boolean | (() => boolean) | Ref<boolean> | Promise<boolean>, rule: ValidationRule): ValidationRule | Promise<ValidationRule>;
60
-
61
- /**
62
- *
63
- * Helper method which adds custom message to any validation.
64
- *
65
- * ```ts
66
- * minLength: withLabel("Too short!", minLength(10))
67
- * ```
68
- *
69
- * @param message Custom message to display in the returned error
70
- * @param validator Validation rule
71
- */
72
- export declare function $withLabel(message: string | Label, validator: ValidationRule): ValidationRule;
73
-
74
36
  /**
75
37
  * @Rule Checks if value is between the provided range
76
38
  * @param min Minimum value
@@ -163,54 +125,6 @@ declare type FixArr<T> = T extends readonly any[] ? Omit<T, Exclude<keyof any[],
163
125
  */
164
126
  export declare const hasSpecialChars: ValidationRuleObject;
165
127
 
166
- /**
167
- * @Rule Checkes wether value is an Array
168
- * @param value Input value
169
- */
170
- export declare const isArr: Type['arr'];
171
-
172
- /**
173
- * @Rule Checkes wether value is a valid Date object
174
- * @param value Input value
175
- */
176
- export declare const isDate: Type['date'];
177
-
178
- /**
179
- * @Rule Checkes wether value is a Map
180
- * @param value Input value
181
- */
182
- export declare const isMap: Type['map'];
183
-
184
- /**
185
- * @Rule Checkes wether value is a number
186
- * @param value Input value
187
- */
188
- export declare const isNum: Type['num'];
189
-
190
- /**
191
- * @Rule Checkes wether value is an Object
192
- * @param value Input value
193
- */
194
- export declare const isObj: Type['obj'];
195
-
196
- /**
197
- * @Rule Checkes wether value is a Set
198
- * @param value Input value
199
- */
200
- export declare const isSet: Type['set'];
201
-
202
- /**
203
- * @Rule Checkes wether value is a string
204
- * @param value Input value
205
- */
206
- export declare const isStr: Type['str'];
207
-
208
- /**
209
- * @Rule Checkes wether value is a Symbol
210
- * @param value Input value
211
- */
212
- export declare const isSymbol: Type['symbol'];
213
-
214
128
  declare type Label = (value: any, args?: Record<string, unknown>) => string;
215
129
 
216
130
  /**
@@ -243,16 +157,6 @@ export declare namespace maxLenNoSpace {
243
157
  var skip: (..._args: any[]) => ValidationRule;
244
158
  }
245
159
 
246
- /**
247
- * @Rule Input must be a number or a date which satisfies the maximum provided value.
248
- * @param max maximum allowed value
249
- */
250
- export declare function maxValue(max: number | Date | Ref<number | Date>): ValidationRule;
251
-
252
- export declare namespace maxValue {
253
- var skip: (..._args: any[]) => ValidationRule;
254
- }
255
-
256
160
  /**
257
161
  * @Rule Input must be equal or greater than the provided amount
258
162
  * @param min Minimum allowed length the input must satisfy
@@ -274,12 +178,22 @@ export declare namespace minLenNoSpace {
274
178
  }
275
179
 
276
180
  /**
277
- * @Rule Input must be a number or a date which satisfies the minimum provided value.
278
- * @param min Minimum allowed value
181
+ * @rule Value must fail the check or list of all provided checks
182
+ * @param rules Single or multiple validation rules
279
183
  */
280
- export declare function minValue(min: number | Date | Ref<number | Date>): ValidationRule;
184
+ export declare function not(...rules: ValidationRule[]): ValidationRule;
281
185
 
282
- export declare namespace minValue {
186
+ export declare namespace not {
187
+ var skip: ValidationRule;
188
+ }
189
+
190
+ /**
191
+ * @rule Value must pass at least one of the provided checks
192
+ * @param rules Single or multiple validation rules
193
+ */
194
+ export declare function or(...rules: ValidationRule[]): ValidationRule;
195
+
196
+ export declare namespace or {
283
197
  var skip: (..._args: any[]) => ValidationRule;
284
198
  }
285
199
 
@@ -328,19 +242,6 @@ export declare namespace startsWith {
328
242
  var skip: (..._args: any[]) => ValidationRule;
329
243
  }
330
244
 
331
- declare interface Type {
332
- str: ValidationRuleObject;
333
- num: ValidationRuleObject;
334
- arr: ValidationRuleObject;
335
- obj: ValidationRuleObject;
336
- set: ValidationRuleObject;
337
- map: ValidationRuleObject;
338
- date: ValidationRuleObject;
339
- symbol: ValidationRuleObject;
340
- }
341
-
342
- export declare const type: Type;
343
-
344
245
  /**
345
246
  * @Rule Input must be a valid URL
346
247
  */
@@ -367,43 +268,92 @@ export declare function useValidation<F extends Record<string, any>, R extends P
367
268
  pending: Ref<boolean>;
368
269
  };
369
270
 
271
+ /**
272
+ * @Rule Perform validation if provided condition is met
273
+ * @param condition Boolean or function returning boolean
274
+ * @param rule Validation rule
275
+ */
276
+ export declare function validateIf(condition: boolean | (() => boolean) | Ref<boolean> | Promise<boolean>, rule: ValidationRule): ValidationRule | Promise<ValidationRule>;
277
+
278
+ /**
279
+ * @Rule Perform validation if provided condition is not met
280
+ * @param condition Boolean or function returning boolean
281
+ * @param rule Validation rule
282
+ */
283
+ export declare function validateIfNot(condition: boolean | (() => boolean) | Ref<boolean> | Promise<boolean>, rule: ValidationRule): ValidationRule | Promise<ValidationRule>;
284
+
370
285
  export declare interface ValidationError {
286
+ /**
287
+ * Form object property name
288
+ */
371
289
  id: string | null;
290
+ /**
291
+ * Received value
292
+ */
372
293
  value: any;
294
+ /**
295
+ * Status
296
+ */
373
297
  invalid: boolean;
298
+ /**
299
+ * Errors object where the key is the name of the rule and the value is the error message
300
+ */
374
301
  errors: Record<string, string>;
302
+ /**
303
+ * Flat array of error messages so it can be easily consumed by UI libraries
304
+ */
305
+ messages: string[];
375
306
  }
376
307
 
377
- declare interface ValidationOptions {
308
+ export declare interface ValidationOptions {
309
+ /**
310
+ * Performs validation whenever the form object updates
311
+ */
378
312
  proactive?: boolean;
313
+ /**
314
+ * Clears errors on new input
315
+ */
379
316
  autoclear?: boolean;
380
317
  }
381
318
 
382
- declare interface ValidationRule {
319
+ export declare interface ValidationRule {
383
320
  __skip: boolean;
384
321
  validate: (arg: any) => Promise<boolean> | boolean;
385
322
  label: Label;
386
323
  name: string;
387
324
  }
388
325
 
389
- declare interface ValidationRuleObject extends ValidationRule {
326
+ export declare interface ValidationRuleObject extends ValidationRule {
390
327
  skip: () => void;
391
328
  }
392
329
 
330
+ /**
331
+ *
332
+ * Helper method which adds custom message to any validation.
333
+ *
334
+ * ```ts
335
+ * minLength: withLabel("Too short!", minLength(10))
336
+ * ```
337
+ *
338
+ * @param message Custom message to display in the returned error
339
+ * @param validator Validation rule
340
+ */
341
+ export declare function withLabel(message: string | Label, validator: ValidationRule): ValidationRule;
342
+
393
343
  export { }
394
344
 
395
345
 
396
- declare namespace $and {
397
- var skip: (..._args: any[]) => ValidationRule;
346
+ declare namespace not {
347
+ var skip: ValidationRule;
398
348
  }
399
349
 
400
350
 
401
- declare namespace $not {
402
- var skip: ValidationRule;
351
+ declare namespace and {
352
+ var skip: (..._args: any[]) => ValidationRule;
403
353
  }
404
354
 
405
355
 
406
- declare namespace $or {
356
+ declare namespace or {
407
357
  var skip: (..._args: any[]) => ValidationRule;
408
358
  }
409
359
 
@@ -413,32 +363,32 @@ declare namespace minLength {
413
363
  }
414
364
 
415
365
 
416
- declare namespace maxLength {
366
+ declare namespace sameAs {
417
367
  var skip: (..._args: any[]) => ValidationRule;
418
368
  }
419
369
 
420
370
 
421
- declare namespace sameAs {
371
+ declare namespace match {
422
372
  var skip: (..._args: any[]) => ValidationRule;
423
373
  }
424
374
 
425
375
 
426
- declare namespace match {
376
+ declare namespace after {
427
377
  var skip: (..._args: any[]) => ValidationRule;
428
378
  }
429
379
 
430
380
 
431
381
  declare namespace between {
432
- var skip: (..._args: any[]) => import("../types").ValidationRule;
382
+ var skip: (..._args: any[]) => import("..").ValidationRule;
433
383
  }
434
384
 
435
385
 
436
- declare namespace maxValue {
386
+ declare namespace before {
437
387
  var skip: (..._args: any[]) => ValidationRule;
438
388
  }
439
389
 
440
390
 
441
- declare namespace minValue {
391
+ declare namespace maxLength {
442
392
  var skip: (..._args: any[]) => ValidationRule;
443
393
  }
444
394
 
@@ -458,13 +408,13 @@ declare namespace contains {
458
408
  }
459
409
 
460
410
 
461
- declare namespace endsWith {
462
- var skip: (..._args: any[]) => import("../../types").ValidationRule;
411
+ declare namespace startsWith {
412
+ var skip: (..._args: any[]) => import("../..").ValidationRule;
463
413
  }
464
414
 
465
415
 
466
- declare namespace startsWith {
467
- var skip: (..._args: any[]) => import("../../types").ValidationRule;
416
+ declare namespace endsWith {
417
+ var skip: (..._args: any[]) => import("../..").ValidationRule;
468
418
  }
469
419
 
470
420