@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.
@@ -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 { }
@@ -1,56 +1,89 @@
1
- import * as r from "@vuelidate/validators";
2
- import { helpers as o } from "@vuelidate/validators";
3
- import { useI18n as a } from "vue-i18n";
4
- import { computed as m, unref as l } from "vue";
5
- const n = r.createI18nMessage({
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
- const { t } = a({ useScope: "global" });
8
- return t(...e);
12
+ if (!o)
13
+ throw new Error("No translation function provided");
14
+ return o(...e);
9
15
  },
10
16
  messagePath(e) {
11
- return console.log(e.$validator), "validation." + e.$validator;
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
- }), A = n(r.required), b = n(r.requiredIf, { withArguments: !0 }), V = n(r.requiredUnless, { withArguments: !0 }), O = n(r.minLength, { withArguments: !0 }), j = n(r.maxLength, { withArguments: !0 }), $ = n(r.minValue, { withArguments: !0 }), q = n(r.maxValue, { withArguments: !0 }), x = n(r.between, { withArguments: !0 }), I = n(r.alpha), y = n(r.alphaNum), L = n(r.numeric), E = n(r.integer), N = n(r.decimal), U = n(r.email), W = n(r.ipAddress), B = n(r.macAddress), M = n(r.sameAs, { withArguments: !0 }), P = n(r.url), T = n((e) => o.withParams({
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
- }, (t) => {
44
+ }, (r) => {
17
45
  const s = Array.isArray(e) ? e : Object.values(e);
18
- return !o.req(t) || s.includes(t);
19
- }), { withArguments: !0 }), R = (e) => m(() => i(e.value));
20
- function i(e) {
21
- return Object.entries(e).map(([t, s]) => t.startsWith("$") ? [t, null] : f(s) ? [t, d(s)] : h(s) ? [t, i(s)] : (console.warn("Unknown validation type.", t, s), [t, null])).reduce((t, [s, u]) => (u && (t[s] = u), t), {});
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
- function f(e) {
24
- return typeof e != "object" || e === null ? !1 : Object.hasOwn(e, "$model") && Object.entries(e).filter(([t]) => !t.startsWith("$")).every(([, t]) => c(t));
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 h(e) {
27
- return typeof e != "object" || e === null ? !1 : Object.entries(e).filter(([t]) => !t.startsWith("$")).some(([, t]) => !c(t));
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 c(e) {
61
+ function f(e) {
30
62
  return typeof e == "object" && e !== null && Object.hasOwn(e, "$params");
31
63
  }
32
- function d(e) {
33
- return e.$errors.map((t) => l(t.$message));
64
+ function j(e) {
65
+ return e.$errors.map((r) => b(r.$message));
34
66
  }
35
67
  export {
36
- I as alpha,
37
- y as alphaNum,
38
- x as between,
39
- N as decimal,
40
- U as email,
41
- E as integer,
42
- W as ipAddress,
43
- B as maxAddress,
44
- j as maxLength,
45
- q as maxValue,
46
- O as minLength,
47
- $ as minValue,
48
- L as numeric,
49
- T as oneOf,
50
- A as required,
51
- b as requiredIf,
52
- V as requiredUnless,
53
- M as sameAs,
54
- P as url,
55
- R as useVuelidateErrors
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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schwarzdavid/ui-kit",
3
- "version": "0.0.1-alpha.11",
3
+ "version": "0.0.1-alpha.13",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "preview": "vite preview",