mhz-helpers 1.0.2 → 1.0.4
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/composables/index.d.ts +2 -0
- package/dist/composables/useAuth.d.ts +9 -0
- package/dist/composables/usePage.d.ts +3 -1
- package/dist/composables/useValidate.d.ts +6 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/rules.d.ts +6 -0
- package/dist/index.js +914 -54
- package/package.json +7 -4
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const isAuth: Readonly<import("vue").Ref<boolean>>;
|
|
2
|
+
export declare function setAuth(auth: boolean): void;
|
|
3
|
+
export declare function logout(url: string, deleteAuthHeader: () => void, tokenName: string): void;
|
|
4
|
+
export declare function setCookieToken(token: string, tokenName: string): void;
|
|
5
|
+
export declare function getCookieToken(tokenName: string): string | undefined;
|
|
6
|
+
export declare function deleteCookieToken(tokenName: string): void;
|
|
7
|
+
export declare function useAuth(): {
|
|
8
|
+
auth: (token: string, url: string, setAuthHeader: (token: string) => void, tokenName: string) => void;
|
|
9
|
+
};
|
|
@@ -5,14 +5,16 @@ export interface ISortOption {
|
|
|
5
5
|
export interface IPageQuery {
|
|
6
6
|
page: number;
|
|
7
7
|
sort: ISortOption;
|
|
8
|
+
filter: object;
|
|
8
9
|
}
|
|
9
|
-
export declare function usePage(): {
|
|
10
|
+
export declare function usePage(filter?: object): {
|
|
10
11
|
query: import("vue").Ref<{
|
|
11
12
|
page: number;
|
|
12
13
|
sort: {
|
|
13
14
|
value?: string | undefined;
|
|
14
15
|
isAsc: boolean;
|
|
15
16
|
};
|
|
17
|
+
filter: object;
|
|
16
18
|
}>;
|
|
17
19
|
resetQuery: (value: string) => void;
|
|
18
20
|
setQueryPage: (pageToSet: number) => void;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
export declare function useValidator<T>(formData: Ref<T>, rules: ComputedRef<object>): {
|
|
3
|
+
error: (field: string) => string | undefined;
|
|
4
|
+
errors: ComputedRef<Record<string, import("async-validator").ValidateError[]> | undefined>;
|
|
5
|
+
isValid: () => boolean;
|
|
6
|
+
};
|
package/dist/helpers/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,83 +1,943 @@
|
|
|
1
|
-
import { computed as
|
|
2
|
-
import { useRouter as
|
|
3
|
-
function
|
|
4
|
-
const
|
|
5
|
-
function
|
|
6
|
-
return !r.value ||
|
|
7
|
-
}
|
|
8
|
-
return { data:
|
|
9
|
-
}
|
|
10
|
-
function
|
|
11
|
-
const e =
|
|
12
|
-
page: Number(
|
|
1
|
+
import { computed as V, ref as j, watch as W, unref as ce, toRef as de, readonly as ie, customRef as le, isRef as pe, shallowRef as ye, toRaw as me } from "vue";
|
|
2
|
+
import { useRouter as ae, useRoute as he } from "vue-router";
|
|
3
|
+
function ir(n) {
|
|
4
|
+
const e = V(() => n.value?.data), r = V(() => n.value?.total);
|
|
5
|
+
function t(i, a) {
|
|
6
|
+
return !r.value || i === 0 || i === r.value + 1 ? a : i;
|
|
7
|
+
}
|
|
8
|
+
return { data: e, total: r, setPage: t };
|
|
9
|
+
}
|
|
10
|
+
function ar(n) {
|
|
11
|
+
const e = ae(), r = he(), t = j({
|
|
12
|
+
page: Number(r.query.page || 1),
|
|
13
13
|
sort: {
|
|
14
|
-
value:
|
|
15
|
-
isAsc:
|
|
16
|
-
}
|
|
14
|
+
value: r.query.sort?.toString(),
|
|
15
|
+
isAsc: r.query.dir !== "desc"
|
|
16
|
+
},
|
|
17
|
+
filter: n || {}
|
|
17
18
|
});
|
|
18
|
-
function
|
|
19
|
-
|
|
19
|
+
function i(f) {
|
|
20
|
+
t.value = Object.assign(t.value, { page: 1, sort: { value: f, isAsc: !0 }, filter: {} });
|
|
20
21
|
}
|
|
21
|
-
function
|
|
22
|
-
|
|
22
|
+
function a(f) {
|
|
23
|
+
t.value.page = f;
|
|
23
24
|
}
|
|
24
|
-
return
|
|
25
|
-
() =>
|
|
25
|
+
return W(
|
|
26
|
+
() => t.value,
|
|
26
27
|
() => {
|
|
27
28
|
e.push({
|
|
28
|
-
path:
|
|
29
|
+
path: r.path,
|
|
29
30
|
query: {
|
|
30
|
-
page:
|
|
31
|
-
sort:
|
|
32
|
-
dir:
|
|
31
|
+
page: t.value.page,
|
|
32
|
+
sort: t.value.sort.value,
|
|
33
|
+
dir: t.value.sort.isAsc ? "asc" : "desc"
|
|
33
34
|
}
|
|
34
35
|
});
|
|
35
36
|
},
|
|
36
37
|
{ deep: !0 }
|
|
37
|
-
), { query:
|
|
38
|
+
), { query: t, resetQuery: i, setQueryPage: a };
|
|
39
|
+
}
|
|
40
|
+
function fr() {
|
|
41
|
+
const n = j(1), e = j([]);
|
|
42
|
+
function r(i) {
|
|
43
|
+
e.value = [...e.value, ...i];
|
|
44
|
+
}
|
|
45
|
+
function t(i, a) {
|
|
46
|
+
i || (n.value = a);
|
|
47
|
+
}
|
|
48
|
+
return { page: n, allData: e, addData: r, handleScroll: t };
|
|
38
49
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
function D(n) {
|
|
51
|
+
return typeof n == "function" ? n() : ce(n);
|
|
52
|
+
}
|
|
53
|
+
const ge = () => {
|
|
54
|
+
};
|
|
55
|
+
function H(n, e = !1, r = "Timeout") {
|
|
56
|
+
return new Promise((t, i) => {
|
|
57
|
+
setTimeout(e ? () => i(r) : t, n);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function ve(...n) {
|
|
61
|
+
if (n.length !== 1)
|
|
62
|
+
return de(...n);
|
|
63
|
+
const e = n[0];
|
|
64
|
+
return typeof e == "function" ? ie(le(() => ({ get: e, set: ge }))) : j(e);
|
|
65
|
+
}
|
|
66
|
+
function Z(n, e = !1) {
|
|
67
|
+
function r(d, { flush: m = "sync", deep: w = !1, timeout: q, throwOnTimeout: c } = {}) {
|
|
68
|
+
let y = null;
|
|
69
|
+
const O = [new Promise((l) => {
|
|
70
|
+
y = W(
|
|
71
|
+
n,
|
|
72
|
+
(h) => {
|
|
73
|
+
d(h) !== e && (y?.(), l(h));
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
flush: m,
|
|
77
|
+
deep: w,
|
|
78
|
+
immediate: !0
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
})];
|
|
82
|
+
return q != null && O.push(
|
|
83
|
+
H(q, c).then(() => D(n)).finally(() => y?.())
|
|
84
|
+
), Promise.race(O);
|
|
85
|
+
}
|
|
86
|
+
function t(d, m) {
|
|
87
|
+
if (!pe(d))
|
|
88
|
+
return r((h) => h === d, m);
|
|
89
|
+
const { flush: w = "sync", deep: q = !1, timeout: c, throwOnTimeout: y } = m ?? {};
|
|
90
|
+
let o = null;
|
|
91
|
+
const l = [new Promise((h) => {
|
|
92
|
+
o = W(
|
|
93
|
+
[n, d],
|
|
94
|
+
([b, x]) => {
|
|
95
|
+
e !== (b === x) && (o?.(), h(b));
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
flush: w,
|
|
99
|
+
deep: q,
|
|
100
|
+
immediate: !0
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
})];
|
|
104
|
+
return c != null && l.push(
|
|
105
|
+
H(c, y).then(() => D(n)).finally(() => (o?.(), D(n)))
|
|
106
|
+
), Promise.race(l);
|
|
107
|
+
}
|
|
108
|
+
function i(d) {
|
|
109
|
+
return r((m) => !!m, d);
|
|
110
|
+
}
|
|
111
|
+
function a(d) {
|
|
112
|
+
return t(null, d);
|
|
113
|
+
}
|
|
114
|
+
function f(d) {
|
|
115
|
+
return t(void 0, d);
|
|
116
|
+
}
|
|
117
|
+
function s(d) {
|
|
118
|
+
return r(Number.isNaN, d);
|
|
119
|
+
}
|
|
120
|
+
function u(d, m) {
|
|
121
|
+
return r((w) => {
|
|
122
|
+
const q = Array.from(w);
|
|
123
|
+
return q.includes(d) || q.includes(D(d));
|
|
124
|
+
}, m);
|
|
125
|
+
}
|
|
126
|
+
function v(d) {
|
|
127
|
+
return g(1, d);
|
|
43
128
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
129
|
+
function g(d = 1, m) {
|
|
130
|
+
let w = -1;
|
|
131
|
+
return r(() => (w += 1, w >= d), m);
|
|
132
|
+
}
|
|
133
|
+
return Array.isArray(D(n)) ? {
|
|
134
|
+
toMatch: r,
|
|
135
|
+
toContains: u,
|
|
136
|
+
changed: v,
|
|
137
|
+
changedTimes: g,
|
|
138
|
+
get not() {
|
|
139
|
+
return Z(n, !e);
|
|
140
|
+
}
|
|
141
|
+
} : {
|
|
142
|
+
toMatch: r,
|
|
143
|
+
toBe: t,
|
|
144
|
+
toBeTruthy: i,
|
|
145
|
+
toBeNull: a,
|
|
146
|
+
toBeNaN: s,
|
|
147
|
+
toBeUndefined: f,
|
|
148
|
+
changed: v,
|
|
149
|
+
changedTimes: g,
|
|
150
|
+
get not() {
|
|
151
|
+
return Z(n, !e);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function we(n) {
|
|
156
|
+
return Z(n);
|
|
157
|
+
}
|
|
158
|
+
function T() {
|
|
159
|
+
return T = Object.assign ? Object.assign.bind() : function(n) {
|
|
160
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
161
|
+
var r = arguments[e];
|
|
162
|
+
for (var t in r)
|
|
163
|
+
Object.prototype.hasOwnProperty.call(r, t) && (n[t] = r[t]);
|
|
164
|
+
}
|
|
165
|
+
return n;
|
|
166
|
+
}, T.apply(this, arguments);
|
|
167
|
+
}
|
|
168
|
+
function qe(n, e) {
|
|
169
|
+
n.prototype = Object.create(e.prototype), n.prototype.constructor = n, I(n, e);
|
|
170
|
+
}
|
|
171
|
+
function C(n) {
|
|
172
|
+
return C = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(r) {
|
|
173
|
+
return r.__proto__ || Object.getPrototypeOf(r);
|
|
174
|
+
}, C(n);
|
|
175
|
+
}
|
|
176
|
+
function I(n, e) {
|
|
177
|
+
return I = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(t, i) {
|
|
178
|
+
return t.__proto__ = i, t;
|
|
179
|
+
}, I(n, e);
|
|
180
|
+
}
|
|
181
|
+
function Fe() {
|
|
182
|
+
if (typeof Reflect > "u" || !Reflect.construct || Reflect.construct.sham)
|
|
183
|
+
return !1;
|
|
184
|
+
if (typeof Proxy == "function")
|
|
185
|
+
return !0;
|
|
186
|
+
try {
|
|
187
|
+
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
|
|
188
|
+
})), !0;
|
|
189
|
+
} catch {
|
|
190
|
+
return !1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function L(n, e, r) {
|
|
194
|
+
return Fe() ? L = Reflect.construct.bind() : L = function(i, a, f) {
|
|
195
|
+
var s = [null];
|
|
196
|
+
s.push.apply(s, a);
|
|
197
|
+
var u = Function.bind.apply(i, s), v = new u();
|
|
198
|
+
return f && I(v, f.prototype), v;
|
|
199
|
+
}, L.apply(null, arguments);
|
|
200
|
+
}
|
|
201
|
+
function be(n) {
|
|
202
|
+
return Function.toString.call(n).indexOf("[native code]") !== -1;
|
|
203
|
+
}
|
|
204
|
+
function Q(n) {
|
|
205
|
+
var e = typeof Map == "function" ? /* @__PURE__ */ new Map() : void 0;
|
|
206
|
+
return Q = function(t) {
|
|
207
|
+
if (t === null || !be(t))
|
|
208
|
+
return t;
|
|
209
|
+
if (typeof t != "function")
|
|
210
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
211
|
+
if (typeof e < "u") {
|
|
212
|
+
if (e.has(t))
|
|
213
|
+
return e.get(t);
|
|
214
|
+
e.set(t, i);
|
|
215
|
+
}
|
|
216
|
+
function i() {
|
|
217
|
+
return L(t, arguments, C(this).constructor);
|
|
218
|
+
}
|
|
219
|
+
return i.prototype = Object.create(t.prototype, {
|
|
220
|
+
constructor: {
|
|
221
|
+
value: i,
|
|
222
|
+
enumerable: !1,
|
|
223
|
+
writable: !0,
|
|
224
|
+
configurable: !0
|
|
225
|
+
}
|
|
226
|
+
}), I(i, t);
|
|
227
|
+
}, Q(n);
|
|
228
|
+
}
|
|
229
|
+
var xe = /%[sdj%]/g, fe = function() {
|
|
230
|
+
};
|
|
231
|
+
typeof process < "u" && process.env && process.env.NODE_ENV !== "production" && typeof window < "u" && typeof document < "u" && (fe = function(e, r) {
|
|
232
|
+
typeof console < "u" && console.warn && typeof ASYNC_VALIDATOR_NO_WARNING > "u" && r.every(function(t) {
|
|
233
|
+
return typeof t == "string";
|
|
234
|
+
}) && console.warn(e, r);
|
|
235
|
+
});
|
|
236
|
+
function Y(n) {
|
|
237
|
+
if (!n || !n.length)
|
|
238
|
+
return null;
|
|
239
|
+
var e = {};
|
|
240
|
+
return n.forEach(function(r) {
|
|
241
|
+
var t = r.field;
|
|
242
|
+
e[t] = e[t] || [], e[t].push(r);
|
|
243
|
+
}), e;
|
|
244
|
+
}
|
|
245
|
+
function A(n) {
|
|
246
|
+
for (var e = arguments.length, r = new Array(e > 1 ? e - 1 : 0), t = 1; t < e; t++)
|
|
247
|
+
r[t - 1] = arguments[t];
|
|
248
|
+
var i = 0, a = r.length;
|
|
249
|
+
if (typeof n == "function")
|
|
250
|
+
return n.apply(null, r);
|
|
251
|
+
if (typeof n == "string") {
|
|
252
|
+
var f = n.replace(xe, function(s) {
|
|
253
|
+
if (s === "%%")
|
|
254
|
+
return "%";
|
|
255
|
+
if (i >= a)
|
|
256
|
+
return s;
|
|
257
|
+
switch (s) {
|
|
258
|
+
case "%s":
|
|
259
|
+
return String(r[i++]);
|
|
260
|
+
case "%d":
|
|
261
|
+
return Number(r[i++]);
|
|
262
|
+
case "%j":
|
|
263
|
+
try {
|
|
264
|
+
return JSON.stringify(r[i++]);
|
|
265
|
+
} catch {
|
|
266
|
+
return "[Circular]";
|
|
267
|
+
}
|
|
268
|
+
break;
|
|
269
|
+
default:
|
|
270
|
+
return s;
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
return f;
|
|
274
|
+
}
|
|
275
|
+
return n;
|
|
276
|
+
}
|
|
277
|
+
function Oe(n) {
|
|
278
|
+
return n === "string" || n === "url" || n === "hex" || n === "email" || n === "date" || n === "pattern";
|
|
279
|
+
}
|
|
280
|
+
function F(n, e) {
|
|
281
|
+
return !!(n == null || e === "array" && Array.isArray(n) && !n.length || Oe(e) && typeof n == "string" && !n);
|
|
282
|
+
}
|
|
283
|
+
function Ae(n, e, r) {
|
|
284
|
+
var t = [], i = 0, a = n.length;
|
|
285
|
+
function f(s) {
|
|
286
|
+
t.push.apply(t, s || []), i++, i === a && r(t);
|
|
287
|
+
}
|
|
288
|
+
n.forEach(function(s) {
|
|
289
|
+
e(s, f);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function X(n, e, r) {
|
|
293
|
+
var t = 0, i = n.length;
|
|
294
|
+
function a(f) {
|
|
295
|
+
if (f && f.length) {
|
|
296
|
+
r(f);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
var s = t;
|
|
300
|
+
t = t + 1, s < i ? e(n[s], a) : r([]);
|
|
301
|
+
}
|
|
302
|
+
a([]);
|
|
303
|
+
}
|
|
304
|
+
function Ee(n) {
|
|
305
|
+
var e = [];
|
|
306
|
+
return Object.keys(n).forEach(function(r) {
|
|
307
|
+
e.push.apply(e, n[r] || []);
|
|
308
|
+
}), e;
|
|
309
|
+
}
|
|
310
|
+
var ee = /* @__PURE__ */ function(n) {
|
|
311
|
+
qe(e, n);
|
|
312
|
+
function e(r, t) {
|
|
313
|
+
var i;
|
|
314
|
+
return i = n.call(this, "Async Validation Error") || this, i.errors = r, i.fields = t, i;
|
|
315
|
+
}
|
|
316
|
+
return e;
|
|
317
|
+
}(/* @__PURE__ */ Q(Error));
|
|
318
|
+
function Pe(n, e, r, t, i) {
|
|
319
|
+
if (e.first) {
|
|
320
|
+
var a = new Promise(function(m, w) {
|
|
321
|
+
var q = function(o) {
|
|
322
|
+
return t(o), o.length ? w(new ee(o, Y(o))) : m(i);
|
|
323
|
+
}, c = Ee(n);
|
|
324
|
+
X(c, r, q);
|
|
325
|
+
});
|
|
326
|
+
return a.catch(function(m) {
|
|
327
|
+
return m;
|
|
328
|
+
}), a;
|
|
329
|
+
}
|
|
330
|
+
var f = e.firstFields === !0 ? Object.keys(n) : e.firstFields || [], s = Object.keys(n), u = s.length, v = 0, g = [], d = new Promise(function(m, w) {
|
|
331
|
+
var q = function(y) {
|
|
332
|
+
if (g.push.apply(g, y), v++, v === u)
|
|
333
|
+
return t(g), g.length ? w(new ee(g, Y(g))) : m(i);
|
|
334
|
+
};
|
|
335
|
+
s.length || (t(g), m(i)), s.forEach(function(c) {
|
|
336
|
+
var y = n[c];
|
|
337
|
+
f.indexOf(c) !== -1 ? X(y, r, q) : Ae(y, r, q);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
return d.catch(function(m) {
|
|
341
|
+
return m;
|
|
342
|
+
}), d;
|
|
343
|
+
}
|
|
344
|
+
function Re(n) {
|
|
345
|
+
return !!(n && n.message !== void 0);
|
|
346
|
+
}
|
|
347
|
+
function je(n, e) {
|
|
348
|
+
for (var r = n, t = 0; t < e.length; t++) {
|
|
349
|
+
if (r == null)
|
|
350
|
+
return r;
|
|
351
|
+
r = r[e[t]];
|
|
352
|
+
}
|
|
353
|
+
return r;
|
|
354
|
+
}
|
|
355
|
+
function re(n, e) {
|
|
356
|
+
return function(r) {
|
|
357
|
+
var t;
|
|
358
|
+
return n.fullFields ? t = je(e, n.fullFields) : t = e[r.field || n.fullField], Re(r) ? (r.field = r.field || n.fullField, r.fieldValue = t, r) : {
|
|
359
|
+
message: typeof r == "function" ? r() : r,
|
|
360
|
+
fieldValue: t,
|
|
361
|
+
field: r.field || n.fullField
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function te(n, e) {
|
|
366
|
+
if (e) {
|
|
367
|
+
for (var r in e)
|
|
368
|
+
if (e.hasOwnProperty(r)) {
|
|
369
|
+
var t = e[r];
|
|
370
|
+
typeof t == "object" && typeof n[r] == "object" ? n[r] = T({}, n[r], t) : n[r] = t;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return n;
|
|
374
|
+
}
|
|
375
|
+
var se = function(e, r, t, i, a, f) {
|
|
376
|
+
e.required && (!t.hasOwnProperty(e.field) || F(r, f || e.type)) && i.push(A(a.messages.required, e.fullField));
|
|
377
|
+
}, _e = function(e, r, t, i, a) {
|
|
378
|
+
(/^\s+$/.test(r) || r === "") && i.push(A(a.messages.whitespace, e.fullField));
|
|
379
|
+
}, U, Te = function() {
|
|
380
|
+
if (U)
|
|
381
|
+
return U;
|
|
382
|
+
var n = "[a-fA-F\\d:]", e = function(h) {
|
|
383
|
+
return h && h.includeBoundaries ? "(?:(?<=\\s|^)(?=" + n + ")|(?<=" + n + ")(?=\\s|$))" : "";
|
|
384
|
+
}, r = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}", t = "[a-fA-F\\d]{1,4}", i = (`
|
|
385
|
+
(?:
|
|
386
|
+
(?:` + t + ":){7}(?:" + t + `|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
387
|
+
(?:` + t + ":){6}(?:" + r + "|:" + t + `|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
388
|
+
(?:` + t + ":){5}(?::" + r + "|(?::" + t + `){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
389
|
+
(?:` + t + ":){4}(?:(?::" + t + "){0,1}:" + r + "|(?::" + t + `){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
390
|
+
(?:` + t + ":){3}(?:(?::" + t + "){0,2}:" + r + "|(?::" + t + `){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
391
|
+
(?:` + t + ":){2}(?:(?::" + t + "){0,3}:" + r + "|(?::" + t + `){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
392
|
+
(?:` + t + ":){1}(?:(?::" + t + "){0,4}:" + r + "|(?::" + t + `){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
393
|
+
(?::(?:(?::` + t + "){0,5}:" + r + "|(?::" + t + `){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
394
|
+
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
395
|
+
`).replace(/\s*\/\/.*$/gm, "").replace(/\n/g, "").trim(), a = new RegExp("(?:^" + r + "$)|(?:^" + i + "$)"), f = new RegExp("^" + r + "$"), s = new RegExp("^" + i + "$"), u = function(h) {
|
|
396
|
+
return h && h.exact ? a : new RegExp("(?:" + e(h) + r + e(h) + ")|(?:" + e(h) + i + e(h) + ")", "g");
|
|
397
|
+
};
|
|
398
|
+
u.v4 = function(l) {
|
|
399
|
+
return l && l.exact ? f : new RegExp("" + e(l) + r + e(l), "g");
|
|
400
|
+
}, u.v6 = function(l) {
|
|
401
|
+
return l && l.exact ? s : new RegExp("" + e(l) + i + e(l), "g");
|
|
402
|
+
};
|
|
403
|
+
var v = "(?:(?:[a-z]+:)?//)", g = "(?:\\S+(?::\\S*)?@)?", d = u.v4().source, m = u.v6().source, w = "(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)", q = "(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*", c = "(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))", y = "(?::\\d{2,5})?", o = '(?:[/?#][^\\s"]*)?', O = "(?:" + v + "|www\\.)" + g + "(?:localhost|" + d + "|" + m + "|" + w + q + c + ")" + y + o;
|
|
404
|
+
return U = new RegExp("(?:^" + O + "$)", "i"), U;
|
|
405
|
+
}, ne = {
|
|
406
|
+
// http://emailregex.com/
|
|
407
|
+
email: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/,
|
|
408
|
+
// url: new RegExp(
|
|
409
|
+
// '^(?!mailto:)(?:(?:http|https|ftp)://|//)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
|
|
410
|
+
// 'i',
|
|
411
|
+
// ),
|
|
412
|
+
hex: /^#?([a-f0-9]{6}|[a-f0-9]{3})$/i
|
|
413
|
+
}, M = {
|
|
414
|
+
integer: function(e) {
|
|
415
|
+
return M.number(e) && parseInt(e, 10) === e;
|
|
416
|
+
},
|
|
417
|
+
float: function(e) {
|
|
418
|
+
return M.number(e) && !M.integer(e);
|
|
419
|
+
},
|
|
420
|
+
array: function(e) {
|
|
421
|
+
return Array.isArray(e);
|
|
422
|
+
},
|
|
423
|
+
regexp: function(e) {
|
|
424
|
+
if (e instanceof RegExp)
|
|
425
|
+
return !0;
|
|
426
|
+
try {
|
|
427
|
+
return !!new RegExp(e);
|
|
428
|
+
} catch {
|
|
429
|
+
return !1;
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
date: function(e) {
|
|
433
|
+
return typeof e.getTime == "function" && typeof e.getMonth == "function" && typeof e.getYear == "function" && !isNaN(e.getTime());
|
|
434
|
+
},
|
|
435
|
+
number: function(e) {
|
|
436
|
+
return isNaN(e) ? !1 : typeof e == "number";
|
|
437
|
+
},
|
|
438
|
+
object: function(e) {
|
|
439
|
+
return typeof e == "object" && !M.array(e);
|
|
440
|
+
},
|
|
441
|
+
method: function(e) {
|
|
442
|
+
return typeof e == "function";
|
|
443
|
+
},
|
|
444
|
+
email: function(e) {
|
|
445
|
+
return typeof e == "string" && e.length <= 320 && !!e.match(ne.email);
|
|
446
|
+
},
|
|
447
|
+
url: function(e) {
|
|
448
|
+
return typeof e == "string" && e.length <= 2048 && !!e.match(Te());
|
|
449
|
+
},
|
|
450
|
+
hex: function(e) {
|
|
451
|
+
return typeof e == "string" && !!e.match(ne.hex);
|
|
452
|
+
}
|
|
453
|
+
}, Ne = function(e, r, t, i, a) {
|
|
454
|
+
if (e.required && r === void 0) {
|
|
455
|
+
se(e, r, t, i, a);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
var f = ["integer", "float", "array", "regexp", "object", "method", "email", "number", "date", "url", "hex"], s = e.type;
|
|
459
|
+
f.indexOf(s) > -1 ? M[s](r) || i.push(A(a.messages.types[s], e.fullField, e.type)) : s && typeof r !== e.type && i.push(A(a.messages.types[s], e.fullField, e.type));
|
|
460
|
+
}, De = function(e, r, t, i, a) {
|
|
461
|
+
var f = typeof e.len == "number", s = typeof e.min == "number", u = typeof e.max == "number", v = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, g = r, d = null, m = typeof r == "number", w = typeof r == "string", q = Array.isArray(r);
|
|
462
|
+
if (m ? d = "number" : w ? d = "string" : q && (d = "array"), !d)
|
|
463
|
+
return !1;
|
|
464
|
+
q && (g = r.length), w && (g = r.replace(v, "_").length), f ? g !== e.len && i.push(A(a.messages[d].len, e.fullField, e.len)) : s && !u && g < e.min ? i.push(A(a.messages[d].min, e.fullField, e.min)) : u && !s && g > e.max ? i.push(A(a.messages[d].max, e.fullField, e.max)) : s && u && (g < e.min || g > e.max) && i.push(A(a.messages[d].range, e.fullField, e.min, e.max));
|
|
465
|
+
}, N = "enum", Ve = function(e, r, t, i, a) {
|
|
466
|
+
e[N] = Array.isArray(e[N]) ? e[N] : [], e[N].indexOf(r) === -1 && i.push(A(a.messages[N], e.fullField, e[N].join(", ")));
|
|
467
|
+
}, $e = function(e, r, t, i, a) {
|
|
468
|
+
if (e.pattern) {
|
|
469
|
+
if (e.pattern instanceof RegExp)
|
|
470
|
+
e.pattern.lastIndex = 0, e.pattern.test(r) || i.push(A(a.messages.pattern.mismatch, e.fullField, r, e.pattern));
|
|
471
|
+
else if (typeof e.pattern == "string") {
|
|
472
|
+
var f = new RegExp(e.pattern);
|
|
473
|
+
f.test(r) || i.push(A(a.messages.pattern.mismatch, e.fullField, r, e.pattern));
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}, p = {
|
|
477
|
+
required: se,
|
|
478
|
+
whitespace: _e,
|
|
479
|
+
type: Ne,
|
|
480
|
+
range: De,
|
|
481
|
+
enum: Ve,
|
|
482
|
+
pattern: $e
|
|
483
|
+
}, Se = function(e, r, t, i, a) {
|
|
484
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
485
|
+
if (s) {
|
|
486
|
+
if (F(r, "string") && !e.required)
|
|
487
|
+
return t();
|
|
488
|
+
p.required(e, r, i, f, a, "string"), F(r, "string") || (p.type(e, r, i, f, a), p.range(e, r, i, f, a), p.pattern(e, r, i, f, a), e.whitespace === !0 && p.whitespace(e, r, i, f, a));
|
|
489
|
+
}
|
|
490
|
+
t(f);
|
|
491
|
+
}, Me = function(e, r, t, i, a) {
|
|
492
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
493
|
+
if (s) {
|
|
494
|
+
if (F(r) && !e.required)
|
|
495
|
+
return t();
|
|
496
|
+
p.required(e, r, i, f, a), r !== void 0 && p.type(e, r, i, f, a);
|
|
497
|
+
}
|
|
498
|
+
t(f);
|
|
499
|
+
}, Be = function(e, r, t, i, a) {
|
|
500
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
501
|
+
if (s) {
|
|
502
|
+
if (r === "" && (r = void 0), F(r) && !e.required)
|
|
503
|
+
return t();
|
|
504
|
+
p.required(e, r, i, f, a), r !== void 0 && (p.type(e, r, i, f, a), p.range(e, r, i, f, a));
|
|
505
|
+
}
|
|
506
|
+
t(f);
|
|
507
|
+
}, Ie = function(e, r, t, i, a) {
|
|
508
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
509
|
+
if (s) {
|
|
510
|
+
if (F(r) && !e.required)
|
|
511
|
+
return t();
|
|
512
|
+
p.required(e, r, i, f, a), r !== void 0 && p.type(e, r, i, f, a);
|
|
513
|
+
}
|
|
514
|
+
t(f);
|
|
515
|
+
}, Ue = function(e, r, t, i, a) {
|
|
516
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
517
|
+
if (s) {
|
|
518
|
+
if (F(r) && !e.required)
|
|
519
|
+
return t();
|
|
520
|
+
p.required(e, r, i, f, a), F(r) || p.type(e, r, i, f, a);
|
|
521
|
+
}
|
|
522
|
+
t(f);
|
|
523
|
+
}, Le = function(e, r, t, i, a) {
|
|
524
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
525
|
+
if (s) {
|
|
526
|
+
if (F(r) && !e.required)
|
|
527
|
+
return t();
|
|
528
|
+
p.required(e, r, i, f, a), r !== void 0 && (p.type(e, r, i, f, a), p.range(e, r, i, f, a));
|
|
529
|
+
}
|
|
530
|
+
t(f);
|
|
531
|
+
}, We = function(e, r, t, i, a) {
|
|
532
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
533
|
+
if (s) {
|
|
534
|
+
if (F(r) && !e.required)
|
|
535
|
+
return t();
|
|
536
|
+
p.required(e, r, i, f, a), r !== void 0 && (p.type(e, r, i, f, a), p.range(e, r, i, f, a));
|
|
537
|
+
}
|
|
538
|
+
t(f);
|
|
539
|
+
}, Je = function(e, r, t, i, a) {
|
|
540
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
541
|
+
if (s) {
|
|
542
|
+
if (r == null && !e.required)
|
|
543
|
+
return t();
|
|
544
|
+
p.required(e, r, i, f, a, "array"), r != null && (p.type(e, r, i, f, a), p.range(e, r, i, f, a));
|
|
545
|
+
}
|
|
546
|
+
t(f);
|
|
547
|
+
}, Ze = function(e, r, t, i, a) {
|
|
548
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
549
|
+
if (s) {
|
|
550
|
+
if (F(r) && !e.required)
|
|
551
|
+
return t();
|
|
552
|
+
p.required(e, r, i, f, a), r !== void 0 && p.type(e, r, i, f, a);
|
|
553
|
+
}
|
|
554
|
+
t(f);
|
|
555
|
+
}, Ce = "enum", Qe = function(e, r, t, i, a) {
|
|
556
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
557
|
+
if (s) {
|
|
558
|
+
if (F(r) && !e.required)
|
|
559
|
+
return t();
|
|
560
|
+
p.required(e, r, i, f, a), r !== void 0 && p[Ce](e, r, i, f, a);
|
|
561
|
+
}
|
|
562
|
+
t(f);
|
|
563
|
+
}, Ye = function(e, r, t, i, a) {
|
|
564
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
565
|
+
if (s) {
|
|
566
|
+
if (F(r, "string") && !e.required)
|
|
567
|
+
return t();
|
|
568
|
+
p.required(e, r, i, f, a), F(r, "string") || p.pattern(e, r, i, f, a);
|
|
569
|
+
}
|
|
570
|
+
t(f);
|
|
571
|
+
}, ze = function(e, r, t, i, a) {
|
|
572
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
573
|
+
if (s) {
|
|
574
|
+
if (F(r, "date") && !e.required)
|
|
575
|
+
return t();
|
|
576
|
+
if (p.required(e, r, i, f, a), !F(r, "date")) {
|
|
577
|
+
var u;
|
|
578
|
+
r instanceof Date ? u = r : u = new Date(r), p.type(e, u, i, f, a), u && p.range(e, u.getTime(), i, f, a);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
t(f);
|
|
582
|
+
}, Ge = function(e, r, t, i, a) {
|
|
583
|
+
var f = [], s = Array.isArray(r) ? "array" : typeof r;
|
|
584
|
+
p.required(e, r, i, f, a, s), t(f);
|
|
585
|
+
}, J = function(e, r, t, i, a) {
|
|
586
|
+
var f = e.type, s = [], u = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
587
|
+
if (u) {
|
|
588
|
+
if (F(r, f) && !e.required)
|
|
589
|
+
return t();
|
|
590
|
+
p.required(e, r, i, s, a, f), F(r, f) || p.type(e, r, i, s, a);
|
|
591
|
+
}
|
|
592
|
+
t(s);
|
|
593
|
+
}, Ke = function(e, r, t, i, a) {
|
|
594
|
+
var f = [], s = e.required || !e.required && i.hasOwnProperty(e.field);
|
|
595
|
+
if (s) {
|
|
596
|
+
if (F(r) && !e.required)
|
|
597
|
+
return t();
|
|
598
|
+
p.required(e, r, i, f, a);
|
|
599
|
+
}
|
|
600
|
+
t(f);
|
|
601
|
+
}, B = {
|
|
602
|
+
string: Se,
|
|
603
|
+
method: Me,
|
|
604
|
+
number: Be,
|
|
605
|
+
boolean: Ie,
|
|
606
|
+
regexp: Ue,
|
|
607
|
+
integer: Le,
|
|
608
|
+
float: We,
|
|
609
|
+
array: Je,
|
|
610
|
+
object: Ze,
|
|
611
|
+
enum: Qe,
|
|
612
|
+
pattern: Ye,
|
|
613
|
+
date: ze,
|
|
614
|
+
url: J,
|
|
615
|
+
hex: J,
|
|
616
|
+
email: J,
|
|
617
|
+
required: Ge,
|
|
618
|
+
any: Ke
|
|
619
|
+
};
|
|
620
|
+
function z() {
|
|
621
|
+
return {
|
|
622
|
+
default: "Validation error on field %s",
|
|
623
|
+
required: "%s is required",
|
|
624
|
+
enum: "%s must be one of %s",
|
|
625
|
+
whitespace: "%s cannot be empty",
|
|
626
|
+
date: {
|
|
627
|
+
format: "%s date %s is invalid for format %s",
|
|
628
|
+
parse: "%s date could not be parsed, %s is invalid ",
|
|
629
|
+
invalid: "%s date %s is invalid"
|
|
630
|
+
},
|
|
631
|
+
types: {
|
|
632
|
+
string: "%s is not a %s",
|
|
633
|
+
method: "%s is not a %s (function)",
|
|
634
|
+
array: "%s is not an %s",
|
|
635
|
+
object: "%s is not an %s",
|
|
636
|
+
number: "%s is not a %s",
|
|
637
|
+
date: "%s is not a %s",
|
|
638
|
+
boolean: "%s is not a %s",
|
|
639
|
+
integer: "%s is not an %s",
|
|
640
|
+
float: "%s is not a %s",
|
|
641
|
+
regexp: "%s is not a valid %s",
|
|
642
|
+
email: "%s is not a valid %s",
|
|
643
|
+
url: "%s is not a valid %s",
|
|
644
|
+
hex: "%s is not a valid %s"
|
|
645
|
+
},
|
|
646
|
+
string: {
|
|
647
|
+
len: "%s must be exactly %s characters",
|
|
648
|
+
min: "%s must be at least %s characters",
|
|
649
|
+
max: "%s cannot be longer than %s characters",
|
|
650
|
+
range: "%s must be between %s and %s characters"
|
|
651
|
+
},
|
|
652
|
+
number: {
|
|
653
|
+
len: "%s must equal %s",
|
|
654
|
+
min: "%s cannot be less than %s",
|
|
655
|
+
max: "%s cannot be greater than %s",
|
|
656
|
+
range: "%s must be between %s and %s"
|
|
657
|
+
},
|
|
658
|
+
array: {
|
|
659
|
+
len: "%s must be exactly %s in length",
|
|
660
|
+
min: "%s cannot be less than %s in length",
|
|
661
|
+
max: "%s cannot be greater than %s in length",
|
|
662
|
+
range: "%s must be between %s and %s in length"
|
|
663
|
+
},
|
|
664
|
+
pattern: {
|
|
665
|
+
mismatch: "%s value %s does not match pattern %s"
|
|
666
|
+
},
|
|
667
|
+
clone: function() {
|
|
668
|
+
var e = JSON.parse(JSON.stringify(this));
|
|
669
|
+
return e.clone = this.clone, e;
|
|
670
|
+
}
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
var G = z(), $ = /* @__PURE__ */ function() {
|
|
674
|
+
function n(r) {
|
|
675
|
+
this.rules = null, this._messages = G, this.define(r);
|
|
676
|
+
}
|
|
677
|
+
var e = n.prototype;
|
|
678
|
+
return e.define = function(t) {
|
|
679
|
+
var i = this;
|
|
680
|
+
if (!t)
|
|
681
|
+
throw new Error("Cannot configure a schema with no rules");
|
|
682
|
+
if (typeof t != "object" || Array.isArray(t))
|
|
683
|
+
throw new Error("Rules must be an object");
|
|
684
|
+
this.rules = {}, Object.keys(t).forEach(function(a) {
|
|
685
|
+
var f = t[a];
|
|
686
|
+
i.rules[a] = Array.isArray(f) ? f : [f];
|
|
687
|
+
});
|
|
688
|
+
}, e.messages = function(t) {
|
|
689
|
+
return t && (this._messages = te(z(), t)), this._messages;
|
|
690
|
+
}, e.validate = function(t, i, a) {
|
|
691
|
+
var f = this;
|
|
692
|
+
i === void 0 && (i = {}), a === void 0 && (a = function() {
|
|
693
|
+
});
|
|
694
|
+
var s = t, u = i, v = a;
|
|
695
|
+
if (typeof u == "function" && (v = u, u = {}), !this.rules || Object.keys(this.rules).length === 0)
|
|
696
|
+
return v && v(null, s), Promise.resolve(s);
|
|
697
|
+
function g(c) {
|
|
698
|
+
var y = [], o = {};
|
|
699
|
+
function O(h) {
|
|
700
|
+
if (Array.isArray(h)) {
|
|
701
|
+
var b;
|
|
702
|
+
y = (b = y).concat.apply(b, h);
|
|
703
|
+
} else
|
|
704
|
+
y.push(h);
|
|
705
|
+
}
|
|
706
|
+
for (var l = 0; l < c.length; l++)
|
|
707
|
+
O(c[l]);
|
|
708
|
+
y.length ? (o = Y(y), v(y, o)) : v(null, s);
|
|
709
|
+
}
|
|
710
|
+
if (u.messages) {
|
|
711
|
+
var d = this.messages();
|
|
712
|
+
d === G && (d = z()), te(d, u.messages), u.messages = d;
|
|
713
|
+
} else
|
|
714
|
+
u.messages = this.messages();
|
|
715
|
+
var m = {}, w = u.keys || Object.keys(this.rules);
|
|
716
|
+
w.forEach(function(c) {
|
|
717
|
+
var y = f.rules[c], o = s[c];
|
|
718
|
+
y.forEach(function(O) {
|
|
719
|
+
var l = O;
|
|
720
|
+
typeof l.transform == "function" && (s === t && (s = T({}, s)), o = s[c] = l.transform(o)), typeof l == "function" ? l = {
|
|
721
|
+
validator: l
|
|
722
|
+
} : l = T({}, l), l.validator = f.getValidationMethod(l), l.validator && (l.field = c, l.fullField = l.fullField || c, l.type = f.getType(l), m[c] = m[c] || [], m[c].push({
|
|
723
|
+
rule: l,
|
|
724
|
+
value: o,
|
|
725
|
+
source: s,
|
|
726
|
+
field: c
|
|
727
|
+
}));
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
var q = {};
|
|
731
|
+
return Pe(m, u, function(c, y) {
|
|
732
|
+
var o = c.rule, O = (o.type === "object" || o.type === "array") && (typeof o.fields == "object" || typeof o.defaultField == "object");
|
|
733
|
+
O = O && (o.required || !o.required && c.value), o.field = c.field;
|
|
734
|
+
function l(x, _) {
|
|
735
|
+
return T({}, _, {
|
|
736
|
+
fullField: o.fullField + "." + x,
|
|
737
|
+
fullFields: o.fullFields ? [].concat(o.fullFields, [x]) : [x]
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
function h(x) {
|
|
741
|
+
x === void 0 && (x = []);
|
|
742
|
+
var _ = Array.isArray(x) ? x : [x];
|
|
743
|
+
!u.suppressWarning && _.length && n.warning("async-validator:", _), _.length && o.message !== void 0 && (_ = [].concat(o.message));
|
|
744
|
+
var P = _.map(re(o, s));
|
|
745
|
+
if (u.first && P.length)
|
|
746
|
+
return q[o.field] = 1, y(P);
|
|
747
|
+
if (!O)
|
|
748
|
+
y(P);
|
|
749
|
+
else {
|
|
750
|
+
if (o.required && !c.value)
|
|
751
|
+
return o.message !== void 0 ? P = [].concat(o.message).map(re(o, s)) : u.error && (P = [u.error(o, A(u.messages.required, o.field))]), y(P);
|
|
752
|
+
var S = {};
|
|
753
|
+
o.defaultField && Object.keys(c.value).map(function(R) {
|
|
754
|
+
S[R] = o.defaultField;
|
|
755
|
+
}), S = T({}, S, c.rule.fields);
|
|
756
|
+
var K = {};
|
|
757
|
+
Object.keys(S).forEach(function(R) {
|
|
758
|
+
var E = S[R], ue = Array.isArray(E) ? E : [E];
|
|
759
|
+
K[R] = ue.map(l.bind(null, R));
|
|
760
|
+
});
|
|
761
|
+
var k = new n(K);
|
|
762
|
+
k.messages(u.messages), c.rule.options && (c.rule.options.messages = u.messages, c.rule.options.error = u.error), k.validate(c.value, c.rule.options || u, function(R) {
|
|
763
|
+
var E = [];
|
|
764
|
+
P && P.length && E.push.apply(E, P), R && R.length && E.push.apply(E, R), y(E.length ? E : null);
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
var b;
|
|
769
|
+
if (o.asyncValidator)
|
|
770
|
+
b = o.asyncValidator(o, c.value, h, c.source, u);
|
|
771
|
+
else if (o.validator) {
|
|
772
|
+
try {
|
|
773
|
+
b = o.validator(o, c.value, h, c.source, u);
|
|
774
|
+
} catch (x) {
|
|
775
|
+
console.error?.(x), u.suppressValidatorError || setTimeout(function() {
|
|
776
|
+
throw x;
|
|
777
|
+
}, 0), h(x.message);
|
|
778
|
+
}
|
|
779
|
+
b === !0 ? h() : b === !1 ? h(typeof o.message == "function" ? o.message(o.fullField || o.field) : o.message || (o.fullField || o.field) + " fails") : b instanceof Array ? h(b) : b instanceof Error && h(b.message);
|
|
780
|
+
}
|
|
781
|
+
b && b.then && b.then(function() {
|
|
782
|
+
return h();
|
|
783
|
+
}, function(x) {
|
|
784
|
+
return h(x);
|
|
785
|
+
});
|
|
786
|
+
}, function(c) {
|
|
787
|
+
g(c);
|
|
788
|
+
}, s);
|
|
789
|
+
}, e.getType = function(t) {
|
|
790
|
+
if (t.type === void 0 && t.pattern instanceof RegExp && (t.type = "pattern"), typeof t.validator != "function" && t.type && !B.hasOwnProperty(t.type))
|
|
791
|
+
throw new Error(A("Unknown rule type %s", t.type));
|
|
792
|
+
return t.type || "string";
|
|
793
|
+
}, e.getValidationMethod = function(t) {
|
|
794
|
+
if (typeof t.validator == "function")
|
|
795
|
+
return t.validator;
|
|
796
|
+
var i = Object.keys(t), a = i.indexOf("message");
|
|
797
|
+
return a !== -1 && i.splice(a, 1), i.length === 1 && i[0] === "required" ? B.required : B[this.getType(t)] || void 0;
|
|
798
|
+
}, n;
|
|
799
|
+
}();
|
|
800
|
+
$.register = function(e, r) {
|
|
801
|
+
if (typeof r != "function")
|
|
802
|
+
throw new Error("Cannot register a validator by type, validator is not a function");
|
|
803
|
+
B[e] = r;
|
|
804
|
+
};
|
|
805
|
+
$.warning = fe;
|
|
806
|
+
$.messages = G;
|
|
807
|
+
$.validators = B;
|
|
808
|
+
const ke = $.default || $;
|
|
809
|
+
function He(n, e, r = {}) {
|
|
810
|
+
const {
|
|
811
|
+
validateOption: t = {},
|
|
812
|
+
immediate: i = !0,
|
|
813
|
+
manual: a = !1
|
|
814
|
+
} = r, f = ve(n), s = ye(null), u = j(!0), v = j(!i || a), g = V(() => s.value?.errors || []), d = V(() => s.value?.fields || {}), m = V(() => new ke(D(e))), w = async () => {
|
|
815
|
+
u.value = !1, v.value = !1;
|
|
816
|
+
try {
|
|
817
|
+
await m.value.validate(f.value, t), v.value = !0, s.value = null;
|
|
818
|
+
} catch (y) {
|
|
819
|
+
s.value = y;
|
|
820
|
+
} finally {
|
|
821
|
+
u.value = !0;
|
|
822
|
+
}
|
|
823
|
+
return {
|
|
824
|
+
pass: v.value,
|
|
825
|
+
errorInfo: s.value,
|
|
826
|
+
errors: g.value,
|
|
827
|
+
errorFields: d.value
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
a || W(
|
|
831
|
+
[f, m],
|
|
832
|
+
() => w(),
|
|
833
|
+
{ immediate: i, deep: !0 }
|
|
834
|
+
);
|
|
835
|
+
const q = {
|
|
836
|
+
isFinished: u,
|
|
837
|
+
pass: v,
|
|
838
|
+
errors: g,
|
|
839
|
+
errorInfo: s,
|
|
840
|
+
errorFields: d,
|
|
841
|
+
execute: w
|
|
842
|
+
};
|
|
843
|
+
function c() {
|
|
844
|
+
return new Promise((y, o) => {
|
|
845
|
+
we(u).toBe(!0).then(() => y(q)).catch((O) => o(O));
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
return {
|
|
849
|
+
...q,
|
|
850
|
+
then(y, o) {
|
|
851
|
+
return c().then(y, o);
|
|
852
|
+
}
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function sr(n, e) {
|
|
856
|
+
const { errorFields: r, isFinished: t, pass: i } = He(n, e, {
|
|
857
|
+
validateOption: { suppressWarning: !0 }
|
|
858
|
+
}), a = j(0);
|
|
859
|
+
function f() {
|
|
860
|
+
return a.value++, i.value && t.value;
|
|
861
|
+
}
|
|
862
|
+
const s = V(() => a.value ? r.value : void 0);
|
|
863
|
+
function u(v) {
|
|
864
|
+
return s.value?.[v]?.[0]?.message;
|
|
865
|
+
}
|
|
866
|
+
return {
|
|
867
|
+
error: u,
|
|
868
|
+
errors: s,
|
|
869
|
+
isValid: f
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
const oe = j(!1), or = ie(oe);
|
|
873
|
+
function Xe(n) {
|
|
874
|
+
oe.value = n;
|
|
875
|
+
}
|
|
876
|
+
function ur(n, e, r) {
|
|
877
|
+
rr(r), e(), window.location.href = n;
|
|
878
|
+
}
|
|
879
|
+
function er(n, e) {
|
|
880
|
+
document.cookie = `${e}=${n};Secure;samesite=strict;`;
|
|
881
|
+
}
|
|
882
|
+
function cr(n) {
|
|
883
|
+
const { [n]: e } = Object.fromEntries(document.cookie.split("; ").map((r) => r.split("=")));
|
|
884
|
+
return e;
|
|
885
|
+
}
|
|
886
|
+
function rr(n) {
|
|
887
|
+
document.cookie = `${n}=;expires=${(/* @__PURE__ */ new Date(0)).toUTCString()}`;
|
|
888
|
+
}
|
|
889
|
+
function dr() {
|
|
890
|
+
const n = ae();
|
|
891
|
+
function e(r, t, i, a) {
|
|
892
|
+
er(r, a), i(r), Xe(!0), n.push(t);
|
|
46
893
|
}
|
|
47
|
-
return {
|
|
894
|
+
return {
|
|
895
|
+
auth: e
|
|
896
|
+
};
|
|
48
897
|
}
|
|
49
|
-
function
|
|
50
|
-
return structuredClone(
|
|
898
|
+
function lr(n) {
|
|
899
|
+
return structuredClone(me(n));
|
|
51
900
|
}
|
|
52
|
-
function
|
|
53
|
-
return
|
|
901
|
+
function pr(n) {
|
|
902
|
+
return n ? new Intl.DateTimeFormat().format(new Date(n)) : "-";
|
|
54
903
|
}
|
|
55
|
-
function
|
|
56
|
-
return
|
|
904
|
+
function yr(n) {
|
|
905
|
+
return n ? new Intl.DateTimeFormat(void 0, {
|
|
57
906
|
year: "numeric",
|
|
58
907
|
month: "numeric",
|
|
59
908
|
day: "numeric",
|
|
60
909
|
hour: "numeric",
|
|
61
910
|
minute: "numeric"
|
|
62
|
-
}).format(new Date(
|
|
911
|
+
}).format(new Date(n)) : "-";
|
|
63
912
|
}
|
|
64
|
-
function
|
|
913
|
+
function mr() {
|
|
65
914
|
return `temp-${crypto.randomUUID()}`;
|
|
66
915
|
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
916
|
+
function hr(n) {
|
|
917
|
+
return n.map((e) => (e._id?.includes("temp") && delete e._id, e));
|
|
69
918
|
}
|
|
70
|
-
function
|
|
71
|
-
return
|
|
919
|
+
function gr(n) {
|
|
920
|
+
return n.map((e) => (delete e._id, e));
|
|
72
921
|
}
|
|
922
|
+
const vr = { required: !0 }, wr = { type: "email" };
|
|
73
923
|
export {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
924
|
+
lr as clone,
|
|
925
|
+
mr as createTempId,
|
|
926
|
+
rr as deleteCookieToken,
|
|
927
|
+
gr as deleteId,
|
|
928
|
+
hr as deleteTempId,
|
|
929
|
+
wr as email,
|
|
930
|
+
pr as formatDate,
|
|
931
|
+
yr as formatDateTime,
|
|
932
|
+
cr as getCookieToken,
|
|
933
|
+
or as isAuth,
|
|
934
|
+
ur as logout,
|
|
935
|
+
vr as required,
|
|
936
|
+
Xe as setAuth,
|
|
937
|
+
er as setCookieToken,
|
|
938
|
+
dr as useAuth,
|
|
939
|
+
fr as useInfiniteScroll,
|
|
940
|
+
ar as usePage,
|
|
941
|
+
ir as usePagination,
|
|
942
|
+
sr as useValidator
|
|
83
943
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mhz-helpers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "mhz-helpers",
|
|
5
5
|
"author": "dergunov.com",
|
|
6
6
|
"type": "module",
|
|
@@ -16,15 +16,18 @@
|
|
|
16
16
|
"ts": "vue-tsc --noEmit"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
+
"@vueuse/core": "10.4.0",
|
|
20
|
+
"@vueuse/integrations": "10.4.0",
|
|
21
|
+
"async-validator": "4.2.5",
|
|
19
22
|
"vue": "3.3.4",
|
|
20
23
|
"vue-router": "4.2.4"
|
|
21
24
|
},
|
|
22
25
|
"devDependencies": {
|
|
23
|
-
"@types/node": "20.5.
|
|
26
|
+
"@types/node": "20.5.6",
|
|
24
27
|
"@typescript-eslint/eslint-plugin": "6.4.1",
|
|
25
28
|
"@typescript-eslint/parser": "6.4.1",
|
|
26
29
|
"@vitejs/plugin-vue": "4.3.3",
|
|
27
|
-
"eslint": "8.
|
|
30
|
+
"eslint": "8.48.0",
|
|
28
31
|
"eslint-config-prettier": "9.0.0",
|
|
29
32
|
"eslint-import-resolver-typescript": "3.6.0",
|
|
30
33
|
"eslint-plugin-import": "2.28.1",
|
|
@@ -37,7 +40,7 @@
|
|
|
37
40
|
"stylelint-config-recommended-scss": "12.0.0",
|
|
38
41
|
"stylelint-config-recommended-vue": "1.5.0",
|
|
39
42
|
"stylelint-prettier": "4.0.2",
|
|
40
|
-
"typescript": "5.
|
|
43
|
+
"typescript": "5.2.2",
|
|
41
44
|
"vite": "4.4.9",
|
|
42
45
|
"vite-plugin-dts": "3.5.2",
|
|
43
46
|
"vue-linters-config": "0.1.6",
|