@schwarzdavid/ui-kit 0.0.1-alpha.11 → 0.0.1-alpha.13
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/validators.d.ts +20 -0
- package/dist/validators.js +74 -41
- package/package.json +1 -1
package/dist/validators.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ComputedRef } from 'vue';
|
|
2
|
+
import { PartialDeep } from 'type-fest';
|
|
2
3
|
import { Ref } from 'vue';
|
|
4
|
+
import { TranslationFunction } from '@vuelidate/validators';
|
|
3
5
|
import { Validation } from '@vuelidate/core';
|
|
4
6
|
import { ValidationArgs } from '@vuelidate/core';
|
|
5
7
|
import { ValidationRuleWithoutParams } from '@vuelidate/core';
|
|
@@ -55,6 +57,8 @@ equalTo: E;
|
|
|
55
57
|
otherName: string;
|
|
56
58
|
}>;
|
|
57
59
|
|
|
60
|
+
export declare function setGlobalValidationSettings(opt: PartialDeep<ValidationOptions>): void;
|
|
61
|
+
|
|
58
62
|
export declare const url: ValidationRuleWithoutParams<any>;
|
|
59
63
|
|
|
60
64
|
export declare const useVuelidateErrors: <T extends object>(validation: Ref<Validation<ValidationArgs<T>, T>>) => ComputedRef<ValidationErrors<T>>;
|
|
@@ -63,4 +67,20 @@ export declare type ValidationErrors<T extends object> = {
|
|
|
63
67
|
[key in keyof T]: T[key] extends object ? ValidationErrors<T[key]> : string[];
|
|
64
68
|
};
|
|
65
69
|
|
|
70
|
+
export declare type ValidationMessageOptions = ValidationTranslationFn | ValidationTranslationTransformOptions;
|
|
71
|
+
|
|
72
|
+
export declare interface ValidationOptions {
|
|
73
|
+
t: typeof TranslationFunction;
|
|
74
|
+
message: ValidationMessageOptions;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare type ValidationTranslationFn = (validatorName: string) => string;
|
|
78
|
+
|
|
79
|
+
export declare type ValidationTranslationTransform = 'snake_case' | 'camelCase' | 'PascalCase' | 'kebab-case' | 'none';
|
|
80
|
+
|
|
81
|
+
export declare interface ValidationTranslationTransformOptions {
|
|
82
|
+
prefix: string;
|
|
83
|
+
transform: ValidationTranslationTransform;
|
|
84
|
+
}
|
|
85
|
+
|
|
66
86
|
export { }
|
package/dist/validators.js
CHANGED
|
@@ -1,56 +1,89 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { helpers as
|
|
3
|
-
import {
|
|
4
|
-
import { computed as
|
|
5
|
-
const
|
|
1
|
+
import * as t from "@vuelidate/validators";
|
|
2
|
+
import { helpers as u } from "@vuelidate/validators";
|
|
3
|
+
import { clone as h, upperFirst as g, camelCase as c, snakeCase as d, kebabCase as p, assign as w } from "lodash";
|
|
4
|
+
import { computed as A, unref as b } from "vue";
|
|
5
|
+
const m = {
|
|
6
|
+
transform: "none",
|
|
7
|
+
prefix: "validation"
|
|
8
|
+
};
|
|
9
|
+
let o = null, a = h(m);
|
|
10
|
+
const n = t.createI18nMessage({
|
|
6
11
|
t: (...e) => {
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
if (!o)
|
|
13
|
+
throw new Error("No translation function provided");
|
|
14
|
+
return o(...e);
|
|
9
15
|
},
|
|
10
16
|
messagePath(e) {
|
|
11
|
-
|
|
17
|
+
try {
|
|
18
|
+
if (typeof a == "function")
|
|
19
|
+
return a(e.$validator);
|
|
20
|
+
const r = V(e.$validator, a.transform);
|
|
21
|
+
return `${a.prefix}.${r}`;
|
|
22
|
+
} catch (r) {
|
|
23
|
+
return console.log("Error while transforming validator: ", r), "yolo";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
function V(e, r) {
|
|
28
|
+
switch (r) {
|
|
29
|
+
case "camelCase":
|
|
30
|
+
return c(e);
|
|
31
|
+
case "kebab-case":
|
|
32
|
+
return p(e);
|
|
33
|
+
case "snake_case":
|
|
34
|
+
return d(e);
|
|
35
|
+
case "PascalCase":
|
|
36
|
+
return g(c(e));
|
|
37
|
+
default:
|
|
38
|
+
return e;
|
|
12
39
|
}
|
|
13
|
-
}
|
|
40
|
+
}
|
|
41
|
+
const E = n(t.required), C = n(t.requiredIf, { withArguments: !0 }), I = n(t.requiredUnless, { withArguments: !0 }), L = n(t.minLength, { withArguments: !0 }), N = n(t.maxLength, { withArguments: !0 }), P = n(t.minValue, { withArguments: !0 }), T = n(t.maxValue, { withArguments: !0 }), U = n(t.between, { withArguments: !0 }), W = n(t.alpha), B = n(t.alphaNum), F = n(t.numeric), M = n(t.integer), S = n(t.decimal), _ = n(t.email), D = n(t.ipAddress), G = n(t.macAddress), R = n(t.sameAs, { withArguments: !0 }), k = n(t.url), z = n((e) => u.withParams({
|
|
14
42
|
type: "oneOf",
|
|
15
43
|
values: e
|
|
16
|
-
}, (
|
|
44
|
+
}, (r) => {
|
|
17
45
|
const s = Array.isArray(e) ? e : Object.values(e);
|
|
18
|
-
return !
|
|
19
|
-
}), { withArguments: !0 })
|
|
20
|
-
function
|
|
21
|
-
|
|
46
|
+
return !u.req(r) || s.includes(r);
|
|
47
|
+
}), { withArguments: !0 });
|
|
48
|
+
function H(e) {
|
|
49
|
+
e.t && (o = e.t), typeof e.message == "function" ? a = e.message : a = w({}, m, e.message);
|
|
22
50
|
}
|
|
23
|
-
|
|
24
|
-
|
|
51
|
+
const J = (e) => A(() => l(e.value));
|
|
52
|
+
function l(e) {
|
|
53
|
+
return Object.entries(e).map(([r, s]) => r.startsWith("$") ? [r, null] : O(s) ? [r, j(s)] : $(s) ? [r, l(s)] : (console.warn("Unknown validation type.", r, s), [r, null])).reduce((r, [s, i]) => (i && (r[s] = i), r), {});
|
|
54
|
+
}
|
|
55
|
+
function O(e) {
|
|
56
|
+
return typeof e != "object" || e === null ? !1 : Object.hasOwn(e, "$model") && Object.entries(e).filter(([r]) => !r.startsWith("$")).every(([, r]) => f(r));
|
|
25
57
|
}
|
|
26
|
-
function
|
|
27
|
-
return typeof e != "object" || e === null ? !1 : Object.entries(e).filter(([
|
|
58
|
+
function $(e) {
|
|
59
|
+
return typeof e != "object" || e === null ? !1 : Object.entries(e).filter(([r]) => !r.startsWith("$")).some(([, r]) => !f(r));
|
|
28
60
|
}
|
|
29
|
-
function
|
|
61
|
+
function f(e) {
|
|
30
62
|
return typeof e == "object" && e !== null && Object.hasOwn(e, "$params");
|
|
31
63
|
}
|
|
32
|
-
function
|
|
33
|
-
return e.$errors.map((
|
|
64
|
+
function j(e) {
|
|
65
|
+
return e.$errors.map((r) => b(r.$message));
|
|
34
66
|
}
|
|
35
67
|
export {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
W as alpha,
|
|
69
|
+
B as alphaNum,
|
|
70
|
+
U as between,
|
|
71
|
+
S as decimal,
|
|
72
|
+
_ as email,
|
|
73
|
+
M as integer,
|
|
74
|
+
D as ipAddress,
|
|
75
|
+
G as maxAddress,
|
|
76
|
+
N as maxLength,
|
|
77
|
+
T as maxValue,
|
|
78
|
+
L as minLength,
|
|
79
|
+
P as minValue,
|
|
80
|
+
F as numeric,
|
|
81
|
+
z as oneOf,
|
|
82
|
+
E as required,
|
|
83
|
+
C as requiredIf,
|
|
84
|
+
I as requiredUnless,
|
|
85
|
+
R as sameAs,
|
|
86
|
+
H as setGlobalValidationSettings,
|
|
87
|
+
k as url,
|
|
88
|
+
J as useVuelidateErrors
|
|
56
89
|
};
|