@kklab/fortress-validator 1.0.15 → 1.0.17
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 +6 -2
- package/dist/FieldValidator.d.ts +18 -2
- package/dist/index.js +149 -101
- package/dist/index.umd.js +1 -1
- package/dist/rules/notEndsWith.d.ts +6 -0
- package/dist/rules/notStartsWith.d.ts +6 -0
- package/dist/rules/notStartsWithNumber.d.ts +3 -0
- package/dist/rules/startsWith.d.ts +2 -2
- package/dist/rules/startsWithNumber.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ const result = validator
|
|
|
87
87
|
| `date` | Passes if the field's value matches the specified date format. |
|
|
88
88
|
| `declined` | Passes if the field's value is considered declined (i.e., "n", "no", "off", "0", "false"). |
|
|
89
89
|
| `different` | Passes if the field's value is different from the specified value in the given field. |
|
|
90
|
-
| `distinct` | Passes if
|
|
90
|
+
| `distinct` | Passes if the field's value contains only unique items. |
|
|
91
91
|
| `domain` | Passes if the field's value is a valid domain. |
|
|
92
92
|
| `email` | Passes if the field's value is a valid email address. |
|
|
93
93
|
| `endsWith` | Passes if the field's value ends with the specified value. |
|
|
@@ -116,8 +116,11 @@ const result = validator
|
|
|
116
116
|
| `lte` | Passes if the field's value is less than or equal to the specified value. |
|
|
117
117
|
| `notContainsAll` | Passes if the field's value does not contain all of the specified values together. |
|
|
118
118
|
| `notContainsAny` | Passes if the field's value does not contain any of the specified values. |
|
|
119
|
+
| `notEndsWith` | Passes if the field's value does not end with the specified value. |
|
|
119
120
|
| `notEquals` | Passes if the field's value is not equal to the specified value. |
|
|
120
121
|
| `notOneOf` | Passes if the field's value is not one of the specified values. |
|
|
122
|
+
| `notStartsWith` | Passes if the field's value does not start with the specified value. |
|
|
123
|
+
| `notStartsWithNumber` | Passes if the field's value does not start with a number. |
|
|
121
124
|
| `notSubsetOf` | Passes if the field's value is not a subset of the specified values. |
|
|
122
125
|
| `number` | Passes if the field's value is a number. |
|
|
123
126
|
| `numeric` | Passes if the field's value contains only numeric characters. |
|
|
@@ -130,6 +133,7 @@ const result = validator
|
|
|
130
133
|
| `same` | Passes if the field's value is the same as the specified value in the given field. |
|
|
131
134
|
| `size` | Passes if the field's value matches the specified size. |
|
|
132
135
|
| `startsWith` | Passes if the field's value starts with the specified value. |
|
|
136
|
+
| `startsWithNumber` | Passes if the field's value starts with a number. |
|
|
133
137
|
| `string` | Passes if the field's value is a string. |
|
|
134
138
|
| `stringContainsAll` | Passes if the field's value contains all of the specified text. |
|
|
135
139
|
| `stringContainsAny` | Passes if the field's value contains at least one of the specified text. |
|
|
@@ -142,7 +146,7 @@ const result = validator
|
|
|
142
146
|
| `stringNotContainsAll` | Passes if the field's value does not contain all of the specified text together. |
|
|
143
147
|
| `stringNotContainsAny` | Passes if the field's value does not contain any of the specified text. |
|
|
144
148
|
| `subsetOf` | Passes if the field's value is a subset of the specified values. |
|
|
145
|
-
| `unique` | Passes if the field's value
|
|
149
|
+
| `unique` | Passes if the field's value does not exist in the provided values. |
|
|
146
150
|
| `uppercase` | Passes if the field's value contains only uppercase characters. |
|
|
147
151
|
| `url` | Passes if the field's value is a valid URL. |
|
|
148
152
|
|
package/dist/FieldValidator.d.ts
CHANGED
|
@@ -122,7 +122,7 @@ declare class FieldValidator {
|
|
|
122
122
|
*/
|
|
123
123
|
different(field: string, value: unknown): this;
|
|
124
124
|
/**
|
|
125
|
-
* Passes if
|
|
125
|
+
* Passes if the field's value contains only unique items.
|
|
126
126
|
*/
|
|
127
127
|
distinct(): this;
|
|
128
128
|
/**
|
|
@@ -237,6 +237,10 @@ declare class FieldValidator {
|
|
|
237
237
|
* Passes if the field's value does not contain any of the specified values.
|
|
238
238
|
*/
|
|
239
239
|
notContainsAny(values: unknown[]): this;
|
|
240
|
+
/**
|
|
241
|
+
* Passes if the field's value does not end with the specified value.
|
|
242
|
+
*/
|
|
243
|
+
notEndsWith(value: string): this;
|
|
240
244
|
/**
|
|
241
245
|
* Passes if the field's value is not equal to the specified value.
|
|
242
246
|
*/
|
|
@@ -245,6 +249,14 @@ declare class FieldValidator {
|
|
|
245
249
|
* Passes if the field's value is not one of the specified values.
|
|
246
250
|
*/
|
|
247
251
|
notOneOf(values: string[]): this;
|
|
252
|
+
/**
|
|
253
|
+
* Passes if the field's value does not start with the specified value.
|
|
254
|
+
*/
|
|
255
|
+
notStartsWith(value: string): this;
|
|
256
|
+
/**
|
|
257
|
+
* Passes if the field's value does not start with a number.
|
|
258
|
+
*/
|
|
259
|
+
notStartsWithNumber(): this;
|
|
248
260
|
/**
|
|
249
261
|
* Passes if the field's value is not a subset of the specified values.
|
|
250
262
|
*/
|
|
@@ -293,6 +305,10 @@ declare class FieldValidator {
|
|
|
293
305
|
* Passes if the field's value starts with the specified value.
|
|
294
306
|
*/
|
|
295
307
|
startsWith(value: string): this;
|
|
308
|
+
/**
|
|
309
|
+
* Passes if the field's value starts with a number.
|
|
310
|
+
*/
|
|
311
|
+
startsWithNumber(): this;
|
|
296
312
|
/**
|
|
297
313
|
* Passes if the field's value is a string.
|
|
298
314
|
*/
|
|
@@ -342,7 +358,7 @@ declare class FieldValidator {
|
|
|
342
358
|
*/
|
|
343
359
|
subsetOf(values: string[]): this;
|
|
344
360
|
/**
|
|
345
|
-
* Passes if the field's value
|
|
361
|
+
* Passes if the field's value does not exist in the provided values.
|
|
346
362
|
*/
|
|
347
363
|
unique(values: string[], ignored?: unknown[] | unknown): this;
|
|
348
364
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var D = Object.defineProperty;
|
|
2
2
|
var P = (t, e, r) => e in t ? D(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
3
|
var o = (t, e, r) => (P(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
|
-
const
|
|
4
|
+
const L = (t) => {
|
|
5
5
|
const e = ",、;:!?。()《》「」『』【】〔〕", r = "\\x20-\\x7E", a = new RegExp(`\\s*([${e}])`, "gu"), l = new RegExp(`([${e}])\\s*([${r}])`, "gu"), u = new RegExp(`([^${r}${e}])([${r}])`, "gu"), E = new RegExp(`([${r}])([^${r}${e}])`, "gu");
|
|
6
6
|
return t.replace(a, "$1").replace(l, "$1$2").replace(u, "$1 $2").replace(E, "$1 $2").replace(/ +/g, " ");
|
|
7
7
|
}, n = (t, e = 0) => new Intl.NumberFormat(void 0, {
|
|
8
8
|
minimumFractionDigits: e,
|
|
9
9
|
maximumFractionDigits: e
|
|
10
|
-
}).format(t),
|
|
11
|
-
class
|
|
10
|
+
}).format(t), I = (t) => Object.prototype.toString.call(t).toLowerCase().slice(8, -1), s = (t) => t == null || t === "" || Array.isArray(t) && t.length < 1, i = (t) => `"${t}"`;
|
|
11
|
+
class K {
|
|
12
12
|
constructor({
|
|
13
13
|
name: e,
|
|
14
14
|
locale: r,
|
|
@@ -64,12 +64,12 @@ class W {
|
|
|
64
64
|
buildRuleFunctionMessage(e, r, a) {
|
|
65
65
|
const l = this.getMessage(e)(this.formattedName, r);
|
|
66
66
|
if (typeof l == "object") {
|
|
67
|
-
const u =
|
|
67
|
+
const u = I(a);
|
|
68
68
|
if (!(u in l))
|
|
69
69
|
throw new Error(`The message for the "${e}" rule of the "${u}" type is missing.`);
|
|
70
|
-
return
|
|
70
|
+
return L(l[u]);
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return L(l);
|
|
73
73
|
}
|
|
74
74
|
pushRuleFunction(e, r) {
|
|
75
75
|
if (e in this.conditions && !this.conditions[e])
|
|
@@ -239,7 +239,7 @@ class W {
|
|
|
239
239
|
return this.apply(this.different.name, { field: e, value: r });
|
|
240
240
|
}
|
|
241
241
|
/**
|
|
242
|
-
* Passes if
|
|
242
|
+
* Passes if the field's value contains only unique items.
|
|
243
243
|
*/
|
|
244
244
|
distinct() {
|
|
245
245
|
return this.apply(this.distinct.name);
|
|
@@ -415,6 +415,12 @@ class W {
|
|
|
415
415
|
notContainsAny(e) {
|
|
416
416
|
return this.apply(this.notContainsAny.name, { values: e });
|
|
417
417
|
}
|
|
418
|
+
/**
|
|
419
|
+
* Passes if the field's value does not end with the specified value.
|
|
420
|
+
*/
|
|
421
|
+
notEndsWith(e) {
|
|
422
|
+
return this.apply(this.notEndsWith.name, { value: e });
|
|
423
|
+
}
|
|
418
424
|
/**
|
|
419
425
|
* Passes if the field's value is not equal to the specified value.
|
|
420
426
|
*/
|
|
@@ -427,6 +433,18 @@ class W {
|
|
|
427
433
|
notOneOf(e) {
|
|
428
434
|
return this.apply(this.notOneOf.name, { values: e });
|
|
429
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Passes if the field's value does not start with the specified value.
|
|
438
|
+
*/
|
|
439
|
+
notStartsWith(e) {
|
|
440
|
+
return this.apply(this.notStartsWith.name, { value: e });
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Passes if the field's value does not start with a number.
|
|
444
|
+
*/
|
|
445
|
+
notStartsWithNumber() {
|
|
446
|
+
return this.apply(this.notStartsWithNumber.name);
|
|
447
|
+
}
|
|
430
448
|
/**
|
|
431
449
|
* Passes if the field's value is not a subset of the specified values.
|
|
432
450
|
*/
|
|
@@ -500,6 +518,12 @@ class W {
|
|
|
500
518
|
startsWith(e) {
|
|
501
519
|
return this.apply(this.startsWith.name, { value: e });
|
|
502
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
* Passes if the field's value starts with a number.
|
|
523
|
+
*/
|
|
524
|
+
startsWithNumber() {
|
|
525
|
+
return this.apply(this.startsWithNumber.name);
|
|
526
|
+
}
|
|
503
527
|
/**
|
|
504
528
|
* Passes if the field's value is a string.
|
|
505
529
|
*/
|
|
@@ -573,7 +597,7 @@ class W {
|
|
|
573
597
|
return this.apply(this.subsetOf.name, { values: e });
|
|
574
598
|
}
|
|
575
599
|
/**
|
|
576
|
-
* Passes if the field's value
|
|
600
|
+
* Passes if the field's value does not exist in the provided values.
|
|
577
601
|
*/
|
|
578
602
|
unique(e, r = []) {
|
|
579
603
|
return this.apply(this.unique.name, { values: e, ignored: r });
|
|
@@ -597,7 +621,7 @@ class W {
|
|
|
597
621
|
return typeof e == "object" ? (this.conditions = e, this) : (e || (this.shouldSkip = !0), this);
|
|
598
622
|
}
|
|
599
623
|
}
|
|
600
|
-
const
|
|
624
|
+
const Z = {
|
|
601
625
|
accepted: (t) => `The ${t} field must be accepted.`,
|
|
602
626
|
alpha: (t) => `The ${t} field must only contain letters.`,
|
|
603
627
|
alphaDash: (t) => `The ${t} field must only contain letters, numbers, dashes and underscores.`,
|
|
@@ -655,7 +679,7 @@ const I = {
|
|
|
655
679
|
email: (t) => `The ${t} field must be a valid email address.`,
|
|
656
680
|
endsWith: (t, e) => {
|
|
657
681
|
const { value: r } = e;
|
|
658
|
-
return `The ${t} field must end with ${r}.`;
|
|
682
|
+
return `The ${t} field must end with ${i(r)}.`;
|
|
659
683
|
},
|
|
660
684
|
equals: (t, e) => {
|
|
661
685
|
const { value: r } = e;
|
|
@@ -745,6 +769,10 @@ const I = {
|
|
|
745
769
|
const { values: r } = e;
|
|
746
770
|
return `The ${t} field must not contain all of the following values together: ${r.map(i).join(", ")}.`;
|
|
747
771
|
},
|
|
772
|
+
notEndsWith: (t, e) => {
|
|
773
|
+
const { value: r } = e;
|
|
774
|
+
return `The ${t} field must not end with ${i(r)}.`;
|
|
775
|
+
},
|
|
748
776
|
notContainsAny: (t, e) => {
|
|
749
777
|
const { values: r } = e;
|
|
750
778
|
return `The ${t} field must not contain any of the following values: ${r.map(i).join(", ")}.`;
|
|
@@ -757,6 +785,11 @@ const I = {
|
|
|
757
785
|
const { values: r } = e;
|
|
758
786
|
return `The ${t} field must not be one of the following values: ${r.map(i).join(", ")}.`;
|
|
759
787
|
},
|
|
788
|
+
notStartsWith: (t, e) => {
|
|
789
|
+
const { value: r } = e;
|
|
790
|
+
return `The ${t} field must not start with ${i(r)}.`;
|
|
791
|
+
},
|
|
792
|
+
notStartsWithNumber: (t) => `The ${t} field must not start with a number.`,
|
|
760
793
|
notSubsetOf: (t, e) => {
|
|
761
794
|
const { values: r } = e;
|
|
762
795
|
return `The ${t} field must not be a subset of the following values: ${r.map(i).join(", ")}.`;
|
|
@@ -791,8 +824,9 @@ const I = {
|
|
|
791
824
|
},
|
|
792
825
|
startsWith: (t, e) => {
|
|
793
826
|
const { value: r } = e;
|
|
794
|
-
return `The ${t} field must start with ${r}.`;
|
|
827
|
+
return `The ${t} field must start with ${i(r)}.`;
|
|
795
828
|
},
|
|
829
|
+
startsWithNumber: (t) => `The ${t} field must start with a number.`,
|
|
796
830
|
string: (t) => `The ${t} field must be a string.`,
|
|
797
831
|
stringContainsAll: (t, e) => {
|
|
798
832
|
const { values: r } = e;
|
|
@@ -859,7 +893,7 @@ const I = {
|
|
|
859
893
|
unique: (t) => `The ${t} field has already been taken.`,
|
|
860
894
|
uppercase: (t) => `The ${t} field must be uppercase.`,
|
|
861
895
|
url: (t) => `The ${t} field must be a valid URL.`
|
|
862
|
-
},
|
|
896
|
+
}, H = {
|
|
863
897
|
accepted: () => "此欄位必須被同意",
|
|
864
898
|
alpha: () => "此欄位只能包含字母",
|
|
865
899
|
alphaDash: () => "此欄位只能包含字母、數字、連接號和底線",
|
|
@@ -917,7 +951,7 @@ const I = {
|
|
|
917
951
|
email: () => "此欄位必須是有效的電子郵件地址",
|
|
918
952
|
endsWith: (t, e) => {
|
|
919
953
|
const { value: r } = e;
|
|
920
|
-
return `此欄位必須以${r}結尾`;
|
|
954
|
+
return `此欄位必須以${i(r)}結尾`;
|
|
921
955
|
},
|
|
922
956
|
equals: (t, e) => {
|
|
923
957
|
const { value: r } = e;
|
|
@@ -1007,6 +1041,10 @@ const I = {
|
|
|
1007
1041
|
const { values: r } = e;
|
|
1008
1042
|
return `此欄位不能同時包含以下所有值:${r.map(i).join(", ")}`;
|
|
1009
1043
|
},
|
|
1044
|
+
notEndsWith: (t, e) => {
|
|
1045
|
+
const { value: r } = e;
|
|
1046
|
+
return `此欄位不能以${i(r)}結尾`;
|
|
1047
|
+
},
|
|
1010
1048
|
notContainsAny: (t, e) => {
|
|
1011
1049
|
const { values: r } = e;
|
|
1012
1050
|
return `此欄位不能包含以下任何值:${r.map(i).join(", ")}`;
|
|
@@ -1019,6 +1057,11 @@ const I = {
|
|
|
1019
1057
|
const { values: r } = e;
|
|
1020
1058
|
return `此欄位不能是以下任何值:${r.map(i).join(", ")}`;
|
|
1021
1059
|
},
|
|
1060
|
+
notStartsWith: (t, e) => {
|
|
1061
|
+
const { value: r } = e;
|
|
1062
|
+
return `此欄位不能以${i(r)}開頭`;
|
|
1063
|
+
},
|
|
1064
|
+
notStartsWithNumber: () => "此欄位不能以數字開頭",
|
|
1022
1065
|
notSubsetOf: (t, e) => {
|
|
1023
1066
|
const { values: r } = e;
|
|
1024
1067
|
return `此欄位不能是以下項目的子集:${r.map(i).join(", ")}`;
|
|
@@ -1053,8 +1096,9 @@ const I = {
|
|
|
1053
1096
|
},
|
|
1054
1097
|
startsWith: (t, e) => {
|
|
1055
1098
|
const { value: r } = e;
|
|
1056
|
-
return `此欄位必須以${r}開頭`;
|
|
1099
|
+
return `此欄位必須以${i(r)}開頭`;
|
|
1057
1100
|
},
|
|
1101
|
+
startsWithNumber: () => "此欄位必須以數字開頭",
|
|
1058
1102
|
string: () => "此欄位必須是字串",
|
|
1059
1103
|
stringContainsAll: (t, e) => {
|
|
1060
1104
|
const { values: r } = e;
|
|
@@ -1121,40 +1165,40 @@ const I = {
|
|
|
1121
1165
|
unique: () => "此欄位已經存在",
|
|
1122
1166
|
uppercase: () => "此欄位必須是大寫",
|
|
1123
1167
|
url: () => "此欄位必須是有效的 URL"
|
|
1124
|
-
},
|
|
1125
|
-
en:
|
|
1126
|
-
"zh-TW":
|
|
1127
|
-
},
|
|
1168
|
+
}, M = {
|
|
1169
|
+
en: Z,
|
|
1170
|
+
"zh-TW": H
|
|
1171
|
+
}, U = () => (t) => s(t) ? !1 : ["y", "yes", "on", "1", "true"].includes(String(t).toLowerCase()), J = () => (t) => s(t) ? !1 : /^[a-zA-Z]+$/.test(String(t)), V = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9-_]+$/.test(String(t)), Q = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9-_.]+$/.test(String(t)), X = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9]+$/.test(String(t)), Y = () => (t) => Array.isArray(t), ee = ({ length: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.length === t : !1, w = ({ length: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.length >= t : !1, T = ({ length: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.length <= t : !1, te = ({ min: t, max: e }) => (r) => s(r) ? !1 : w({ length: t })(r) && T({ length: e })(r), re = ({ length: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.length > t : !1, ne = ({ length: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.length < t : !1, se = () => (t) => s(t) ? !1 : /^[\x20-\x7E]+$/.test(String(t)), h = ({ value: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e >= t : Array.isArray(e) ? e.every((r) => h({ value: t })(r)) : !1, f = ({ value: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e <= t : Array.isArray(e) ? e.every((r) => f({ value: t })(r)) : !1, ae = ({ min: t, max: e }) => (r) => s(r) ? !1 : h({ value: t })(r) && f({ value: e })(r), ie = () => (t) => s(t) ? !1 : typeof t == "boolean", le = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? t.every((r) => e.includes(r)) : !1, oe = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? t.some((r) => e.includes(r)) : !1, ue = () => (t) => s(t) ? !1 : ["n", "no", "off", "0", "false"].includes(String(t).toLowerCase()), he = ({ value: t }) => (e) => s(e) ? !1 : e !== t, fe = () => (t) => s(t) ? !1 : Array.isArray(t) ? new Set(t).size === t.length : !0, ce = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)), me = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)), v = ({ value: t }) => (e) => s(e) ? !1 : String(e).toLowerCase().endsWith(t.toLowerCase()), ye = ({ value: t }) => (e) => e === t, ge = () => (t) => t instanceof File, R = ({ size: t }) => (e) => {
|
|
1128
1172
|
if (s(e))
|
|
1129
1173
|
return !1;
|
|
1130
1174
|
if (e instanceof File) {
|
|
1131
1175
|
const r = t * 1024, a = (t + 1) * 1024;
|
|
1132
1176
|
return e.size >= r && e.size < a;
|
|
1133
1177
|
}
|
|
1134
|
-
return Array.isArray(e) ? e.every((r) =>
|
|
1135
|
-
}, c = ({ size: t }) => (e) => s(e) ? !1 : e instanceof File ? e.size >= t * 1024 : Array.isArray(e) ? e.every((r) => c({ size: t })(r)) : !1, m = ({ size: t }) => (e) => s(e) ? !1 : e instanceof File ? e.size <= t * 1024 : Array.isArray(e) ? e.every((r) => m({ size: t })(r)) : !1,
|
|
1178
|
+
return Array.isArray(e) ? e.every((r) => R({ size: t })(r)) : !1;
|
|
1179
|
+
}, c = ({ size: t }) => (e) => s(e) ? !1 : e instanceof File ? e.size >= t * 1024 : Array.isArray(e) ? e.every((r) => c({ size: t })(r)) : !1, m = ({ size: t }) => (e) => s(e) ? !1 : e instanceof File ? e.size <= t * 1024 : Array.isArray(e) ? e.every((r) => m({ size: t })(r)) : !1, $e = ({ min: t, max: e }) => (r) => s(r) ? !1 : c({ size: t })(r) && m({ size: e })(r), S = ({ size: t }) => (e) => s(e) ? !1 : e instanceof File ? e.size > t * 1024 : Array.isArray(e) ? e.every((r) => S({ size: t })(r)) : !1, z = ({ size: t }) => (e) => s(e) ? !1 : e instanceof File ? e.size < t * 1024 : Array.isArray(e) ? e.every((r) => z({ size: t })(r)) : !1, j = ({ value: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e > t : Array.isArray(e) ? e.every((r) => j({ value: t })(r)) : !1, y = ({ value: t }) => (e) => s(e) ? !1 : String(e).toLowerCase().startsWith(t.toLowerCase()), g = ({ values: t }) => (e) => s(e) ? !1 : t.map((r) => `${r}://`).some((r) => y({ value: r })(e)), C = () => (t) => s(t) ? !1 : g({ values: ["http"] })(t), F = () => (t) => s(t) ? !1 : g({ values: ["https"] })(t), de = () => (t) => s(t) ? !1 : C()(t) || F()(t), $ = () => (t) => s(t) ? !1 : typeof t == "number", pe = () => (t) => s(t) ? !1 : $()(t) && Number.isInteger(t), d = ({ includeProtocol: t } = {}) => (e) => {
|
|
1136
1180
|
if (s(e))
|
|
1137
1181
|
return !1;
|
|
1138
1182
|
if (t)
|
|
1139
1183
|
try {
|
|
1140
1184
|
const { host: r } = new URL(String(e));
|
|
1141
|
-
return
|
|
1185
|
+
return d({})(r);
|
|
1142
1186
|
} catch {
|
|
1143
1187
|
return !1;
|
|
1144
1188
|
}
|
|
1145
1189
|
return /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:\d+)?$/.test(String(e));
|
|
1146
|
-
},
|
|
1190
|
+
}, p = ({ includeProtocol: t } = {}) => (e) => {
|
|
1147
1191
|
if (s(e))
|
|
1148
1192
|
return !1;
|
|
1149
1193
|
if (t)
|
|
1150
1194
|
try {
|
|
1151
1195
|
const { host: r } = new URL(String(e));
|
|
1152
|
-
return
|
|
1196
|
+
return p({})(r);
|
|
1153
1197
|
} catch {
|
|
1154
1198
|
return !1;
|
|
1155
1199
|
}
|
|
1156
1200
|
return /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(String(e));
|
|
1157
|
-
},
|
|
1201
|
+
}, be = ({ includeProtocol: t } = {}) => (e) => s(e) ? !1 : d({ includeProtocol: t })(e) || p({ includeProtocol: t })(e), Ae = () => (t) => {
|
|
1158
1202
|
if (s(t))
|
|
1159
1203
|
return !1;
|
|
1160
1204
|
try {
|
|
@@ -1162,13 +1206,13 @@ const I = {
|
|
|
1162
1206
|
} catch {
|
|
1163
1207
|
return !1;
|
|
1164
1208
|
}
|
|
1165
|
-
},
|
|
1209
|
+
}, Le = () => (t) => s(t) ? !1 : String(t) === String(t).toLowerCase(), _ = ({ value: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e < t : Array.isArray(e) ? e.every((r) => _({ value: t })(r)) : !1, we = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? !t.every((r) => e.includes(r)) : !1, Te = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? !t.some((r) => e.includes(r)) : !1, ve = ({ value: t }) => (e) => s(e) ? !1 : !v({ value: t })(e), Re = ({ value: t }) => (e) => e !== t, q = ({ values: t }) => (e) => s(e) ? !1 : !t.includes(e), Se = ({ value: t }) => (e) => s(e) ? !1 : !y({ value: t })(e), O = () => (t) => s(t) ? !1 : /^\d/.test(String(t)), ze = () => (t) => s(t) ? !1 : !O()(t), je = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.some((r) => !t.includes(r)) : q({ values: t })(e), W = () => (t) => typeof t == "string", Ce = () => (t) => s(t) ? !1 : W()(t) ? /^-?\d+(\.\d+)?$/.test(String(t)) : $()(t), Fe = () => (t) => typeof t == "object" && t !== null && !Array.isArray(t), G = ({ values: t }) => (e) => s(e) ? !1 : t.includes(e), _e = ({ expression: t }) => (e) => {
|
|
1166
1210
|
if (s(e))
|
|
1167
1211
|
return !1;
|
|
1168
1212
|
if (!(t instanceof RegExp))
|
|
1169
1213
|
throw new TypeError("The expression provided is not a valid RegExp.");
|
|
1170
1214
|
return t.test(String(e));
|
|
1171
|
-
},
|
|
1215
|
+
}, qe = () => (t) => !s(t), Oe = ({ value: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.every((r) => r === t) : e === t, k = ({ size: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e === t : Array.isArray(e) ? e.every((r) => k({ size: t })(r)) : !1, We = ({ values: t }) => (e) => s(e) ? !1 : typeof e == "string" ? t.every((r) => e.includes(r)) : !1, Ge = ({ values: t }) => (e) => s(e) ? !1 : typeof e == "string" ? t.some((r) => e.includes(r)) : !1, x = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length === t : Array.isArray(e) ? e.every((r) => x({ length: t })(r)) : !1, b = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length >= t : Array.isArray(e) ? e.every((r) => b({ length: t })(r)) : !1, A = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length <= t : Array.isArray(e) ? e.every((r) => A({ length: t })(r)) : !1, ke = ({ min: t, max: e }) => (r) => s(r) ? !1 : b({ length: t })(r) && A({ length: e })(r), B = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length > t : Array.isArray(e) ? e.every((r) => B({ length: t })(r)) : !1, N = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length < t : Array.isArray(e) ? e.every((r) => N({ length: t })(r)) : !1, xe = ({ values: t }) => (e) => s(e) ? !1 : typeof e == "string" ? !t.every((r) => e.includes(r)) : !1, Be = ({ values: t }) => (e) => s(e) ? !1 : typeof e == "string" ? !t.some((r) => e.includes(r)) : !1, Ne = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.every((r) => t.includes(r)) : G({ values: t })(e), Ee = ({ values: t, ignored: e = [] }) => (r) => s(r) ? !1 : (Array.isArray(e) ? e : [e]).some((a) => a === r) ? !0 : !t.some((a) => a === r), De = () => (t) => s(t) ? !1 : String(t) === String(t).toUpperCase(), Pe = () => (t) => {
|
|
1172
1216
|
if (s(t))
|
|
1173
1217
|
return !1;
|
|
1174
1218
|
try {
|
|
@@ -1176,83 +1220,87 @@ const I = {
|
|
|
1176
1220
|
} catch {
|
|
1177
1221
|
return !1;
|
|
1178
1222
|
}
|
|
1179
|
-
},
|
|
1180
|
-
accepted:
|
|
1181
|
-
alpha:
|
|
1182
|
-
alphaDash:
|
|
1183
|
-
alphaDashDot:
|
|
1184
|
-
alphaNum:
|
|
1185
|
-
array:
|
|
1186
|
-
arrayLength:
|
|
1187
|
-
arrayLengthBetween:
|
|
1188
|
-
arrayLengthGt:
|
|
1189
|
-
arrayLengthGte:
|
|
1190
|
-
arrayLengthLt:
|
|
1191
|
-
arrayLengthLte:
|
|
1192
|
-
ascii:
|
|
1193
|
-
between:
|
|
1194
|
-
boolean:
|
|
1195
|
-
containsAll:
|
|
1196
|
-
containsAny:
|
|
1197
|
-
declined:
|
|
1198
|
-
different:
|
|
1199
|
-
distinct:
|
|
1200
|
-
domain:
|
|
1201
|
-
email:
|
|
1202
|
-
endsWith:
|
|
1203
|
-
equals:
|
|
1204
|
-
file:
|
|
1205
|
-
fileSize:
|
|
1206
|
-
fileSizeBetween:
|
|
1207
|
-
fileSizeGt:
|
|
1223
|
+
}, Ie = {
|
|
1224
|
+
accepted: U,
|
|
1225
|
+
alpha: J,
|
|
1226
|
+
alphaDash: V,
|
|
1227
|
+
alphaDashDot: Q,
|
|
1228
|
+
alphaNum: X,
|
|
1229
|
+
array: Y,
|
|
1230
|
+
arrayLength: ee,
|
|
1231
|
+
arrayLengthBetween: te,
|
|
1232
|
+
arrayLengthGt: re,
|
|
1233
|
+
arrayLengthGte: w,
|
|
1234
|
+
arrayLengthLt: ne,
|
|
1235
|
+
arrayLengthLte: T,
|
|
1236
|
+
ascii: se,
|
|
1237
|
+
between: ae,
|
|
1238
|
+
boolean: ie,
|
|
1239
|
+
containsAll: le,
|
|
1240
|
+
containsAny: oe,
|
|
1241
|
+
declined: ue,
|
|
1242
|
+
different: he,
|
|
1243
|
+
distinct: fe,
|
|
1244
|
+
domain: ce,
|
|
1245
|
+
email: me,
|
|
1246
|
+
endsWith: v,
|
|
1247
|
+
equals: ye,
|
|
1248
|
+
file: ge,
|
|
1249
|
+
fileSize: R,
|
|
1250
|
+
fileSizeBetween: $e,
|
|
1251
|
+
fileSizeGt: S,
|
|
1208
1252
|
fileSizeGte: c,
|
|
1209
|
-
fileSizeLt:
|
|
1253
|
+
fileSizeLt: z,
|
|
1210
1254
|
fileSizeLte: m,
|
|
1211
|
-
gt:
|
|
1255
|
+
gt: j,
|
|
1212
1256
|
gte: h,
|
|
1213
|
-
http:
|
|
1214
|
-
httpOrHttps:
|
|
1257
|
+
http: C,
|
|
1258
|
+
httpOrHttps: de,
|
|
1215
1259
|
https: F,
|
|
1216
|
-
integer:
|
|
1217
|
-
ip:
|
|
1218
|
-
ipv4:
|
|
1219
|
-
ipv6:
|
|
1220
|
-
json:
|
|
1221
|
-
lowercase:
|
|
1222
|
-
lt:
|
|
1260
|
+
integer: pe,
|
|
1261
|
+
ip: be,
|
|
1262
|
+
ipv4: d,
|
|
1263
|
+
ipv6: p,
|
|
1264
|
+
json: Ae,
|
|
1265
|
+
lowercase: Le,
|
|
1266
|
+
lt: _,
|
|
1223
1267
|
lte: f,
|
|
1224
|
-
notContainsAll:
|
|
1225
|
-
notContainsAny:
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1268
|
+
notContainsAll: we,
|
|
1269
|
+
notContainsAny: Te,
|
|
1270
|
+
notEndsWith: ve,
|
|
1271
|
+
notEquals: Re,
|
|
1272
|
+
notOneOf: q,
|
|
1273
|
+
notStartsWith: Se,
|
|
1274
|
+
notStartsWithNumber: ze,
|
|
1275
|
+
notSubsetOf: je,
|
|
1276
|
+
number: $,
|
|
1277
|
+
numeric: Ce,
|
|
1278
|
+
object: Fe,
|
|
1279
|
+
oneOf: G,
|
|
1280
|
+
protocol: g,
|
|
1281
|
+
regex: _e,
|
|
1282
|
+
required: qe,
|
|
1283
|
+
same: Oe,
|
|
1284
|
+
size: k,
|
|
1285
|
+
startsWith: y,
|
|
1286
|
+
startsWithNumber: O,
|
|
1287
|
+
string: W,
|
|
1288
|
+
stringContainsAll: We,
|
|
1289
|
+
stringContainsAny: Ge,
|
|
1290
|
+
stringLength: x,
|
|
1291
|
+
stringLengthBetween: ke,
|
|
1292
|
+
stringLengthGt: B,
|
|
1293
|
+
stringLengthGte: b,
|
|
1294
|
+
stringLengthLt: N,
|
|
1295
|
+
stringLengthLte: A,
|
|
1296
|
+
stringNotContainsAll: xe,
|
|
1297
|
+
stringNotContainsAny: Be,
|
|
1298
|
+
subsetOf: Ne,
|
|
1299
|
+
unique: Ee,
|
|
1300
|
+
uppercase: De,
|
|
1301
|
+
url: Pe
|
|
1254
1302
|
};
|
|
1255
|
-
class
|
|
1303
|
+
class Ze {
|
|
1256
1304
|
constructor({
|
|
1257
1305
|
fallbackLocale: e,
|
|
1258
1306
|
locale: r,
|
|
@@ -1262,7 +1310,7 @@ class Ne {
|
|
|
1262
1310
|
o(this, "fallbackLocale", "en");
|
|
1263
1311
|
o(this, "locales", {});
|
|
1264
1312
|
o(this, "rules", {});
|
|
1265
|
-
this.registerLocales(
|
|
1313
|
+
this.registerLocales(M), this.registerRules(Ie), e && this.setFallbackLocale(e), r && this.setLocale(r), a && a.forEach((l) => this.registerPlugin(l));
|
|
1266
1314
|
}
|
|
1267
1315
|
getLocale() {
|
|
1268
1316
|
return this.locale;
|
|
@@ -1281,7 +1329,7 @@ class Ne {
|
|
|
1281
1329
|
return this.fallbackLocale = e, this;
|
|
1282
1330
|
}
|
|
1283
1331
|
defineField(e) {
|
|
1284
|
-
return new
|
|
1332
|
+
return new K({
|
|
1285
1333
|
name: e,
|
|
1286
1334
|
locale: this.locale,
|
|
1287
1335
|
fallbackLocale: this.fallbackLocale,
|
|
@@ -1305,6 +1353,6 @@ class Ne {
|
|
|
1305
1353
|
}
|
|
1306
1354
|
}
|
|
1307
1355
|
export {
|
|
1308
|
-
|
|
1309
|
-
|
|
1356
|
+
K as FieldValidator,
|
|
1357
|
+
Ze as FormValidator
|
|
1310
1358
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.Fortress={}))})(this,function(h){"use strict";var Oe=Object.defineProperty;var _e=(h,o,n)=>o in h?Oe(h,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):h[o]=n;var u=(h,o,n)=>(_e(h,typeof o!="symbol"?o+"":o,n),n);const o=t=>{const e=",、;:!?。()《》「」『』【】〔〕",r="\\x20-\\x7E",a=new RegExp(`\\s*([${e}])`,"gu"),l=new RegExp(`([${e}])\\s*([${r}])`,"gu"),f=new RegExp(`([^${r}${e}])([${r}])`,"gu"),Ce=new RegExp(`([${r}])([^${r}${e}])`,"gu");return t.replace(a,"$1").replace(l,"$1$2").replace(f,"$1 $2").replace(Ce,"$1 $2").replace(/ +/g," ")},n=(t,e=0)=>new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e}).format(t),N=t=>Object.prototype.toString.call(t).toLowerCase().slice(8,-1),s=t=>t==null||t===""||Array.isArray(t)&&t.length<1,i=t=>`"${t}"`;class T{constructor({name:e,locale:r,fallbackLocale:a,locales:l,rules:f}){u(this,"name");u(this,"locale");u(this,"fallbackLocale");u(this,"locales");u(this,"rules");u(this,"ruleFunctions",{});u(this,"conditions",{});u(this,"shouldSkip",!1);u(this,"appliedProtocols",{});this.name=e,this.locale=r,this.fallbackLocale=a,this.locales=l,this.rules=f}get formattedName(){return this.name.toLowerCase()}get messages(){return this.locales[this.locale]||{}}get fallbackMessages(){return this.locales[this.fallbackLocale]||{}}get mandatoryRules(){return[this.required.name,this.string.name,this.array.name,this.equals.name,this.notEquals.name]}getMessage(e){return this.messages[e]||this.fallbackMessages[e]||(r=>`The ${r} field is invalid.`)}getRule(e){if(!(e in this.rules))throw new Error(`The "${e}" rule is not registered.`);return this.rules[e]}buildRuleFunction(e,r){return a=>{if(s(a)&&!this.mandatoryRules.includes(e))return!0;const l=this.getRule(e)(r)(a);return typeof l=="string"?l:l===!0?!0:this.buildRuleFunctionMessage(e,r,a)}}buildRuleFunctionMessage(e,r,a){const l=this.getMessage(e)(this.formattedName,r);if(typeof l=="object"){const f=N(a);if(!(f in l))throw new Error(`The message for the "${e}" rule of the "${f}" type is missing.`);return o(l[f])}return o(l)}pushRuleFunction(e,r){if(e in this.conditions&&!this.conditions[e])return this;const a=this.buildRuleFunction(e,r);return this.ruleFunctions[e]=a,this}getRuleFunctions(){return Object.values(this.ruleFunctions)}collect(){return this.shouldSkip?[]:this.getRuleFunctions()}validate(e){if(this.shouldSkip)return!0;const r=this.getRuleFunctions();for(const a of r){const l=a(e);if(typeof l=="string")return l}return!0}apply(e,r={}){return this.pushRuleFunction(e,r)}accepted(){return this.apply(this.accepted.name)}after(e,r,a,l=!0){return this.apply(this.after.name,{date:e,format:r,displayFormat:a,strict:l})}alpha(){return this.apply(this.alpha.name)}alphaDash(){return this.apply(this.alphaDash.name)}alphaDashDot(){return this.apply(this.alphaDashDot.name)}alphaNum(){return this.apply(this.alphaNum.name)}array(){return this.apply(this.array.name)}arrayLength(e){return this.apply(this.arrayLength.name,{length:e})}arrayLengthBetween(e,r){return this.apply(this.arrayLengthBetween.name,{min:e,max:r})}arrayLengthGt(e){return this.apply(this.arrayLengthGt.name,{length:e})}arrayLengthGte(e){return this.apply(this.arrayLengthGte.name,{length:e})}arrayLengthLt(e){return this.apply(this.arrayLengthLt.name,{length:e})}arrayLengthLte(e){return this.apply(this.arrayLengthLte.name,{length:e})}ascii(){return this.apply(this.ascii.name)}before(e,r,a,l=!0){return this.apply(this.before.name,{date:e,format:r,displayFormat:a,strict:l})}between(e,r){return this.apply(this.between.name,{min:e,max:r})}boolean(){return this.apply(this.boolean.name)}containsAll(e){return this.apply(this.containsAll.name,{values:e})}containsAny(e){return this.apply(this.containsAny.name,{values:e})}date(e,r=!0){return this.apply(this.date.name,{format:e,strict:r})}declined(){return this.apply(this.declined.name)}different(e,r){return this.apply(this.different.name,{field:e,value:r})}distinct(){return this.apply(this.distinct.name)}domain(){return this.apply(this.domain.name)}email(){return this.apply(this.email.name)}endsWith(e){return this.apply(this.endsWith.name,{value:e})}equals(e){return this.apply(this.equals.name,{value:e})}file(){return this.apply(this.file.name)}fileSize(e){return this.apply(this.fileSize.name,{size:e})}fileSizeBetween(e,r){return this.apply(this.fileSizeBetween.name,{min:e,max:r})}fileSizeGt(e){return this.apply(this.fileSizeGt.name,{size:e})}fileSizeGte(e){return this.apply(this.fileSizeGte.name,{size:e})}fileSizeLt(e){return this.apply(this.fileSizeLt.name,{size:e})}fileSizeLte(e){return this.apply(this.fileSizeLte.name,{size:e})}gt(e){return this.apply(this.gt.name,{value:e})}gte(e){return this.apply(this.gte.name,{value:e})}http(){return this.appliedProtocols[this.http.name]=!0,this.apply(this.http.name)}httpOrHttps(){return this.appliedProtocols[this.http.name]=!0,this.appliedProtocols[this.https.name]=!0,this.apply(this.httpOrHttps.name)}https(){return this.appliedProtocols[this.https.name]=!0,this.apply(this.https.name)}integer(){return this.apply(this.integer.name)}ip(){const e=Object.keys(this.appliedProtocols).length>0;return this.apply(this.ip.name,{includeProtocol:e})}ipv4(){const e=Object.keys(this.appliedProtocols).length>0;return this.apply(this.ipv4.name,{includeProtocol:e})}ipv6(){const e=Object.keys(this.appliedProtocols).length>0;return this.apply(this.ipv6.name,{includeProtocol:e})}iso8601(){return this.apply(this.iso8601.name)}json(){return this.apply(this.json.name)}jsonSchema(e){return this.apply(this.jsonSchema.name,{schema:e,locale:this.locale,field:this.name})}lowercase(){return this.apply(this.lowercase.name)}lt(e){return this.apply(this.lt.name,{value:e})}lte(e){return this.apply(this.lte.name,{value:e})}notContainsAll(e){return this.apply(this.notContainsAll.name,{values:e})}notContainsAny(e){return this.apply(this.notContainsAny.name,{values:e})}notEquals(e){return this.apply(this.notEquals.name,{value:e})}notOneOf(e){return this.apply(this.notOneOf.name,{values:e})}notSubsetOf(e){return this.apply(this.notSubsetOf.name,{values:e})}number(){return this.apply(this.number.name)}numeric(){return this.apply(this.numeric.name)}object(){return this.apply(this.object.name)}oneOf(e){return this.apply(this.oneOf.name,{values:e})}protocol(e){const r=Array.isArray(e)?e:[e];return r.forEach(a=>this.appliedProtocols[a]=!0),this.apply(this.protocol.name,{values:r})}regex(e){return this.apply(this.regex.name,{expression:e})}required(){return this.apply(this.required.name)}requiredWhen(e){return this.when({required:e}).required()}same(e,r){return this.apply(this.same.name,{field:e,value:r})}size(e){return this.apply(this.size.name,{size:e})}startsWith(e){return this.apply(this.startsWith.name,{value:e})}string(){return this.apply(this.string.name)}stringContainsAll(e){return this.apply(this.stringContainsAll.name,{values:e})}stringContainsAny(e){return this.apply(this.stringContainsAny.name,{values:e})}stringLength(e){return this.apply(this.stringLength.name,{length:e})}stringLengthBetween(e,r){return this.apply(this.stringLengthBetween.name,{min:e,max:r})}stringLengthGt(e){return this.apply(this.stringLengthGt.name,{length:e})}stringLengthGte(e){return this.apply(this.stringLengthGte.name,{length:e})}stringLengthLt(e){return this.apply(this.stringLengthLt.name,{length:e})}stringLengthLte(e){return this.apply(this.stringLengthLte.name,{length:e})}stringNotContainsAll(e){return this.apply(this.stringNotContainsAll.name,{values:e})}stringNotContainsAny(e){return this.apply(this.stringNotContainsAny.name,{values:e})}subsetOf(e){return this.apply(this.subsetOf.name,{values:e})}unique(e,r=[]){return this.apply(this.unique.name,{values:e,ignored:r})}uppercase(){return this.apply(this.uppercase.name)}url(){return this.apply(this.url.name)}when(e){return typeof e=="object"?(this.conditions=e,this):(e||(this.shouldSkip=!0),this)}}const P={en:{accepted:t=>`The ${t} field must be accepted.`,alpha:t=>`The ${t} field must only contain letters.`,alphaDash:t=>`The ${t} field must only contain letters, numbers, dashes and underscores.`,alphaDashDot:t=>`The ${t} field must only contain letters, numbers, dashes, underscores and dots.`,alphaNum:t=>`The ${t} field must only contain letters and numbers.`,array:t=>`The ${t} field must be an array.`,arrayLength:(t,e)=>{const{length:r}=e;return`The ${t} field must be ${n(r)} items.`},arrayLengthBetween:(t,e)=>{const{min:r,max:a}=e;return`The ${t} field must be between ${n(r)} and ${n(a)} items.`},arrayLengthGt:(t,e)=>{const{length:r}=e;return`The ${t} field must be greater than ${n(r)} items.`},arrayLengthGte:(t,e)=>{const{length:r}=e;return`The ${t} field must be greater than or equal to ${n(r)} items.`},arrayLengthLte:(t,e)=>{const{length:r}=e;return`The ${t} field must be less than or equal to ${n(r)} items.`},arrayLengthLt:(t,e)=>{const{length:r}=e;return`The ${t} field must be less than ${n(r)} items.`},ascii:t=>`The ${t} field must only contain ASCII characters and symbols.`,between:(t,e)=>{const{min:r,max:a}=e;return{number:`The ${t} field must be between ${n(r)} and ${n(a)}.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(a)}.`}},boolean:t=>`The ${t} field must be a boolean value.`,containsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must contain all of the following values: ${r.map(i).join(", ")}.`},containsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following values: ${r.map(i).join(", ")}.`},declined:t=>`The ${t} field must be declined.`,different:(t,e)=>{const{field:r}=e;return`The ${t} and ${r} fields must be different.`},distinct:t=>`The ${t} field must not contain duplicate values.`,domain:t=>`The ${t} field must be a valid domain.`,email:t=>`The ${t} field must be a valid email address.`,endsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must end with ${r}.`},equals:(t,e)=>{const{value:r}=e;return`The ${t} field must be equal to ${r}.`},file:t=>`The ${t} field must be a file.`,fileSizeBetween:(t,e)=>{const{min:r,max:a}=e;return{file:`The ${t} field must be between ${n(r)} and ${n(a)} kilobytes.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(a)} kilobytes.`}},fileSizeGt:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be greater than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is greater than ${n(r)} kilobytes.`}},fileSizeGte:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be greater than or equal to ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is greater than or equal to ${n(r)} kilobytes.`}},fileSizeLt:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be less than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is less than ${n(r)} kilobytes.`}},fileSizeLte:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be less than or equal to ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is less than or equal to ${n(r)} kilobytes.`}},fileSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is ${n(r)} kilobytes.`}},http:t=>`The ${t} field must start with the "http://" protocol.`,httpOrHttps:t=>`The ${t} field must start with the "http://" or "https://" protocols.`,https:t=>`The ${t} field must start with the "https://" protocol.`,integer:t=>`The ${t} field must be an integer.`,ip:t=>`The ${t} field must be a valid IP address.`,ipv4:t=>`The ${t} field must be a valid IPv4 address.`,ipv6:t=>`The ${t} field must be a valid IPv6 address.`,json:t=>`The ${t} field must be a valid JSON string.`,lowercase:t=>`The ${t} field must be lowercase.`,lt:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be less than ${n(r)}.`,array:`The ${t} field must contain items where each item is less than ${n(r)}.`}},lte:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be less than or equal to ${n(r)}.`,array:`The ${t} field must contain items where each item is less than or equal to ${n(r)}.`}},gt:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be greater than ${n(r)}.`,array:`The ${t} field must contain items where each item is greater than ${n(r)}.`}},gte:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be greater than or equal to ${n(r)}.`,array:`The ${t} field must contain items where each item is greater than or equal to ${n(r)}.`}},notContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain all of the following values together: ${r.map(i).join(", ")}.`},notContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain any of the following values: ${r.map(i).join(", ")}.`},notEquals:(t,e)=>{const{value:r}=e;return`The ${t} field must not be equal to ${r}.`},notOneOf:(t,e)=>{const{values:r}=e;return`The ${t} field must not be one of the following values: ${r.map(i).join(", ")}.`},notSubsetOf:(t,e)=>{const{values:r}=e;return`The ${t} field must not be a subset of the following values: ${r.map(i).join(", ")}.`},number:t=>`The ${t} field must be a number.`,numeric:t=>`The ${t} field must be a number.`,object:t=>`The ${t} field must be an object.`,oneOf:(t,e)=>{const{values:r}=e;return`The ${t} field must be one of the following values: ${r.map(i).join(", ")}.`},protocol:(t,e)=>{const{values:r}=e;if(r.length===1){const[a]=r;return`The ${t} field must start with the "${a}://" protocol.`}return`The ${t} field must start with one of the following protocols: ${r.map(a=>`${a}://`).map(i).join(", ")}.`},regex:t=>`The ${t} field must match the required format.`,required:t=>`The ${t} field is required.`,same:(t,e)=>{const{field:r}=e;return`The ${t} and ${r} fields must match.`},size:(t,e)=>{const{size:r}=e;return{number:`The ${t} field must be ${n(r)}.`,array:`The ${t} field must contain items where each item is ${n(r)}.`}},startsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must start with ${r}.`},string:t=>`The ${t} field must be a string.`,stringContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must contain all of the following text: ${r.map(i).join(", ")}.`},stringContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following text: ${r.map(i).join(", ")}.`},stringLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be ${n(r)} characters.`,array:`The ${t} field must contain items where each item is ${n(r)} characters.`}},stringLengthBetween:(t,e)=>{const{min:r,max:a}=e;return{string:`The ${t} field must be between ${n(r)} and ${n(a)} characters.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(a)} characters.`}},stringLengthGt:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be greater than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is greater than ${n(r)} characters.`}},stringLengthGte:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be greater than or equal to ${n(r)} characters.`,array:`The ${t} field must contain items where each item is greater than or equal to ${n(r)} characters.`}},stringLengthLt:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be less than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is less than ${n(r)} characters.`}},stringLengthLte:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be less than or equal to ${n(r)} characters.`,array:`The ${t} field must contain items where each item is less than or equal to ${n(r)} characters.`}},stringNotContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain all of the following text together: ${r.map(i).join(", ")}.`},stringNotContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain any of the following text: ${r.map(i).join(", ")}.`},subsetOf:(t,e)=>{const{values:r}=e;return`The ${t} field must be a subset of the following values: ${r.map(i).join(", ")}.`},unique:t=>`The ${t} field has already been taken.`,uppercase:t=>`The ${t} field must be uppercase.`,url:t=>`The ${t} field must be a valid URL.`},"zh-TW":{accepted:()=>"此欄位必須被同意",alpha:()=>"此欄位只能包含字母",alphaDash:()=>"此欄位只能包含字母、數字、連接號和底線",alphaDashDot:()=>"此欄位只能包含字母、數字、連接號、底線和點",alphaNum:()=>"此欄位只能包含字母和數字",array:()=>"此欄位必須是一個陣列",arrayLength:(t,e)=>{const{length:r}=e;return`此欄位必須是${n(r)}個項目`},arrayLengthBetween:(t,e)=>{const{min:r,max:a}=e;return`此欄位必須介於${n(r)}到${n(a)}個項目之間`},arrayLengthGt:(t,e)=>{const{length:r}=e;return`此欄位必須大於${n(r)}個項目`},arrayLengthGte:(t,e)=>{const{length:r}=e;return`此欄位必須大於或等於${n(r)}個項目`},arrayLengthLt:(t,e)=>{const{length:r}=e;return`此欄位必須小於${n(r)}個項目`},arrayLengthLte:(t,e)=>{const{length:r}=e;return`此欄位必須小於或等於${n(r)}個項目`},ascii:()=>"此欄位只能包含 ASCII 字元和符號",between:(t,e)=>{const{min:r,max:a}=e;return{number:`此欄位必須介於${n(r)}到${n(a)}`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(a)}`}},boolean:()=>"此欄位必須是一個布林值",containsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有項目:${r.map(i).join(", ")}`},containsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個項目:${r.map(i).join(", ")}`},declined:()=>"此欄位必須被拒絕",different:(t,e)=>{const{field:r}=e;return`此欄位必須和${r}欄位不同`},distinct:()=>"此欄位不能包含重複的值",domain:()=>"此欄位必須是有效的網域",email:()=>"此欄位必須是有效的電子郵件地址",endsWith:(t,e)=>{const{value:r}=e;return`此欄位必須以${r}結尾`},equals:(t,e)=>{const{value:r}=e;return`此欄位必須是${r}`},file:()=>"此欄位必須是檔案",fileSize:(t,e)=>{const{size:r}=e;return{file:`此欄位必須是${n(r)} KB`,array:`此欄位中的每個項目都必須是${n(r)} KB`}},fileSizeBetween:(t,e)=>{const{min:r,max:a}=e;return{file:`此欄位必須介於${n(r)}到${n(a)} KB 之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(a)} KB 之間`}},fileSizeGt:(t,e)=>{const{size:r}=e;return{file:`此欄位必須大於${n(r)} KB`,array:`此欄位中的每個項目都必須大於${n(r)} KB`}},fileSizeGte:(t,e)=>{const{size:r}=e;return{file:`此欄位必須大於或等於${n(r)} KB`,array:`此欄位中的每個項目都必須大於或等於${n(r)} KB`}},fileSizeLt:(t,e)=>{const{size:r}=e;return{file:`此欄位必須小於${n(r)} KB`,array:`此欄位中的每個項目都必須小於${n(r)} KB`}},fileSizeLte:(t,e)=>{const{size:r}=e;return{file:`此欄位必須小於或等於${n(r)} KB`,array:`此欄位中的每個項目都必須小於或等於${n(r)} KB`}},gt:(t,e)=>{const{value:r}=e;return{number:`此欄位必須大於${n(r)}`,array:`此欄位中的每個項目都必須大於${n(r)}`}},gte:(t,e)=>{const{value:r}=e;return{number:`此欄位必須大於或等於${n(r)}`,array:`此欄位中的每個項目都必須大於或等於${n(r)}`}},http:()=>'此欄位必須以 "http://" 協議開頭',httpOrHttps:()=>'此欄位必須以 "http://" 或 "https://" 協議開頭',https:()=>'此欄位必須以 "https://" 協議開頭',integer:()=>"此欄位必須是整數",ip:()=>"此欄位必須是有效的 IP 位址",ipv4:()=>"此欄位必須是有效的 IPv4 位址",ipv6:()=>"此欄位必須是有效的 IPv6 位址",json:()=>"此欄位必須是有效的 JSON 字串",lowercase:()=>"此欄位必須是小寫",lt:(t,e)=>{const{value:r}=e;return{number:`此欄位必須小於${n(r)}`,array:`此欄位中的每個項目都必須小於${n(r)}`}},lte:(t,e)=>{const{value:r}=e;return{number:`此欄位必須小於或等於${n(r)}`,array:`此欄位中的每個項目都必須小於或等於${n(r)}`}},notContainsAll:(t,e)=>{const{values:r}=e;return`此欄位不能同時包含以下所有值:${r.map(i).join(", ")}`},notContainsAny:(t,e)=>{const{values:r}=e;return`此欄位不能包含以下任何值:${r.map(i).join(", ")}`},notEquals:(t,e)=>{const{value:r}=e;return`此欄位不能是${r}`},notOneOf:(t,e)=>{const{values:r}=e;return`此欄位不能是以下任何值:${r.map(i).join(", ")}`},notSubsetOf:(t,e)=>{const{values:r}=e;return`此欄位不能是以下項目的子集:${r.map(i).join(", ")}`},number:()=>"此欄位必須是數字",numeric:()=>"此欄位必須是數字",object:()=>"此欄位必須是物件",oneOf:(t,e)=>{const{values:r}=e;return`此欄位必須是以下其中一個值:${r.map(i).join(", ")}`},protocol:(t,e)=>{const{values:r}=e;if(r.length===1){const[a]=r;return`此欄位必須以 "${a}://" 協議開頭`}return`此欄位必須以以下其中一個協議開頭:${r.map(a=>`${a}://`).map(i).join(", ")}`},regex:()=>"此欄位必須符合所需的格式",required:()=>"此欄位為必填",same:(t,e)=>{const{field:r}=e;return`此欄位必須與${r}欄位相同`},size:(t,e)=>{const{size:r}=e;return{number:`此欄位必須是${n(r)}`,array:`此欄位中的每個項目都必須是${n(r)}`}},startsWith:(t,e)=>{const{value:r}=e;return`此欄位必須以${r}開頭`},string:()=>"此欄位必須是字串",stringContainsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有文字:${r.map(i).join(", ")}`},stringContainsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個文字:${r.map(i).join(", ")}`},stringLength:(t,e)=>{const{length:r}=e;return{string:`此欄位必須是${n(r)}個字元`,array:`此欄位中的每個項目都必須是${n(r)}個字元`}},stringLengthBetween:(t,e)=>{const{min:r,max:a}=e;return{string:`此欄位必須介於${n(r)}到${n(a)}個字元之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(a)}個字元之間`}},stringLengthGt:(t,e)=>{const{length:r}=e;return{string:`此欄位必須大於${n(r)}個字元`,array:`此欄位中的每個項目都必須大於${n(r)}個字元`}},stringLengthGte:(t,e)=>{const{length:r}=e;return{string:`此欄位必須大於或等於${n(r)}個字元`,array:`此欄位中的每個項目都必須大於或等於${n(r)}個字元`}},stringLengthLt:(t,e)=>{const{length:r}=e;return{string:`此欄位必須小於${n(r)}個字元`,array:`此欄位中的每個項目都必須小於${n(r)}個字元`}},stringLengthLte:(t,e)=>{const{length:r}=e;return{string:`此欄位必須小於或等於${n(r)}個字元`,array:`此欄位中的每個項目都必須小於或等於${n(r)}個字元`}},stringNotContainsAll:(t,e)=>{const{values:r}=e;return`此欄位不能同時包含以下所有文字:${r.map(i).join(", ")}`},stringNotContainsAny:(t,e)=>{const{values:r}=e;return`此欄位不能包含以下任何文字:${r.map(i).join(", ")}`},subsetOf:(t,e)=>{const{values:r}=e;return`此欄位必須是以下項目的子集:${r.map(i).join(", ")}`},unique:()=>"此欄位已經存在",uppercase:()=>"此欄位必須是大寫",url:()=>"此欄位必須是有效的 URL"}},W=()=>t=>s(t)?!1:["y","yes","on","1","true"].includes(String(t).toLowerCase()),I=()=>t=>s(t)?!1:/^[a-zA-Z]+$/.test(String(t)),K=()=>t=>s(t)?!1:/^[a-zA-Z0-9-_]+$/.test(String(t)),Z=()=>t=>s(t)?!1:/^[a-zA-Z0-9-_.]+$/.test(String(t)),M=()=>t=>s(t)?!1:/^[a-zA-Z0-9]+$/.test(String(t)),H=()=>t=>Array.isArray(t),U=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length===t:!1,w=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length>=t:!1,v=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length<=t:!1,V=({min:t,max:e})=>r=>s(r)?!1:w({length:t})(r)&&v({length:e})(r),J=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length>t:!1,Q=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length<t:!1,X=()=>t=>s(t)?!1:/^[\x20-\x7E]+$/.test(String(t)),c=({value:t})=>e=>s(e)?!1:typeof e=="number"?e>=t:Array.isArray(e)?e.every(r=>c({value:t})(r)):!1,m=({value:t})=>e=>s(e)?!1:typeof e=="number"?e<=t:Array.isArray(e)?e.every(r=>m({value:t})(r)):!1,Y=({min:t,max:e})=>r=>s(r)?!1:c({value:t})(r)&&m({value:e})(r),ee=()=>t=>s(t)?!1:typeof t=="boolean",te=({values:t})=>e=>s(e)?!1:Array.isArray(e)?t.every(r=>e.includes(r)):!1,re=({values:t})=>e=>s(e)?!1:Array.isArray(e)?t.some(r=>e.includes(r)):!1,ne=()=>t=>s(t)?!1:["n","no","off","0","false"].includes(String(t).toLowerCase()),se=({value:t})=>e=>s(e)?!1:e!==t,ae=()=>t=>s(t)?!1:Array.isArray(t)?new Set(t).size===t.length:!0,ie=()=>t=>s(t)?!1:/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),le=()=>t=>s(t)?!1:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),oe=({value:t})=>e=>s(e)?!1:String(e).endsWith(t),ue=({value:t})=>e=>e===t,he=()=>t=>t instanceof File,R=({size:t})=>e=>{if(s(e))return!1;if(e instanceof File){const r=t*1024,a=(t+1)*1024;return e.size>=r&&e.size<a}return Array.isArray(e)?e.every(r=>R({size:t})(r)):!1},y=({size:t})=>e=>s(e)?!1:e instanceof File?e.size>=t*1024:Array.isArray(e)?e.every(r=>y({size:t})(r)):!1,g=({size:t})=>e=>s(e)?!1:e instanceof File?e.size<=t*1024:Array.isArray(e)?e.every(r=>g({size:t})(r)):!1,fe=({min:t,max:e})=>r=>s(r)?!1:y({size:t})(r)&&g({size:e})(r),S=({size:t})=>e=>s(e)?!1:e instanceof File?e.size>t*1024:Array.isArray(e)?e.every(r=>S({size:t})(r)):!1,z=({size:t})=>e=>s(e)?!1:e instanceof File?e.size<t*1024:Array.isArray(e)?e.every(r=>z({size:t})(r)):!1,j=({value:t})=>e=>s(e)?!1:typeof e=="number"?e>t:Array.isArray(e)?e.every(r=>j({value:t})(r)):!1,F=({value:t})=>e=>s(e)?!1:String(e).startsWith(t),$=({values:t})=>e=>s(e)?!1:t.map(r=>`${r}://`).some(r=>F({value:r})(e)),q=()=>t=>s(t)?!1:$({values:["http"]})(t),C=()=>t=>s(t)?!1:$({values:["https"]})(t),ce=()=>t=>s(t)?!1:q()(t)||C()(t),d=()=>t=>s(t)?!1:typeof t=="number",me=()=>t=>s(t)?!1:d()(t)&&Number.isInteger(t),p=({includeProtocol:t}={})=>e=>{if(s(e))return!1;if(t)try{const{host:r}=new URL(String(e));return p({})(r)}catch{return!1}return/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:\d+)?$/.test(String(e))},b=({includeProtocol:t}={})=>e=>{if(s(e))return!1;if(t)try{const{host:r}=new URL(String(e));return b({})(r)}catch{return!1}return/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(String(e))},ye=({includeProtocol:t}={})=>e=>s(e)?!1:p({includeProtocol:t})(e)||b({includeProtocol:t})(e),ge=()=>t=>{if(s(t))return!1;try{return JSON.parse(String(t)),!0}catch{return!1}},$e=()=>t=>s(t)?!1:String(t)===String(t).toLowerCase(),O=({value:t})=>e=>s(e)?!1:typeof e=="number"?e<t:Array.isArray(e)?e.every(r=>O({value:t})(r)):!1,de=({values:t})=>e=>s(e)?!1:Array.isArray(e)?!t.every(r=>e.includes(r)):!1,pe=({values:t})=>e=>s(e)?!1:Array.isArray(e)?!t.some(r=>e.includes(r)):!1,be=({value:t})=>e=>e!==t,_=({values:t})=>e=>s(e)?!1:!t.includes(e),Ae=({values:t})=>e=>s(e)?!1:Array.isArray(e)?e.some(r=>!t.includes(r)):_({values:t})(e),G=()=>t=>typeof t=="string",Le=()=>t=>s(t)?!1:G()(t)?/^-?\d+(\.\d+)?$/.test(String(t)):d()(t),Te=()=>t=>typeof t=="object"&&t!==null&&!Array.isArray(t),k=({values:t})=>e=>s(e)?!1:t.includes(e),we=({expression:t})=>e=>{if(s(e))return!1;if(!(t instanceof RegExp))throw new TypeError("The expression provided is not a valid RegExp.");return t.test(String(e))},ve=()=>t=>!s(t),Re=({value:t})=>e=>s(e)?!1:Array.isArray(e)?e.every(r=>r===t):e===t,x=({size:t})=>e=>s(e)?!1:typeof e=="number"?e===t:Array.isArray(e)?e.every(r=>x({size:t})(r)):!1,Se=({values:t})=>e=>s(e)?!1:typeof e=="string"?t.every(r=>e.includes(r)):!1,ze=({values:t})=>e=>s(e)?!1:typeof e=="string"?t.some(r=>e.includes(r)):!1,B=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length===t:Array.isArray(e)?e.every(r=>B({length:t})(r)):!1,A=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length>=t:Array.isArray(e)?e.every(r=>A({length:t})(r)):!1,L=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length<=t:Array.isArray(e)?e.every(r=>L({length:t})(r)):!1,je=({min:t,max:e})=>r=>s(r)?!1:A({length:t})(r)&&L({length:e})(r),E=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length>t:Array.isArray(e)?e.every(r=>E({length:t})(r)):!1,D=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length<t:Array.isArray(e)?e.every(r=>D({length:t})(r)):!1,Fe={accepted:W,alpha:I,alphaDash:K,alphaDashDot:Z,alphaNum:M,array:H,arrayLength:U,arrayLengthBetween:V,arrayLengthGt:J,arrayLengthGte:w,arrayLengthLt:Q,arrayLengthLte:v,ascii:X,between:Y,boolean:ee,containsAll:te,containsAny:re,declined:ne,different:se,distinct:ae,domain:ie,email:le,endsWith:oe,equals:ue,file:he,fileSize:R,fileSizeBetween:fe,fileSizeGt:S,fileSizeGte:y,fileSizeLt:z,fileSizeLte:g,gt:j,gte:c,http:q,httpOrHttps:ce,https:C,integer:me,ip:ye,ipv4:p,ipv6:b,json:ge,lowercase:$e,lt:O,lte:m,notContainsAll:de,notContainsAny:pe,notEquals:be,notOneOf:_,notSubsetOf:Ae,number:d,numeric:Le,object:Te,oneOf:k,protocol:$,regex:we,required:ve,same:Re,size:x,startsWith:F,string:G,stringContainsAll:Se,stringContainsAny:ze,stringLength:B,stringLengthBetween:je,stringLengthGt:E,stringLengthGte:A,stringLengthLt:D,stringLengthLte:L,stringNotContainsAll:({values:t})=>e=>s(e)?!1:typeof e=="string"?!t.every(r=>e.includes(r)):!1,stringNotContainsAny:({values:t})=>e=>s(e)?!1:typeof e=="string"?!t.some(r=>e.includes(r)):!1,subsetOf:({values:t})=>e=>s(e)?!1:Array.isArray(e)?e.every(r=>t.includes(r)):k({values:t})(e),unique:({values:t,ignored:e=[]})=>r=>s(r)?!1:(Array.isArray(e)?e:[e]).some(a=>a===r)?!0:!t.some(a=>a===r),uppercase:()=>t=>s(t)?!1:String(t)===String(t).toUpperCase(),url:()=>t=>{if(s(t))return!1;try{return new URL(String(t)),!0}catch{return!1}}};class qe{constructor({fallbackLocale:e,locale:r,plugins:a}={}){u(this,"locale","en");u(this,"fallbackLocale","en");u(this,"locales",{});u(this,"rules",{});this.registerLocales(P),this.registerRules(Fe),e&&this.setFallbackLocale(e),r&&this.setLocale(r),a&&a.forEach(l=>this.registerPlugin(l))}getLocale(){return this.locale}getFallbackLocale(){return this.fallbackLocale}setLocale(e){if(!(e in this.locales))throw new Error(`The "${e}" locale is not registered.`);return this.locale=e,this}setFallbackLocale(e){if(!(e in this.locales))throw new Error(`The "${e}" fallback locale is not registered.`);return this.fallbackLocale=e,this}defineField(e){return new T({name:e,locale:this.locale,fallbackLocale:this.fallbackLocale,locales:this.locales,rules:this.rules})}registerLocales(e){return this.locales=Object.keys(e).reduce((r,a)=>(r[a]={...this.locales[a],...e[a]},r),{...this.locales}),this}registerRules(e){return this.rules={...this.rules,...e},this}registerPlugin(e){if(!e||!e.locales||!e.rules)throw new Error('The plugin must have "locales" and "rules" properties.');return this.registerLocales(e.locales).registerRules(e.rules)}}h.FieldValidator=T,h.FormValidator=qe,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.Fortress={}))})(this,function(h){"use strict";var ke=Object.defineProperty;var Ne=(h,o,n)=>o in h?ke(h,o,{enumerable:!0,configurable:!0,writable:!0,value:n}):h[o]=n;var u=(h,o,n)=>(Ne(h,typeof o!="symbol"?o+"":o,n),n);const o=t=>{const e=",、;:!?。()《》「」『』【】〔〕",r="\\x20-\\x7E",a=new RegExp(`\\s*([${e}])`,"gu"),l=new RegExp(`([${e}])\\s*([${r}])`,"gu"),f=new RegExp(`([^${r}${e}])([${r}])`,"gu"),Ge=new RegExp(`([${r}])([^${r}${e}])`,"gu");return t.replace(a,"$1").replace(l,"$1$2").replace(f,"$1 $2").replace(Ge,"$1 $2").replace(/ +/g," ")},n=(t,e=0)=>new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e}).format(t),P=t=>Object.prototype.toString.call(t).toLowerCase().slice(8,-1),s=t=>t==null||t===""||Array.isArray(t)&&t.length<1,i=t=>`"${t}"`;class T{constructor({name:e,locale:r,fallbackLocale:a,locales:l,rules:f}){u(this,"name");u(this,"locale");u(this,"fallbackLocale");u(this,"locales");u(this,"rules");u(this,"ruleFunctions",{});u(this,"conditions",{});u(this,"shouldSkip",!1);u(this,"appliedProtocols",{});this.name=e,this.locale=r,this.fallbackLocale=a,this.locales=l,this.rules=f}get formattedName(){return this.name.toLowerCase()}get messages(){return this.locales[this.locale]||{}}get fallbackMessages(){return this.locales[this.fallbackLocale]||{}}get mandatoryRules(){return[this.required.name,this.string.name,this.array.name,this.equals.name,this.notEquals.name]}getMessage(e){return this.messages[e]||this.fallbackMessages[e]||(r=>`The ${r} field is invalid.`)}getRule(e){if(!(e in this.rules))throw new Error(`The "${e}" rule is not registered.`);return this.rules[e]}buildRuleFunction(e,r){return a=>{if(s(a)&&!this.mandatoryRules.includes(e))return!0;const l=this.getRule(e)(r)(a);return typeof l=="string"?l:l===!0?!0:this.buildRuleFunctionMessage(e,r,a)}}buildRuleFunctionMessage(e,r,a){const l=this.getMessage(e)(this.formattedName,r);if(typeof l=="object"){const f=P(a);if(!(f in l))throw new Error(`The message for the "${e}" rule of the "${f}" type is missing.`);return o(l[f])}return o(l)}pushRuleFunction(e,r){if(e in this.conditions&&!this.conditions[e])return this;const a=this.buildRuleFunction(e,r);return this.ruleFunctions[e]=a,this}getRuleFunctions(){return Object.values(this.ruleFunctions)}collect(){return this.shouldSkip?[]:this.getRuleFunctions()}validate(e){if(this.shouldSkip)return!0;const r=this.getRuleFunctions();for(const a of r){const l=a(e);if(typeof l=="string")return l}return!0}apply(e,r={}){return this.pushRuleFunction(e,r)}accepted(){return this.apply(this.accepted.name)}after(e,r,a,l=!0){return this.apply(this.after.name,{date:e,format:r,displayFormat:a,strict:l})}alpha(){return this.apply(this.alpha.name)}alphaDash(){return this.apply(this.alphaDash.name)}alphaDashDot(){return this.apply(this.alphaDashDot.name)}alphaNum(){return this.apply(this.alphaNum.name)}array(){return this.apply(this.array.name)}arrayLength(e){return this.apply(this.arrayLength.name,{length:e})}arrayLengthBetween(e,r){return this.apply(this.arrayLengthBetween.name,{min:e,max:r})}arrayLengthGt(e){return this.apply(this.arrayLengthGt.name,{length:e})}arrayLengthGte(e){return this.apply(this.arrayLengthGte.name,{length:e})}arrayLengthLt(e){return this.apply(this.arrayLengthLt.name,{length:e})}arrayLengthLte(e){return this.apply(this.arrayLengthLte.name,{length:e})}ascii(){return this.apply(this.ascii.name)}before(e,r,a,l=!0){return this.apply(this.before.name,{date:e,format:r,displayFormat:a,strict:l})}between(e,r){return this.apply(this.between.name,{min:e,max:r})}boolean(){return this.apply(this.boolean.name)}containsAll(e){return this.apply(this.containsAll.name,{values:e})}containsAny(e){return this.apply(this.containsAny.name,{values:e})}date(e,r=!0){return this.apply(this.date.name,{format:e,strict:r})}declined(){return this.apply(this.declined.name)}different(e,r){return this.apply(this.different.name,{field:e,value:r})}distinct(){return this.apply(this.distinct.name)}domain(){return this.apply(this.domain.name)}email(){return this.apply(this.email.name)}endsWith(e){return this.apply(this.endsWith.name,{value:e})}equals(e){return this.apply(this.equals.name,{value:e})}file(){return this.apply(this.file.name)}fileSize(e){return this.apply(this.fileSize.name,{size:e})}fileSizeBetween(e,r){return this.apply(this.fileSizeBetween.name,{min:e,max:r})}fileSizeGt(e){return this.apply(this.fileSizeGt.name,{size:e})}fileSizeGte(e){return this.apply(this.fileSizeGte.name,{size:e})}fileSizeLt(e){return this.apply(this.fileSizeLt.name,{size:e})}fileSizeLte(e){return this.apply(this.fileSizeLte.name,{size:e})}gt(e){return this.apply(this.gt.name,{value:e})}gte(e){return this.apply(this.gte.name,{value:e})}http(){return this.appliedProtocols[this.http.name]=!0,this.apply(this.http.name)}httpOrHttps(){return this.appliedProtocols[this.http.name]=!0,this.appliedProtocols[this.https.name]=!0,this.apply(this.httpOrHttps.name)}https(){return this.appliedProtocols[this.https.name]=!0,this.apply(this.https.name)}integer(){return this.apply(this.integer.name)}ip(){const e=Object.keys(this.appliedProtocols).length>0;return this.apply(this.ip.name,{includeProtocol:e})}ipv4(){const e=Object.keys(this.appliedProtocols).length>0;return this.apply(this.ipv4.name,{includeProtocol:e})}ipv6(){const e=Object.keys(this.appliedProtocols).length>0;return this.apply(this.ipv6.name,{includeProtocol:e})}iso8601(){return this.apply(this.iso8601.name)}json(){return this.apply(this.json.name)}jsonSchema(e){return this.apply(this.jsonSchema.name,{schema:e,locale:this.locale,field:this.name})}lowercase(){return this.apply(this.lowercase.name)}lt(e){return this.apply(this.lt.name,{value:e})}lte(e){return this.apply(this.lte.name,{value:e})}notContainsAll(e){return this.apply(this.notContainsAll.name,{values:e})}notContainsAny(e){return this.apply(this.notContainsAny.name,{values:e})}notEndsWith(e){return this.apply(this.notEndsWith.name,{value:e})}notEquals(e){return this.apply(this.notEquals.name,{value:e})}notOneOf(e){return this.apply(this.notOneOf.name,{values:e})}notStartsWith(e){return this.apply(this.notStartsWith.name,{value:e})}notStartsWithNumber(){return this.apply(this.notStartsWithNumber.name)}notSubsetOf(e){return this.apply(this.notSubsetOf.name,{values:e})}number(){return this.apply(this.number.name)}numeric(){return this.apply(this.numeric.name)}object(){return this.apply(this.object.name)}oneOf(e){return this.apply(this.oneOf.name,{values:e})}protocol(e){const r=Array.isArray(e)?e:[e];return r.forEach(a=>this.appliedProtocols[a]=!0),this.apply(this.protocol.name,{values:r})}regex(e){return this.apply(this.regex.name,{expression:e})}required(){return this.apply(this.required.name)}requiredWhen(e){return this.when({required:e}).required()}same(e,r){return this.apply(this.same.name,{field:e,value:r})}size(e){return this.apply(this.size.name,{size:e})}startsWith(e){return this.apply(this.startsWith.name,{value:e})}startsWithNumber(){return this.apply(this.startsWithNumber.name)}string(){return this.apply(this.string.name)}stringContainsAll(e){return this.apply(this.stringContainsAll.name,{values:e})}stringContainsAny(e){return this.apply(this.stringContainsAny.name,{values:e})}stringLength(e){return this.apply(this.stringLength.name,{length:e})}stringLengthBetween(e,r){return this.apply(this.stringLengthBetween.name,{min:e,max:r})}stringLengthGt(e){return this.apply(this.stringLengthGt.name,{length:e})}stringLengthGte(e){return this.apply(this.stringLengthGte.name,{length:e})}stringLengthLt(e){return this.apply(this.stringLengthLt.name,{length:e})}stringLengthLte(e){return this.apply(this.stringLengthLte.name,{length:e})}stringNotContainsAll(e){return this.apply(this.stringNotContainsAll.name,{values:e})}stringNotContainsAny(e){return this.apply(this.stringNotContainsAny.name,{values:e})}subsetOf(e){return this.apply(this.subsetOf.name,{values:e})}unique(e,r=[]){return this.apply(this.unique.name,{values:e,ignored:r})}uppercase(){return this.apply(this.uppercase.name)}url(){return this.apply(this.url.name)}when(e){return typeof e=="object"?(this.conditions=e,this):(e||(this.shouldSkip=!0),this)}}const I={en:{accepted:t=>`The ${t} field must be accepted.`,alpha:t=>`The ${t} field must only contain letters.`,alphaDash:t=>`The ${t} field must only contain letters, numbers, dashes and underscores.`,alphaDashDot:t=>`The ${t} field must only contain letters, numbers, dashes, underscores and dots.`,alphaNum:t=>`The ${t} field must only contain letters and numbers.`,array:t=>`The ${t} field must be an array.`,arrayLength:(t,e)=>{const{length:r}=e;return`The ${t} field must be ${n(r)} items.`},arrayLengthBetween:(t,e)=>{const{min:r,max:a}=e;return`The ${t} field must be between ${n(r)} and ${n(a)} items.`},arrayLengthGt:(t,e)=>{const{length:r}=e;return`The ${t} field must be greater than ${n(r)} items.`},arrayLengthGte:(t,e)=>{const{length:r}=e;return`The ${t} field must be greater than or equal to ${n(r)} items.`},arrayLengthLte:(t,e)=>{const{length:r}=e;return`The ${t} field must be less than or equal to ${n(r)} items.`},arrayLengthLt:(t,e)=>{const{length:r}=e;return`The ${t} field must be less than ${n(r)} items.`},ascii:t=>`The ${t} field must only contain ASCII characters and symbols.`,between:(t,e)=>{const{min:r,max:a}=e;return{number:`The ${t} field must be between ${n(r)} and ${n(a)}.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(a)}.`}},boolean:t=>`The ${t} field must be a boolean value.`,containsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must contain all of the following values: ${r.map(i).join(", ")}.`},containsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following values: ${r.map(i).join(", ")}.`},declined:t=>`The ${t} field must be declined.`,different:(t,e)=>{const{field:r}=e;return`The ${t} and ${r} fields must be different.`},distinct:t=>`The ${t} field must not contain duplicate values.`,domain:t=>`The ${t} field must be a valid domain.`,email:t=>`The ${t} field must be a valid email address.`,endsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must end with ${i(r)}.`},equals:(t,e)=>{const{value:r}=e;return`The ${t} field must be equal to ${r}.`},file:t=>`The ${t} field must be a file.`,fileSizeBetween:(t,e)=>{const{min:r,max:a}=e;return{file:`The ${t} field must be between ${n(r)} and ${n(a)} kilobytes.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(a)} kilobytes.`}},fileSizeGt:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be greater than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is greater than ${n(r)} kilobytes.`}},fileSizeGte:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be greater than or equal to ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is greater than or equal to ${n(r)} kilobytes.`}},fileSizeLt:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be less than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is less than ${n(r)} kilobytes.`}},fileSizeLte:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be less than or equal to ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is less than or equal to ${n(r)} kilobytes.`}},fileSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is ${n(r)} kilobytes.`}},http:t=>`The ${t} field must start with the "http://" protocol.`,httpOrHttps:t=>`The ${t} field must start with the "http://" or "https://" protocols.`,https:t=>`The ${t} field must start with the "https://" protocol.`,integer:t=>`The ${t} field must be an integer.`,ip:t=>`The ${t} field must be a valid IP address.`,ipv4:t=>`The ${t} field must be a valid IPv4 address.`,ipv6:t=>`The ${t} field must be a valid IPv6 address.`,json:t=>`The ${t} field must be a valid JSON string.`,lowercase:t=>`The ${t} field must be lowercase.`,lt:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be less than ${n(r)}.`,array:`The ${t} field must contain items where each item is less than ${n(r)}.`}},lte:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be less than or equal to ${n(r)}.`,array:`The ${t} field must contain items where each item is less than or equal to ${n(r)}.`}},gt:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be greater than ${n(r)}.`,array:`The ${t} field must contain items where each item is greater than ${n(r)}.`}},gte:(t,e)=>{const{value:r}=e;return{number:`The ${t} field must be greater than or equal to ${n(r)}.`,array:`The ${t} field must contain items where each item is greater than or equal to ${n(r)}.`}},notContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain all of the following values together: ${r.map(i).join(", ")}.`},notEndsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must not end with ${i(r)}.`},notContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain any of the following values: ${r.map(i).join(", ")}.`},notEquals:(t,e)=>{const{value:r}=e;return`The ${t} field must not be equal to ${r}.`},notOneOf:(t,e)=>{const{values:r}=e;return`The ${t} field must not be one of the following values: ${r.map(i).join(", ")}.`},notStartsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must not start with ${i(r)}.`},notStartsWithNumber:t=>`The ${t} field must not start with a number.`,notSubsetOf:(t,e)=>{const{values:r}=e;return`The ${t} field must not be a subset of the following values: ${r.map(i).join(", ")}.`},number:t=>`The ${t} field must be a number.`,numeric:t=>`The ${t} field must be a number.`,object:t=>`The ${t} field must be an object.`,oneOf:(t,e)=>{const{values:r}=e;return`The ${t} field must be one of the following values: ${r.map(i).join(", ")}.`},protocol:(t,e)=>{const{values:r}=e;if(r.length===1){const[a]=r;return`The ${t} field must start with the "${a}://" protocol.`}return`The ${t} field must start with one of the following protocols: ${r.map(a=>`${a}://`).map(i).join(", ")}.`},regex:t=>`The ${t} field must match the required format.`,required:t=>`The ${t} field is required.`,same:(t,e)=>{const{field:r}=e;return`The ${t} and ${r} fields must match.`},size:(t,e)=>{const{size:r}=e;return{number:`The ${t} field must be ${n(r)}.`,array:`The ${t} field must contain items where each item is ${n(r)}.`}},startsWith:(t,e)=>{const{value:r}=e;return`The ${t} field must start with ${i(r)}.`},startsWithNumber:t=>`The ${t} field must start with a number.`,string:t=>`The ${t} field must be a string.`,stringContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must contain all of the following text: ${r.map(i).join(", ")}.`},stringContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following text: ${r.map(i).join(", ")}.`},stringLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be ${n(r)} characters.`,array:`The ${t} field must contain items where each item is ${n(r)} characters.`}},stringLengthBetween:(t,e)=>{const{min:r,max:a}=e;return{string:`The ${t} field must be between ${n(r)} and ${n(a)} characters.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(a)} characters.`}},stringLengthGt:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be greater than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is greater than ${n(r)} characters.`}},stringLengthGte:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be greater than or equal to ${n(r)} characters.`,array:`The ${t} field must contain items where each item is greater than or equal to ${n(r)} characters.`}},stringLengthLt:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be less than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is less than ${n(r)} characters.`}},stringLengthLte:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be less than or equal to ${n(r)} characters.`,array:`The ${t} field must contain items where each item is less than or equal to ${n(r)} characters.`}},stringNotContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain all of the following text together: ${r.map(i).join(", ")}.`},stringNotContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain any of the following text: ${r.map(i).join(", ")}.`},subsetOf:(t,e)=>{const{values:r}=e;return`The ${t} field must be a subset of the following values: ${r.map(i).join(", ")}.`},unique:t=>`The ${t} field has already been taken.`,uppercase:t=>`The ${t} field must be uppercase.`,url:t=>`The ${t} field must be a valid URL.`},"zh-TW":{accepted:()=>"此欄位必須被同意",alpha:()=>"此欄位只能包含字母",alphaDash:()=>"此欄位只能包含字母、數字、連接號和底線",alphaDashDot:()=>"此欄位只能包含字母、數字、連接號、底線和點",alphaNum:()=>"此欄位只能包含字母和數字",array:()=>"此欄位必須是一個陣列",arrayLength:(t,e)=>{const{length:r}=e;return`此欄位必須是${n(r)}個項目`},arrayLengthBetween:(t,e)=>{const{min:r,max:a}=e;return`此欄位必須介於${n(r)}到${n(a)}個項目之間`},arrayLengthGt:(t,e)=>{const{length:r}=e;return`此欄位必須大於${n(r)}個項目`},arrayLengthGte:(t,e)=>{const{length:r}=e;return`此欄位必須大於或等於${n(r)}個項目`},arrayLengthLt:(t,e)=>{const{length:r}=e;return`此欄位必須小於${n(r)}個項目`},arrayLengthLte:(t,e)=>{const{length:r}=e;return`此欄位必須小於或等於${n(r)}個項目`},ascii:()=>"此欄位只能包含 ASCII 字元和符號",between:(t,e)=>{const{min:r,max:a}=e;return{number:`此欄位必須介於${n(r)}到${n(a)}`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(a)}`}},boolean:()=>"此欄位必須是一個布林值",containsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有項目:${r.map(i).join(", ")}`},containsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個項目:${r.map(i).join(", ")}`},declined:()=>"此欄位必須被拒絕",different:(t,e)=>{const{field:r}=e;return`此欄位必須和${r}欄位不同`},distinct:()=>"此欄位不能包含重複的值",domain:()=>"此欄位必須是有效的網域",email:()=>"此欄位必須是有效的電子郵件地址",endsWith:(t,e)=>{const{value:r}=e;return`此欄位必須以${i(r)}結尾`},equals:(t,e)=>{const{value:r}=e;return`此欄位必須是${r}`},file:()=>"此欄位必須是檔案",fileSize:(t,e)=>{const{size:r}=e;return{file:`此欄位必須是${n(r)} KB`,array:`此欄位中的每個項目都必須是${n(r)} KB`}},fileSizeBetween:(t,e)=>{const{min:r,max:a}=e;return{file:`此欄位必須介於${n(r)}到${n(a)} KB 之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(a)} KB 之間`}},fileSizeGt:(t,e)=>{const{size:r}=e;return{file:`此欄位必須大於${n(r)} KB`,array:`此欄位中的每個項目都必須大於${n(r)} KB`}},fileSizeGte:(t,e)=>{const{size:r}=e;return{file:`此欄位必須大於或等於${n(r)} KB`,array:`此欄位中的每個項目都必須大於或等於${n(r)} KB`}},fileSizeLt:(t,e)=>{const{size:r}=e;return{file:`此欄位必須小於${n(r)} KB`,array:`此欄位中的每個項目都必須小於${n(r)} KB`}},fileSizeLte:(t,e)=>{const{size:r}=e;return{file:`此欄位必須小於或等於${n(r)} KB`,array:`此欄位中的每個項目都必須小於或等於${n(r)} KB`}},gt:(t,e)=>{const{value:r}=e;return{number:`此欄位必須大於${n(r)}`,array:`此欄位中的每個項目都必須大於${n(r)}`}},gte:(t,e)=>{const{value:r}=e;return{number:`此欄位必須大於或等於${n(r)}`,array:`此欄位中的每個項目都必須大於或等於${n(r)}`}},http:()=>'此欄位必須以 "http://" 協議開頭',httpOrHttps:()=>'此欄位必須以 "http://" 或 "https://" 協議開頭',https:()=>'此欄位必須以 "https://" 協議開頭',integer:()=>"此欄位必須是整數",ip:()=>"此欄位必須是有效的 IP 位址",ipv4:()=>"此欄位必須是有效的 IPv4 位址",ipv6:()=>"此欄位必須是有效的 IPv6 位址",json:()=>"此欄位必須是有效的 JSON 字串",lowercase:()=>"此欄位必須是小寫",lt:(t,e)=>{const{value:r}=e;return{number:`此欄位必須小於${n(r)}`,array:`此欄位中的每個項目都必須小於${n(r)}`}},lte:(t,e)=>{const{value:r}=e;return{number:`此欄位必須小於或等於${n(r)}`,array:`此欄位中的每個項目都必須小於或等於${n(r)}`}},notContainsAll:(t,e)=>{const{values:r}=e;return`此欄位不能同時包含以下所有值:${r.map(i).join(", ")}`},notEndsWith:(t,e)=>{const{value:r}=e;return`此欄位不能以${i(r)}結尾`},notContainsAny:(t,e)=>{const{values:r}=e;return`此欄位不能包含以下任何值:${r.map(i).join(", ")}`},notEquals:(t,e)=>{const{value:r}=e;return`此欄位不能是${r}`},notOneOf:(t,e)=>{const{values:r}=e;return`此欄位不能是以下任何值:${r.map(i).join(", ")}`},notStartsWith:(t,e)=>{const{value:r}=e;return`此欄位不能以${i(r)}開頭`},notStartsWithNumber:()=>"此欄位不能以數字開頭",notSubsetOf:(t,e)=>{const{values:r}=e;return`此欄位不能是以下項目的子集:${r.map(i).join(", ")}`},number:()=>"此欄位必須是數字",numeric:()=>"此欄位必須是數字",object:()=>"此欄位必須是物件",oneOf:(t,e)=>{const{values:r}=e;return`此欄位必須是以下其中一個值:${r.map(i).join(", ")}`},protocol:(t,e)=>{const{values:r}=e;if(r.length===1){const[a]=r;return`此欄位必須以 "${a}://" 協議開頭`}return`此欄位必須以以下其中一個協議開頭:${r.map(a=>`${a}://`).map(i).join(", ")}`},regex:()=>"此欄位必須符合所需的格式",required:()=>"此欄位為必填",same:(t,e)=>{const{field:r}=e;return`此欄位必須與${r}欄位相同`},size:(t,e)=>{const{size:r}=e;return{number:`此欄位必須是${n(r)}`,array:`此欄位中的每個項目都必須是${n(r)}`}},startsWith:(t,e)=>{const{value:r}=e;return`此欄位必須以${i(r)}開頭`},startsWithNumber:()=>"此欄位必須以數字開頭",string:()=>"此欄位必須是字串",stringContainsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有文字:${r.map(i).join(", ")}`},stringContainsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個文字:${r.map(i).join(", ")}`},stringLength:(t,e)=>{const{length:r}=e;return{string:`此欄位必須是${n(r)}個字元`,array:`此欄位中的每個項目都必須是${n(r)}個字元`}},stringLengthBetween:(t,e)=>{const{min:r,max:a}=e;return{string:`此欄位必須介於${n(r)}到${n(a)}個字元之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(a)}個字元之間`}},stringLengthGt:(t,e)=>{const{length:r}=e;return{string:`此欄位必須大於${n(r)}個字元`,array:`此欄位中的每個項目都必須大於${n(r)}個字元`}},stringLengthGte:(t,e)=>{const{length:r}=e;return{string:`此欄位必須大於或等於${n(r)}個字元`,array:`此欄位中的每個項目都必須大於或等於${n(r)}個字元`}},stringLengthLt:(t,e)=>{const{length:r}=e;return{string:`此欄位必須小於${n(r)}個字元`,array:`此欄位中的每個項目都必須小於${n(r)}個字元`}},stringLengthLte:(t,e)=>{const{length:r}=e;return{string:`此欄位必須小於或等於${n(r)}個字元`,array:`此欄位中的每個項目都必須小於或等於${n(r)}個字元`}},stringNotContainsAll:(t,e)=>{const{values:r}=e;return`此欄位不能同時包含以下所有文字:${r.map(i).join(", ")}`},stringNotContainsAny:(t,e)=>{const{values:r}=e;return`此欄位不能包含以下任何文字:${r.map(i).join(", ")}`},subsetOf:(t,e)=>{const{values:r}=e;return`此欄位必須是以下項目的子集:${r.map(i).join(", ")}`},unique:()=>"此欄位已經存在",uppercase:()=>"此欄位必須是大寫",url:()=>"此欄位必須是有效的 URL"}},K=()=>t=>s(t)?!1:["y","yes","on","1","true"].includes(String(t).toLowerCase()),Z=()=>t=>s(t)?!1:/^[a-zA-Z]+$/.test(String(t)),M=()=>t=>s(t)?!1:/^[a-zA-Z0-9-_]+$/.test(String(t)),H=()=>t=>s(t)?!1:/^[a-zA-Z0-9-_.]+$/.test(String(t)),U=()=>t=>s(t)?!1:/^[a-zA-Z0-9]+$/.test(String(t)),V=()=>t=>Array.isArray(t),J=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length===t:!1,v=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length>=t:!1,R=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length<=t:!1,Q=({min:t,max:e})=>r=>s(r)?!1:v({length:t})(r)&&R({length:e})(r),X=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length>t:!1,Y=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length<t:!1,ee=()=>t=>s(t)?!1:/^[\x20-\x7E]+$/.test(String(t)),c=({value:t})=>e=>s(e)?!1:typeof e=="number"?e>=t:Array.isArray(e)?e.every(r=>c({value:t})(r)):!1,m=({value:t})=>e=>s(e)?!1:typeof e=="number"?e<=t:Array.isArray(e)?e.every(r=>m({value:t})(r)):!1,te=({min:t,max:e})=>r=>s(r)?!1:c({value:t})(r)&&m({value:e})(r),re=()=>t=>s(t)?!1:typeof t=="boolean",ne=({values:t})=>e=>s(e)?!1:Array.isArray(e)?t.every(r=>e.includes(r)):!1,se=({values:t})=>e=>s(e)?!1:Array.isArray(e)?t.some(r=>e.includes(r)):!1,ae=()=>t=>s(t)?!1:["n","no","off","0","false"].includes(String(t).toLowerCase()),ie=({value:t})=>e=>s(e)?!1:e!==t,le=()=>t=>s(t)?!1:Array.isArray(t)?new Set(t).size===t.length:!0,oe=()=>t=>s(t)?!1:/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),ue=()=>t=>s(t)?!1:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),S=({value:t})=>e=>s(e)?!1:String(e).toLowerCase().endsWith(t.toLowerCase()),he=({value:t})=>e=>e===t,fe=()=>t=>t instanceof File,z=({size:t})=>e=>{if(s(e))return!1;if(e instanceof File){const r=t*1024,a=(t+1)*1024;return e.size>=r&&e.size<a}return Array.isArray(e)?e.every(r=>z({size:t})(r)):!1},y=({size:t})=>e=>s(e)?!1:e instanceof File?e.size>=t*1024:Array.isArray(e)?e.every(r=>y({size:t})(r)):!1,g=({size:t})=>e=>s(e)?!1:e instanceof File?e.size<=t*1024:Array.isArray(e)?e.every(r=>g({size:t})(r)):!1,ce=({min:t,max:e})=>r=>s(r)?!1:y({size:t})(r)&&g({size:e})(r),j=({size:t})=>e=>s(e)?!1:e instanceof File?e.size>t*1024:Array.isArray(e)?e.every(r=>j({size:t})(r)):!1,F=({size:t})=>e=>s(e)?!1:e instanceof File?e.size<t*1024:Array.isArray(e)?e.every(r=>F({size:t})(r)):!1,C=({value:t})=>e=>s(e)?!1:typeof e=="number"?e>t:Array.isArray(e)?e.every(r=>C({value:t})(r)):!1,$=({value:t})=>e=>s(e)?!1:String(e).toLowerCase().startsWith(t.toLowerCase()),d=({values:t})=>e=>s(e)?!1:t.map(r=>`${r}://`).some(r=>$({value:r})(e)),q=()=>t=>s(t)?!1:d({values:["http"]})(t),_=()=>t=>s(t)?!1:d({values:["https"]})(t),me=()=>t=>s(t)?!1:q()(t)||_()(t),p=()=>t=>s(t)?!1:typeof t=="number",ye=()=>t=>s(t)?!1:p()(t)&&Number.isInteger(t),b=({includeProtocol:t}={})=>e=>{if(s(e))return!1;if(t)try{const{host:r}=new URL(String(e));return b({})(r)}catch{return!1}return/^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:\d+)?$/.test(String(e))},A=({includeProtocol:t}={})=>e=>{if(s(e))return!1;if(t)try{const{host:r}=new URL(String(e));return A({})(r)}catch{return!1}return/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/.test(String(e))},ge=({includeProtocol:t}={})=>e=>s(e)?!1:b({includeProtocol:t})(e)||A({includeProtocol:t})(e),$e=()=>t=>{if(s(t))return!1;try{return JSON.parse(String(t)),!0}catch{return!1}},de=()=>t=>s(t)?!1:String(t)===String(t).toLowerCase(),O=({value:t})=>e=>s(e)?!1:typeof e=="number"?e<t:Array.isArray(e)?e.every(r=>O({value:t})(r)):!1,pe=({values:t})=>e=>s(e)?!1:Array.isArray(e)?!t.every(r=>e.includes(r)):!1,be=({values:t})=>e=>s(e)?!1:Array.isArray(e)?!t.some(r=>e.includes(r)):!1,Ae=({value:t})=>e=>s(e)?!1:!S({value:t})(e),Le=({value:t})=>e=>e!==t,W=({values:t})=>e=>s(e)?!1:!t.includes(e),we=({value:t})=>e=>s(e)?!1:!$({value:t})(e),G=()=>t=>s(t)?!1:/^\d/.test(String(t)),Te=()=>t=>s(t)?!1:!G()(t),ve=({values:t})=>e=>s(e)?!1:Array.isArray(e)?e.some(r=>!t.includes(r)):W({values:t})(e),k=()=>t=>typeof t=="string",Re=()=>t=>s(t)?!1:k()(t)?/^-?\d+(\.\d+)?$/.test(String(t)):p()(t),Se=()=>t=>typeof t=="object"&&t!==null&&!Array.isArray(t),N=({values:t})=>e=>s(e)?!1:t.includes(e),ze=({expression:t})=>e=>{if(s(e))return!1;if(!(t instanceof RegExp))throw new TypeError("The expression provided is not a valid RegExp.");return t.test(String(e))},je=()=>t=>!s(t),Fe=({value:t})=>e=>s(e)?!1:Array.isArray(e)?e.every(r=>r===t):e===t,x=({size:t})=>e=>s(e)?!1:typeof e=="number"?e===t:Array.isArray(e)?e.every(r=>x({size:t})(r)):!1,Ce=({values:t})=>e=>s(e)?!1:typeof e=="string"?t.every(r=>e.includes(r)):!1,qe=({values:t})=>e=>s(e)?!1:typeof e=="string"?t.some(r=>e.includes(r)):!1,B=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length===t:Array.isArray(e)?e.every(r=>B({length:t})(r)):!1,L=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length>=t:Array.isArray(e)?e.every(r=>L({length:t})(r)):!1,w=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length<=t:Array.isArray(e)?e.every(r=>w({length:t})(r)):!1,_e=({min:t,max:e})=>r=>s(r)?!1:L({length:t})(r)&&w({length:e})(r),E=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length>t:Array.isArray(e)?e.every(r=>E({length:t})(r)):!1,D=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length<t:Array.isArray(e)?e.every(r=>D({length:t})(r)):!1,Oe={accepted:K,alpha:Z,alphaDash:M,alphaDashDot:H,alphaNum:U,array:V,arrayLength:J,arrayLengthBetween:Q,arrayLengthGt:X,arrayLengthGte:v,arrayLengthLt:Y,arrayLengthLte:R,ascii:ee,between:te,boolean:re,containsAll:ne,containsAny:se,declined:ae,different:ie,distinct:le,domain:oe,email:ue,endsWith:S,equals:he,file:fe,fileSize:z,fileSizeBetween:ce,fileSizeGt:j,fileSizeGte:y,fileSizeLt:F,fileSizeLte:g,gt:C,gte:c,http:q,httpOrHttps:me,https:_,integer:ye,ip:ge,ipv4:b,ipv6:A,json:$e,lowercase:de,lt:O,lte:m,notContainsAll:pe,notContainsAny:be,notEndsWith:Ae,notEquals:Le,notOneOf:W,notStartsWith:we,notStartsWithNumber:Te,notSubsetOf:ve,number:p,numeric:Re,object:Se,oneOf:N,protocol:d,regex:ze,required:je,same:Fe,size:x,startsWith:$,startsWithNumber:G,string:k,stringContainsAll:Ce,stringContainsAny:qe,stringLength:B,stringLengthBetween:_e,stringLengthGt:E,stringLengthGte:L,stringLengthLt:D,stringLengthLte:w,stringNotContainsAll:({values:t})=>e=>s(e)?!1:typeof e=="string"?!t.every(r=>e.includes(r)):!1,stringNotContainsAny:({values:t})=>e=>s(e)?!1:typeof e=="string"?!t.some(r=>e.includes(r)):!1,subsetOf:({values:t})=>e=>s(e)?!1:Array.isArray(e)?e.every(r=>t.includes(r)):N({values:t})(e),unique:({values:t,ignored:e=[]})=>r=>s(r)?!1:(Array.isArray(e)?e:[e]).some(a=>a===r)?!0:!t.some(a=>a===r),uppercase:()=>t=>s(t)?!1:String(t)===String(t).toUpperCase(),url:()=>t=>{if(s(t))return!1;try{return new URL(String(t)),!0}catch{return!1}}};class We{constructor({fallbackLocale:e,locale:r,plugins:a}={}){u(this,"locale","en");u(this,"fallbackLocale","en");u(this,"locales",{});u(this,"rules",{});this.registerLocales(I),this.registerRules(Oe),e&&this.setFallbackLocale(e),r&&this.setLocale(r),a&&a.forEach(l=>this.registerPlugin(l))}getLocale(){return this.locale}getFallbackLocale(){return this.fallbackLocale}setLocale(e){if(!(e in this.locales))throw new Error(`The "${e}" locale is not registered.`);return this.locale=e,this}setFallbackLocale(e){if(!(e in this.locales))throw new Error(`The "${e}" fallback locale is not registered.`);return this.fallbackLocale=e,this}defineField(e){return new T({name:e,locale:this.locale,fallbackLocale:this.fallbackLocale,locales:this.locales,rules:this.rules})}registerLocales(e){return this.locales=Object.keys(e).reduce((r,a)=>(r[a]={...this.locales[a],...e[a]},r),{...this.locales}),this}registerRules(e){return this.rules={...this.rules,...e},this}registerPlugin(e){if(!e||!e.locales||!e.rules)throw new Error('The plugin must have "locales" and "rules" properties.');return this.registerLocales(e.locales).registerRules(e.rules)}}h.FieldValidator=T,h.FormValidator=We,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
-
export interface
|
|
2
|
+
export interface StartsWithRuleArguments extends RuleArguments {
|
|
3
3
|
value: string;
|
|
4
4
|
}
|
|
5
|
-
declare const startsWithRule: Rule<
|
|
5
|
+
declare const startsWithRule: Rule<StartsWithRuleArguments>;
|
|
6
6
|
export default startsWithRule;
|