@dolanske/v-valid 3.0.0 → 3.0.1
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/README.md +20 -9
- package/dist/v-valid.d.ts +11 -11
- package/dist/v-valid.js +42 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,7 +147,7 @@ Requires input to have a minimal specified length.
|
|
|
147
147
|
|
|
148
148
|
- **Parameters**
|
|
149
149
|
- `Ref<number> | number` min
|
|
150
|
-
- **
|
|
150
|
+
- **Supports**
|
|
151
151
|
- `string`, `Set<any>`, `Map<any, any>`, `any[]` and `Object`
|
|
152
152
|
|
|
153
153
|
```js
|
|
@@ -164,7 +164,7 @@ Requires input to have a maximum specified length.
|
|
|
164
164
|
|
|
165
165
|
- **Parameters**
|
|
166
166
|
- `Ref<number> | number` max
|
|
167
|
-
- **
|
|
167
|
+
- **Supports**
|
|
168
168
|
- `string`, `Set<any>`, `Map<any, any>`, `any[]`, `Object`
|
|
169
169
|
|
|
170
170
|
```js
|
|
@@ -181,7 +181,7 @@ Input must be a string and excluding spaces must be equal or greater to the prov
|
|
|
181
181
|
|
|
182
182
|
- **Parameters**
|
|
183
183
|
- `Ref<number> | number` min - Minimum allowed string length
|
|
184
|
-
- **
|
|
184
|
+
- **Supports**
|
|
185
185
|
- `string`
|
|
186
186
|
|
|
187
187
|
```js
|
|
@@ -202,7 +202,7 @@ Input must be a string and excluding spaces must be equal or lesser to the provi
|
|
|
202
202
|
|
|
203
203
|
- **Parameters**
|
|
204
204
|
- `Ref<number> | number` max - Maximum allowed string length
|
|
205
|
-
- **
|
|
205
|
+
- **Supports**
|
|
206
206
|
- `string`
|
|
207
207
|
|
|
208
208
|
```js
|
|
@@ -224,7 +224,7 @@ Requires input to be a number or Date within the specified bounds.
|
|
|
224
224
|
- **Parameters**
|
|
225
225
|
- `Ref<number> | number | Date` min
|
|
226
226
|
- `Ref<number> | number | Date` max
|
|
227
|
-
- **
|
|
227
|
+
- **Supports**
|
|
228
228
|
- `number`, `Date`
|
|
229
229
|
|
|
230
230
|
```js
|
|
@@ -238,6 +238,17 @@ const rules = {
|
|
|
238
238
|
|
|
239
239
|
---
|
|
240
240
|
|
|
241
|
+
### `before(Date)`
|
|
242
|
+
|
|
243
|
+
Provided value must be a date and be at or before the rule
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
### `after(Date)`
|
|
248
|
+
|
|
249
|
+
Provided value must be a date and be at or after the rule
|
|
250
|
+
---
|
|
251
|
+
|
|
241
252
|
### `url`
|
|
242
253
|
|
|
243
254
|
Requires input to be a valid URL.
|
|
@@ -269,7 +280,7 @@ Requires input to be the same as the provided value in the rule.
|
|
|
269
280
|
- **Parameters**
|
|
270
281
|
- `Ref<any> | any` value
|
|
271
282
|
- `boolean` (default: false) lenient - wether to only compare based on value or value and type (eg. `==` vs `===`)
|
|
272
|
-
- **
|
|
283
|
+
- **Supports**
|
|
273
284
|
- `any`
|
|
274
285
|
|
|
275
286
|
```js
|
|
@@ -286,7 +297,7 @@ Requires value to match the provided regular expression check.
|
|
|
286
297
|
|
|
287
298
|
- **Parameters**
|
|
288
299
|
- `string | RegExp` regex
|
|
289
|
-
- **
|
|
300
|
+
- **Supports**
|
|
290
301
|
- `string`
|
|
291
302
|
|
|
292
303
|
```js
|
|
@@ -307,7 +318,7 @@ Checks wether string input contains certain words or characters. If you write mu
|
|
|
307
318
|
- **Parameters**
|
|
308
319
|
- `string | string[]` items - Words to check for
|
|
309
320
|
- `boolean` (default: false) exact - Wether to match against the entire input string or split it by spaces. Default to true
|
|
310
|
-
- **
|
|
321
|
+
- **Supports**
|
|
311
322
|
- `string`
|
|
312
323
|
|
|
313
324
|
```js
|
|
@@ -332,7 +343,7 @@ You can optionally specify the position where the check begins in the input valu
|
|
|
332
343
|
- `string | Ref<string>` String we are matching against
|
|
333
344
|
- `number` Starting position of the matching
|
|
334
345
|
- *Note*: When using `endsWith`, the position starts at the end and goes backwards
|
|
335
|
-
- **
|
|
346
|
+
- **Supports**
|
|
336
347
|
- `string`
|
|
337
348
|
|
|
338
349
|
```js
|
package/dist/v-valid.d.ts
CHANGED
|
@@ -343,27 +343,32 @@ export declare function withLabel(message: string | Label, validator: Validation
|
|
|
343
343
|
export { }
|
|
344
344
|
|
|
345
345
|
|
|
346
|
+
declare namespace and {
|
|
347
|
+
var skip: (..._args: any[]) => ValidationRule;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
346
351
|
declare namespace not {
|
|
347
352
|
var skip: ValidationRule;
|
|
348
353
|
}
|
|
349
354
|
|
|
350
355
|
|
|
351
|
-
declare namespace
|
|
356
|
+
declare namespace maxLength {
|
|
352
357
|
var skip: (..._args: any[]) => ValidationRule;
|
|
353
358
|
}
|
|
354
359
|
|
|
355
360
|
|
|
356
|
-
declare namespace
|
|
361
|
+
declare namespace minLength {
|
|
357
362
|
var skip: (..._args: any[]) => ValidationRule;
|
|
358
363
|
}
|
|
359
364
|
|
|
360
365
|
|
|
361
|
-
declare namespace
|
|
366
|
+
declare namespace sameAs {
|
|
362
367
|
var skip: (..._args: any[]) => ValidationRule;
|
|
363
368
|
}
|
|
364
369
|
|
|
365
370
|
|
|
366
|
-
declare namespace
|
|
371
|
+
declare namespace or {
|
|
367
372
|
var skip: (..._args: any[]) => ValidationRule;
|
|
368
373
|
}
|
|
369
374
|
|
|
@@ -383,17 +388,12 @@ declare namespace between {
|
|
|
383
388
|
}
|
|
384
389
|
|
|
385
390
|
|
|
386
|
-
declare namespace
|
|
387
|
-
var skip: (..._args: any[]) => ValidationRule;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
declare namespace maxLength {
|
|
391
|
+
declare namespace maxLenNoSpace {
|
|
392
392
|
var skip: (..._args: any[]) => ValidationRule;
|
|
393
393
|
}
|
|
394
394
|
|
|
395
395
|
|
|
396
|
-
declare namespace
|
|
396
|
+
declare namespace before {
|
|
397
397
|
var skip: (..._args: any[]) => ValidationRule;
|
|
398
398
|
}
|
|
399
399
|
|
package/dist/v-valid.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { ref as
|
|
1
|
+
import { ref as $, reactive as j, watch as V, isRef as R, unref as a } from "vue-demi";
|
|
2
2
|
function y(e) {
|
|
3
3
|
return e.trim().replace(" ", ".");
|
|
4
4
|
}
|
|
5
|
-
async function
|
|
5
|
+
async function D(e, t, n = "") {
|
|
6
6
|
for (const r in e) {
|
|
7
7
|
const s = `${n} ${r}`.trim();
|
|
8
|
-
d(e[r]) && !(e[r] instanceof Date) ? await
|
|
8
|
+
d(e[r]) && !(e[r] instanceof Date) ? await D(e[r], t, s) : await t(r, e[r], s);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function N(e, t, n = "") {
|
|
12
12
|
for (const r in e) {
|
|
13
13
|
const s = `${n} ${r}`.trim();
|
|
14
|
-
d(e[r]) && !(e[r] instanceof Date) ?
|
|
14
|
+
d(e[r]) && !(e[r] instanceof Date) ? D(e[r], t, s) : t(r, e[r], s);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function l(e) {
|
|
18
18
|
return e == null;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function W(e) {
|
|
21
21
|
return typeof e == "boolean";
|
|
22
22
|
}
|
|
23
23
|
function L(e) {
|
|
@@ -26,19 +26,19 @@ function L(e) {
|
|
|
26
26
|
function v(e) {
|
|
27
27
|
return e instanceof Date;
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function C(e) {
|
|
30
30
|
return Array.isArray(e);
|
|
31
31
|
}
|
|
32
32
|
function I(e) {
|
|
33
33
|
return l(e) ? !0 : "length" in e ? e.length <= 0 : "size" in e ? e.size <= 0 : d(e) ? Object.keys(e).length <= 0 : !0;
|
|
34
34
|
}
|
|
35
|
-
function
|
|
35
|
+
function U(e) {
|
|
36
36
|
return e instanceof Map;
|
|
37
37
|
}
|
|
38
38
|
function d(e) {
|
|
39
|
-
return typeof e == "object" && !
|
|
39
|
+
return typeof e == "object" && !C(e) && e !== null && !L(e);
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function F(e) {
|
|
42
42
|
return e instanceof Set;
|
|
43
43
|
}
|
|
44
44
|
function c(e, t, n) {
|
|
@@ -79,51 +79,51 @@ function q() {
|
|
|
79
79
|
return { id: null, value: null, invalid: !1, errors: {}, messages: [] };
|
|
80
80
|
}
|
|
81
81
|
function ke(e, t, n = {}) {
|
|
82
|
-
const { proactive: r = !1, autoclear: s = !1 } = n, i =
|
|
82
|
+
const { proactive: r = !1, autoclear: s = !1 } = n, i = $(!1), o = $(!1), u = $({}), g = j({
|
|
83
83
|
didValidate: !1
|
|
84
84
|
});
|
|
85
|
-
s ?
|
|
85
|
+
s ? V(e, () => {
|
|
86
86
|
g.didValidate && k();
|
|
87
|
-
}, { deep: !0 }) : r && (
|
|
88
|
-
function
|
|
89
|
-
i.value = !1, o.value = !1,
|
|
90
|
-
c(u.value, y(
|
|
87
|
+
}, { deep: !0 }) : r && (V(e, () => b(), { deep: !0 }), R(t) && V(t, () => b(), { deep: !0 })), k();
|
|
88
|
+
function K() {
|
|
89
|
+
i.value = !1, o.value = !1, N(e, (m, h, w) => {
|
|
90
|
+
c(u.value, y(w), q());
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
function k() {
|
|
94
|
-
g.didValidate = !1,
|
|
94
|
+
g.didValidate = !1, K();
|
|
95
95
|
}
|
|
96
|
-
async function
|
|
97
|
-
return k(), o.value = !0, new Promise(async (h,
|
|
98
|
-
await
|
|
96
|
+
async function b(...m) {
|
|
97
|
+
return k(), o.value = !0, new Promise(async (h, w) => {
|
|
98
|
+
await D(e, async (H, _, p) => {
|
|
99
99
|
p = y(p), c(u.value, p, q());
|
|
100
|
-
const
|
|
100
|
+
const J = a(t), z = T(J, p);
|
|
101
101
|
if (!z)
|
|
102
102
|
return Promise.resolve();
|
|
103
|
-
for (const [E,
|
|
103
|
+
for (const [E, Q] of Object.entries(z)) {
|
|
104
104
|
if (m.length > 0 && !m.includes(E))
|
|
105
105
|
continue;
|
|
106
|
-
const { label: P, validate:
|
|
107
|
-
if (
|
|
106
|
+
const { label: P, validate: X, __skip: Y } = Q;
|
|
107
|
+
if (Y)
|
|
108
108
|
continue;
|
|
109
|
-
const
|
|
110
|
-
if (c(u.value, `${p}.id`,
|
|
109
|
+
const Z = await X(_);
|
|
110
|
+
if (c(u.value, `${p}.id`, H), c(u.value, `${p}.value`, _), !Z) {
|
|
111
111
|
i.value = !0, c(u.value, `${p}.invalid`, !0), c(u.value, `${p}.errors.${E}`, P(_));
|
|
112
112
|
const A = `${p}.messages`, O = T(u.value, A);
|
|
113
113
|
O.push(P(_)), c(u.value, A, O);
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
return Promise.resolve();
|
|
117
|
-
}), o.value = !1, g.didValidate = !0, i.value ?
|
|
117
|
+
}), o.value = !1, g.didValidate = !0, i.value ? w(u.value) : h(u.value);
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function G(m, h) {
|
|
121
121
|
c(u.value, `${m}.errors.${h.key}`, h.message), c(u.value, `${m}.invalid`, !0);
|
|
122
122
|
}
|
|
123
123
|
return {
|
|
124
124
|
reset: k,
|
|
125
|
-
validate:
|
|
126
|
-
addError:
|
|
125
|
+
validate: b,
|
|
126
|
+
addError: G,
|
|
127
127
|
errors: u,
|
|
128
128
|
anyError: i,
|
|
129
129
|
pending: o
|
|
@@ -162,14 +162,14 @@ function S(e, t, n) {
|
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
const
|
|
165
|
+
const M = "Value does not satisfy the validation rule.";
|
|
166
166
|
function _e(e, t, n) {
|
|
167
167
|
return {
|
|
168
168
|
skip: f,
|
|
169
169
|
name: n ?? "custom-object-rule",
|
|
170
170
|
__skip: !1,
|
|
171
171
|
validate: (r) => e(r),
|
|
172
|
-
label: (r) => l(t) ?
|
|
172
|
+
label: (r) => l(t) ? M : typeof t == "string" ? t : t(r)
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
function ye(e, t, n) {
|
|
@@ -179,13 +179,13 @@ function ye(e, t, n) {
|
|
|
179
179
|
__skip: !1,
|
|
180
180
|
name: n ?? "custom-param-rule",
|
|
181
181
|
validate: (i) => e(i, s),
|
|
182
|
-
label: (i) => l(t) ?
|
|
182
|
+
label: (i) => l(t) ? M : typeof t == "string" ? t : t(i, s)
|
|
183
183
|
});
|
|
184
184
|
return r.skip = f, r;
|
|
185
185
|
}
|
|
186
186
|
function be(e) {
|
|
187
|
-
return
|
|
188
|
-
|
|
187
|
+
return N(e, (t, n, r) => {
|
|
188
|
+
C(n) && c(e, r, n.reduce((s, i, o) => (i.name in s ? Reflect.set(s, i.name + o, i) : Reflect.set(s, i.name, i), s), {}));
|
|
189
189
|
}), e;
|
|
190
190
|
}
|
|
191
191
|
function we(e, t) {
|
|
@@ -200,10 +200,10 @@ function we(e, t) {
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
function $e(e, t) {
|
|
203
|
-
return
|
|
203
|
+
return W(e) ? e ? t : f() : R(e) ? e.value ? t : f() : L(e) ? e() ? t : f() : e.then((n) => n ? t : f());
|
|
204
204
|
}
|
|
205
205
|
function Ve(e, t) {
|
|
206
|
-
return
|
|
206
|
+
return W(e) ? e ? f() : t : R(e) ? e.value ? f() : t : L(e) ? e() ? f() : t : e.then((n) => n ? f() : t);
|
|
207
207
|
}
|
|
208
208
|
function x(...e) {
|
|
209
209
|
return {
|
|
@@ -250,7 +250,7 @@ function ne(e) {
|
|
|
250
250
|
return {
|
|
251
251
|
name: "minLength",
|
|
252
252
|
__skip: !1,
|
|
253
|
-
validate: (t) => l(t) ? !1 : (e = a(e),
|
|
253
|
+
validate: (t) => l(t) ? !1 : (e = a(e), F(t) || U(t) ? t.size >= e : d(t) ? Object.keys(t).length >= e : t != null && t.length ? t.length >= e : !1),
|
|
254
254
|
/* c8 ignore next 3 */
|
|
255
255
|
label: () => `Value must be greater or equal to ${a(e)}`
|
|
256
256
|
};
|
|
@@ -260,13 +260,13 @@ function re(e) {
|
|
|
260
260
|
return {
|
|
261
261
|
name: "maxLength",
|
|
262
262
|
__skip: !1,
|
|
263
|
-
validate: (t) => l(t) ? !1 : (e = a(e),
|
|
263
|
+
validate: (t) => l(t) ? !1 : (e = a(e), F(t) || U(t) ? t.size <= e : d(t) ? Object.keys(t).length <= e : t.length <= e),
|
|
264
264
|
/* c8 ignore next 3 */
|
|
265
265
|
label: () => `Value must be lesser or equal to ${a(e)}`
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
268
|
re.skip = f;
|
|
269
|
-
const se = /^([\w!#$%&'*+/=?^`{|}~-]+(?:\.[\w!#$%&'*+/=?^`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)$/i, ie = /[^a-z0-9]/i,
|
|
269
|
+
const se = /^([\w!#$%&'*+/=?^`{|}~-]+(?:\.[\w!#$%&'*+/=?^`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)$/i, ie = /[^a-z0-9]/i, B = /\S/g, De = {
|
|
270
270
|
__skip: !1,
|
|
271
271
|
name: "email",
|
|
272
272
|
skip: f,
|
|
@@ -347,7 +347,7 @@ function ce(e) {
|
|
|
347
347
|
if (l(t) || typeof t != "string")
|
|
348
348
|
return !1;
|
|
349
349
|
e = a(e);
|
|
350
|
-
const n = t.match(
|
|
350
|
+
const n = t.match(B);
|
|
351
351
|
return n ? n.length <= e : !1;
|
|
352
352
|
},
|
|
353
353
|
label: (t) => typeof t != "string" ? "Value must be a string and " : `Value must have maximal lenght of ${a(e)} excluding spaces`
|
|
@@ -362,7 +362,7 @@ function pe(e) {
|
|
|
362
362
|
if (l(t) || typeof t != "string")
|
|
363
363
|
return !1;
|
|
364
364
|
e = a(e);
|
|
365
|
-
const n = t.match(
|
|
365
|
+
const n = t.match(B);
|
|
366
366
|
return n ? n.length >= e : !1;
|
|
367
367
|
},
|
|
368
368
|
/* c8 ignore next 3 */
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dolanske/v-valid",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Model based form validation made for vue 3. Inspired by vuelidate with personal take on the API and implementation",
|
|
7
7
|
"author": "dolanske",
|