@dolanske/v-valid 2.1.0 → 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/LICENSE +20 -20
- package/README.md +470 -521
- package/dist/v-valid.d.ts +176 -210
- package/dist/v-valid.js +438 -508
- package/package.json +53 -53
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
|
-
* @
|
|
7
|
-
* @param
|
|
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
|
|
10
|
+
export declare function after(min: MaybeRef<Date>): ValidationRule;
|
|
10
11
|
|
|
11
|
-
export declare namespace
|
|
12
|
+
export declare namespace after {
|
|
12
13
|
var skip: (..._args: any[]) => ValidationRule;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* @rule Value must
|
|
17
|
+
* @rule Value must pass every provided check
|
|
17
18
|
* @param rules Single or multiple validation rules
|
|
18
19
|
*/
|
|
19
|
-
export declare function
|
|
20
|
+
export declare function and(...rules: ValidationRule[]): ValidationRule;
|
|
20
21
|
|
|
21
|
-
export declare namespace
|
|
22
|
-
var skip: ValidationRule;
|
|
22
|
+
export declare namespace and {
|
|
23
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
|
-
* @
|
|
27
|
-
* @param
|
|
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
|
|
30
|
+
export declare function before(max: MaybeRef<Date>): ValidationRule;
|
|
30
31
|
|
|
31
|
-
export declare namespace
|
|
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
|
|
@@ -115,6 +77,16 @@ declare type _DeepKeys<T> = T extends object ? ({
|
|
|
115
77
|
[K in (string | number) & keyof T]: `${(`.${K}` | (`${K}` extends `${number}` ? `[${K}]` : never))}${'' | _DeepKeys<FixArr<T[K]>>}`;
|
|
116
78
|
}[(string | number) & keyof T]) : never;
|
|
117
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Type safe helper to generating rules from form objects. Also allows array rule definition
|
|
82
|
+
*
|
|
83
|
+
* @param rules
|
|
84
|
+
* @returns Rules to be used within the composable
|
|
85
|
+
*/
|
|
86
|
+
export declare function defineRules<F>(rules: DefineRuleType<F>): DefineRuleType<F>;
|
|
87
|
+
|
|
88
|
+
declare type DefineRuleType<T> = ReplacePrimitivesOptional<T, Record<string, Rule> | Array<Rule>>;
|
|
89
|
+
|
|
118
90
|
declare type DefLabel = string | ((value: any) => string);
|
|
119
91
|
|
|
120
92
|
/**
|
|
@@ -153,54 +125,6 @@ declare type FixArr<T> = T extends readonly any[] ? Omit<T, Exclude<keyof any[],
|
|
|
153
125
|
*/
|
|
154
126
|
export declare const hasSpecialChars: ValidationRuleObject;
|
|
155
127
|
|
|
156
|
-
/**
|
|
157
|
-
* @Rule Checkes wether value is an Array
|
|
158
|
-
* @param value Input value
|
|
159
|
-
*/
|
|
160
|
-
export declare const isArr: Type['arr'];
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @Rule Checkes wether value is a valid Date object
|
|
164
|
-
* @param value Input value
|
|
165
|
-
*/
|
|
166
|
-
export declare const isDate: Type['date'];
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @Rule Checkes wether value is a Map
|
|
170
|
-
* @param value Input value
|
|
171
|
-
*/
|
|
172
|
-
export declare const isMap: Type['map'];
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @Rule Checkes wether value is a number
|
|
176
|
-
* @param value Input value
|
|
177
|
-
*/
|
|
178
|
-
export declare const isNum: Type['num'];
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @Rule Checkes wether value is an Object
|
|
182
|
-
* @param value Input value
|
|
183
|
-
*/
|
|
184
|
-
export declare const isObj: Type['obj'];
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* @Rule Checkes wether value is a Set
|
|
188
|
-
* @param value Input value
|
|
189
|
-
*/
|
|
190
|
-
export declare const isSet: Type['set'];
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* @Rule Checkes wether value is a string
|
|
194
|
-
* @param value Input value
|
|
195
|
-
*/
|
|
196
|
-
export declare const isStr: Type['str'];
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @Rule Checkes wether value is a Symbol
|
|
200
|
-
* @param value Input value
|
|
201
|
-
*/
|
|
202
|
-
export declare const isSymbol: Type['symbol'];
|
|
203
|
-
|
|
204
128
|
declare type Label = (value: any, args?: Record<string, unknown>) => string;
|
|
205
129
|
|
|
206
130
|
/**
|
|
@@ -233,16 +157,6 @@ export declare namespace maxLenNoSpace {
|
|
|
233
157
|
var skip: (..._args: any[]) => ValidationRule;
|
|
234
158
|
}
|
|
235
159
|
|
|
236
|
-
/**
|
|
237
|
-
* @Rule Input must be a number or a date which satisfies the maximum provided value.
|
|
238
|
-
* @param max maximum allowed value
|
|
239
|
-
*/
|
|
240
|
-
export declare function maxValue(max: number | Date | Ref<number | Date>): ValidationRule;
|
|
241
|
-
|
|
242
|
-
export declare namespace maxValue {
|
|
243
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
160
|
/**
|
|
247
161
|
* @Rule Input must be equal or greater than the provided amount
|
|
248
162
|
* @param min Minimum allowed length the input must satisfy
|
|
@@ -264,12 +178,22 @@ export declare namespace minLenNoSpace {
|
|
|
264
178
|
}
|
|
265
179
|
|
|
266
180
|
/**
|
|
267
|
-
* @
|
|
268
|
-
* @param
|
|
181
|
+
* @rule Value must fail the check or list of all provided checks
|
|
182
|
+
* @param rules Single or multiple validation rules
|
|
269
183
|
*/
|
|
270
|
-
export declare function
|
|
184
|
+
export declare function not(...rules: ValidationRule[]): ValidationRule;
|
|
271
185
|
|
|
272
|
-
export declare namespace
|
|
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 {
|
|
273
197
|
var skip: (..._args: any[]) => ValidationRule;
|
|
274
198
|
}
|
|
275
199
|
|
|
@@ -277,12 +201,18 @@ declare type ReplacePrimitives<T, ReplaceWith> = T extends Record<string, unknow
|
|
|
277
201
|
[K in keyof T]: ReplacePrimitives<T[K], ReplaceWith>;
|
|
278
202
|
} : ReplaceWith;
|
|
279
203
|
|
|
204
|
+
declare type ReplacePrimitivesOptional<T, ReplaceWith> = T extends Record<string, unknown> ? {
|
|
205
|
+
[K in keyof T]?: ReplacePrimitivesOptional<T[K], ReplaceWith>;
|
|
206
|
+
} : ReplaceWith;
|
|
207
|
+
|
|
280
208
|
/**
|
|
281
209
|
* @Rule Input must not be empty, null or undefined.
|
|
282
210
|
* If input is number with value 0, it will return true as value was provided
|
|
283
211
|
*/
|
|
284
212
|
export declare const required: ValidationRuleObject;
|
|
285
213
|
|
|
214
|
+
declare type Rule = ValidationRule | ValidationRuleObject;
|
|
215
|
+
|
|
286
216
|
declare type RuleParams = Record<string, any>;
|
|
287
217
|
|
|
288
218
|
/**
|
|
@@ -312,19 +242,6 @@ export declare namespace startsWith {
|
|
|
312
242
|
var skip: (..._args: any[]) => ValidationRule;
|
|
313
243
|
}
|
|
314
244
|
|
|
315
|
-
declare interface Type {
|
|
316
|
-
str: ValidationRuleObject;
|
|
317
|
-
num: ValidationRuleObject;
|
|
318
|
-
arr: ValidationRuleObject;
|
|
319
|
-
obj: ValidationRuleObject;
|
|
320
|
-
set: ValidationRuleObject;
|
|
321
|
-
map: ValidationRuleObject;
|
|
322
|
-
date: ValidationRuleObject;
|
|
323
|
-
symbol: ValidationRuleObject;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
export declare const type: Type;
|
|
327
|
-
|
|
328
245
|
/**
|
|
329
246
|
* @Rule Input must be a valid URL
|
|
330
247
|
*/
|
|
@@ -351,108 +268,157 @@ export declare function useValidation<F extends Record<string, any>, R extends P
|
|
|
351
268
|
pending: Ref<boolean>;
|
|
352
269
|
};
|
|
353
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
|
+
|
|
354
285
|
export declare interface ValidationError {
|
|
286
|
+
/**
|
|
287
|
+
* Form object property name
|
|
288
|
+
*/
|
|
355
289
|
id: string | null;
|
|
290
|
+
/**
|
|
291
|
+
* Received value
|
|
292
|
+
*/
|
|
356
293
|
value: any;
|
|
294
|
+
/**
|
|
295
|
+
* Status
|
|
296
|
+
*/
|
|
357
297
|
invalid: boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Errors object where the key is the name of the rule and the value is the error message
|
|
300
|
+
*/
|
|
358
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[];
|
|
359
306
|
}
|
|
360
307
|
|
|
361
|
-
declare interface ValidationOptions {
|
|
308
|
+
export declare interface ValidationOptions {
|
|
309
|
+
/**
|
|
310
|
+
* Performs validation whenever the form object updates
|
|
311
|
+
*/
|
|
362
312
|
proactive?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Clears errors on new input
|
|
315
|
+
*/
|
|
363
316
|
autoclear?: boolean;
|
|
364
317
|
}
|
|
365
318
|
|
|
366
|
-
declare interface ValidationRule {
|
|
319
|
+
export declare interface ValidationRule {
|
|
367
320
|
__skip: boolean;
|
|
368
321
|
validate: (arg: any) => Promise<boolean> | boolean;
|
|
369
322
|
label: Label;
|
|
370
323
|
name: string;
|
|
371
324
|
}
|
|
372
325
|
|
|
373
|
-
declare interface ValidationRuleObject extends ValidationRule {
|
|
326
|
+
export declare interface ValidationRuleObject extends ValidationRule {
|
|
374
327
|
skip: () => void;
|
|
375
328
|
}
|
|
376
329
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
declare namespace $not {
|
|
391
|
-
var skip: ValidationRule;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
declare namespace minLength {
|
|
396
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
declare namespace sameAs {
|
|
401
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
declare namespace maxLength {
|
|
406
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
declare namespace match {
|
|
411
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
declare namespace between {
|
|
416
|
-
var skip: (..._args: any[]) => import("../types").ValidationRule;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
declare namespace minValue {
|
|
421
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
declare namespace maxLenNoSpace {
|
|
426
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
declare namespace maxValue {
|
|
431
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
declare namespace startsWith {
|
|
436
|
-
var skip: (..._args: any[]) => import("../../types").ValidationRule;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
declare namespace endsWith {
|
|
441
|
-
var skip: (..._args: any[]) => import("../../types").ValidationRule;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
declare namespace contains {
|
|
446
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
declare namespace minLenNoSpace {
|
|
451
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
declare namespace password {
|
|
456
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
457
|
-
}
|
|
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;
|
|
458
342
|
|
|
343
|
+
export { }
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
declare namespace not {
|
|
347
|
+
var skip: ValidationRule;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
declare namespace and {
|
|
352
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
declare namespace or {
|
|
357
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
declare namespace minLength {
|
|
362
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
declare namespace sameAs {
|
|
367
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
declare namespace match {
|
|
372
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
declare namespace after {
|
|
377
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
declare namespace between {
|
|
382
|
+
var skip: (..._args: any[]) => import("..").ValidationRule;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
declare namespace before {
|
|
387
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
declare namespace maxLength {
|
|
392
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
declare namespace maxLenNoSpace {
|
|
397
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
declare namespace minLenNoSpace {
|
|
402
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
declare namespace contains {
|
|
407
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
declare namespace startsWith {
|
|
412
|
+
var skip: (..._args: any[]) => import("../..").ValidationRule;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
declare namespace endsWith {
|
|
417
|
+
var skip: (..._args: any[]) => import("../..").ValidationRule;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
declare namespace password {
|
|
422
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
423
|
+
}
|
|
424
|
+
|