@kklab/fortress-validator 1.0.9 → 1.0.10
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 +9 -3
- package/dist/FieldValidator.d.ts +30 -6
- package/dist/index.js +221 -123
- package/dist/index.umd.js +1 -1
- package/dist/rules/notContainsAll.d.ts +6 -0
- package/dist/rules/notContainsAny.d.ts +6 -0
- package/dist/rules/notOneOf.d.ts +6 -0
- package/dist/rules/oneOf.d.ts +6 -0
- package/dist/rules/stringContainsAll.d.ts +6 -0
- package/dist/rules/stringContainsAny.d.ts +6 -0
- package/dist/rules/stringNotContainsAll.d.ts +6 -0
- package/dist/rules/stringNotContainsAny.d.ts +6 -0
- package/package.json +1 -1
- package/dist/rules/in.d.ts +0 -6
- package/dist/rules/notIn.d.ts +0 -6
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ const result = validator
|
|
|
77
77
|
| `between` | Passes if the field's value is between the specified minimum and maximum values. |
|
|
78
78
|
| `betweenLength` | Passes if the field's value is between the specified minimum and maximum lengths. |
|
|
79
79
|
| `boolean` | Passes if the field's value is a boolean. |
|
|
80
|
-
| `containsAll` | Passes if the field's value contains all the specified values. |
|
|
80
|
+
| `containsAll` | Passes if the field's value contains all of the specified values. |
|
|
81
81
|
| `containsAny` | Passes if the field's value contains at least one of the specified values. |
|
|
82
82
|
| `date` | Passes if the field's value matches the specified date format. |
|
|
83
83
|
| `declined` | Passes if the field's value is considered declined (i.e., "n", "no", "off", "0", "false"). |
|
|
@@ -94,7 +94,6 @@ const result = validator
|
|
|
94
94
|
| `fileSize` | Passes if the field's value matches the specified file size. |
|
|
95
95
|
| `http` | Passes if the field's value starts with "http://" or "https://". |
|
|
96
96
|
| `https` | Passes if the field's value starts with "https://". |
|
|
97
|
-
| `in` | Passes if the field's value is one of the specified values. |
|
|
98
97
|
| `integer` | Passes if the field's value is an integer. |
|
|
99
98
|
| `iso8601` | Passes if the field's value is a valid ISO 8601 date. |
|
|
100
99
|
| `json` | Passes if the field's value is a valid JSON string. |
|
|
@@ -105,10 +104,13 @@ const result = validator
|
|
|
105
104
|
| `maxLength` | Passes if the field's value is not greater than the specified maximum length. |
|
|
106
105
|
| `min` | Passes if the field's value is at least the specified minimum. |
|
|
107
106
|
| `minLength` | Passes if the field's value is at least the specified minimum length. |
|
|
107
|
+
| `notContainsAll` | Passes if the field's value does not contain all of the specified values together. |
|
|
108
|
+
| `notContainsAny` | Passes if the field's value does not contain any of the specified values. |
|
|
108
109
|
| `notEquals` | Passes if the field's value is not equal to the specified value. |
|
|
109
|
-
| `
|
|
110
|
+
| `notOneOf` | Passes if the field's value is not one of the specified values. |
|
|
110
111
|
| `number` | Passes if the field's value is a number. |
|
|
111
112
|
| `numeric` | Passes if the field's value contains only numeric characters. |
|
|
113
|
+
| `oneOf` | Passes if the field's value is one of the specified values. |
|
|
112
114
|
| `regex` | Passes if the field's value matches the specified regular expression. |
|
|
113
115
|
| `required` | Passes if the field's value is not empty. |
|
|
114
116
|
| `requiredWhen` | Passes if the field's value is not empty when the specified condition is true. |
|
|
@@ -117,9 +119,13 @@ const result = validator
|
|
|
117
119
|
| `startsWith` | Passes if the field's value starts with the specified value. |
|
|
118
120
|
| `string` | Passes if the field's value is a string. |
|
|
119
121
|
| `stringBetweenLength` | Passes if the field's value is between the specified minimum and maximum string lengths. |
|
|
122
|
+
| `stringContainsAll` | Passes if the field's value contains all of the specified text. |
|
|
123
|
+
| `stringContainsAny` | Passes if the field's value contains at least one of the specified text. |
|
|
120
124
|
| `stringLength` | Passes if the field's value matches the specified string length. |
|
|
121
125
|
| `stringMaxLength` | Passes if the field's value is not greater than the specified maximum string length. |
|
|
122
126
|
| `stringMinLength` | Passes if the field's value is at least the specified minimum string length. |
|
|
127
|
+
| `stringNotContainsAll` | Passes if the field's value does not contain all of the specified text together. |
|
|
128
|
+
| `stringNotContainsAny` | Passes if the field's value does not contain any of the specified text. |
|
|
123
129
|
| `unique` | Passes if the field's value contains only unique items, with optional ignored values. |
|
|
124
130
|
| `uppercase` | Passes if the field's value contains only uppercase characters. |
|
|
125
131
|
| `url` | Passes if the field's value is a valid URL. |
|
package/dist/FieldValidator.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ declare class FieldValidator {
|
|
|
81
81
|
*/
|
|
82
82
|
boolean(): this;
|
|
83
83
|
/**
|
|
84
|
-
* Passes if the field's value contains all the specified values.
|
|
84
|
+
* Passes if the field's value contains all of the specified values.
|
|
85
85
|
*/
|
|
86
86
|
containsAll(values: unknown[]): this;
|
|
87
87
|
/**
|
|
@@ -148,10 +148,6 @@ declare class FieldValidator {
|
|
|
148
148
|
* Passes if the field's value starts with "https://".
|
|
149
149
|
*/
|
|
150
150
|
https(): this;
|
|
151
|
-
/**
|
|
152
|
-
* Passes if the field's value is one of the specified values.
|
|
153
|
-
*/
|
|
154
|
-
in(values: unknown[]): this;
|
|
155
151
|
/**
|
|
156
152
|
* Passes if the field's value is an integer.
|
|
157
153
|
*/
|
|
@@ -192,6 +188,14 @@ declare class FieldValidator {
|
|
|
192
188
|
* Passes if the field's value is at least the specified minimum length.
|
|
193
189
|
*/
|
|
194
190
|
minLength(length: number): this;
|
|
191
|
+
/**
|
|
192
|
+
* Passes if the field's value does not contain all of the specified values together.
|
|
193
|
+
*/
|
|
194
|
+
notContainsAll(values: unknown[]): this;
|
|
195
|
+
/**
|
|
196
|
+
* Passes if the field's value does not contain any of the specified values.
|
|
197
|
+
*/
|
|
198
|
+
notContainsAny(values: unknown[]): this;
|
|
195
199
|
/**
|
|
196
200
|
* Passes if the field's value is not equal to the specified value.
|
|
197
201
|
*/
|
|
@@ -199,7 +203,7 @@ declare class FieldValidator {
|
|
|
199
203
|
/**
|
|
200
204
|
* Passes if the field's value is not one of the specified values.
|
|
201
205
|
*/
|
|
202
|
-
|
|
206
|
+
notOneOf(values: string[]): this;
|
|
203
207
|
/**
|
|
204
208
|
* Passes if the field's value is a number.
|
|
205
209
|
*/
|
|
@@ -208,6 +212,10 @@ declare class FieldValidator {
|
|
|
208
212
|
* Passes if the field's value contains only numeric characters.
|
|
209
213
|
*/
|
|
210
214
|
numeric(): this;
|
|
215
|
+
/**
|
|
216
|
+
* Passes if the field's value is one of the specified values.
|
|
217
|
+
*/
|
|
218
|
+
oneOf(values: unknown[]): this;
|
|
211
219
|
/**
|
|
212
220
|
* Passes if the field's value matches the specified regular expression.
|
|
213
221
|
*/
|
|
@@ -240,6 +248,14 @@ declare class FieldValidator {
|
|
|
240
248
|
* Passes if the field's value is between the specified minimum and maximum string lengths.
|
|
241
249
|
*/
|
|
242
250
|
stringBetweenLength(min: number, max: number): this;
|
|
251
|
+
/**
|
|
252
|
+
* Passes if the field's value contains all of the specified text.
|
|
253
|
+
*/
|
|
254
|
+
stringContainsAll(values: string[]): this;
|
|
255
|
+
/**
|
|
256
|
+
* Passes if the field's value contains at least one of the specified text.
|
|
257
|
+
*/
|
|
258
|
+
stringContainsAny(values: string[]): this;
|
|
243
259
|
/**
|
|
244
260
|
* Passes if the field's value matches the specified string length.
|
|
245
261
|
*/
|
|
@@ -252,6 +268,14 @@ declare class FieldValidator {
|
|
|
252
268
|
* Passes if the field's value is at least the specified minimum string length.
|
|
253
269
|
*/
|
|
254
270
|
stringMinLength(length: number): this;
|
|
271
|
+
/**
|
|
272
|
+
* Passes if the field's value does not contain all of the specified text together.
|
|
273
|
+
*/
|
|
274
|
+
stringNotContainsAll(values: string[]): this;
|
|
275
|
+
/**
|
|
276
|
+
* Passes if the field's value does not contain any of the specified text.
|
|
277
|
+
*/
|
|
278
|
+
stringNotContainsAny(values: string[]): this;
|
|
255
279
|
/**
|
|
256
280
|
* Passes if the field's value contains only unique items, with optional ignored values.
|
|
257
281
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
var
|
|
2
|
-
var S = (t, e, r) => e in t ?
|
|
1
|
+
var x = Object.defineProperty;
|
|
2
|
+
var S = (t, e, r) => e in t ? x(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
3
3
|
var l = (t, e, r) => (S(t, typeof e != "symbol" ? e + "" : e, r), r);
|
|
4
4
|
const $ = (t) => t.replace(/([^\x20-\x7E])([\x20-\x7E])/gu, "$1 $2").replace(/([\x20-\x7E])([^\x20-\x7E])/gu, "$1 $2").replace(/ +/g, " "), n = (t, e = 0) => new Intl.NumberFormat(void 0, {
|
|
5
5
|
minimumFractionDigits: e,
|
|
6
6
|
maximumFractionDigits: e
|
|
7
|
-
}).format(t), z = (t) => Object.prototype.toString.call(t).toLowerCase().slice(8, -1),
|
|
8
|
-
class
|
|
7
|
+
}).format(t), z = (t) => Object.prototype.toString.call(t).toLowerCase().slice(8, -1), s = (t) => t == null || t === "" || Array.isArray(t) && t.length < 1;
|
|
8
|
+
class C {
|
|
9
9
|
constructor({
|
|
10
10
|
name: e,
|
|
11
11
|
locale: r,
|
|
12
|
-
fallbackLocale:
|
|
13
|
-
locales:
|
|
12
|
+
fallbackLocale: i,
|
|
13
|
+
locales: a,
|
|
14
14
|
rules: u
|
|
15
15
|
}) {
|
|
16
16
|
l(this, "name");
|
|
@@ -21,7 +21,7 @@ class x {
|
|
|
21
21
|
l(this, "ruleFunctions", []);
|
|
22
22
|
l(this, "conditions", {});
|
|
23
23
|
l(this, "shouldSkip", !1);
|
|
24
|
-
this.name = e, this.locale = r, this.fallbackLocale =
|
|
24
|
+
this.name = e, this.locale = r, this.fallbackLocale = i, this.locales = a, this.rules = u;
|
|
25
25
|
}
|
|
26
26
|
get formattedName() {
|
|
27
27
|
return this.name.toLowerCase();
|
|
@@ -50,28 +50,28 @@ class x {
|
|
|
50
50
|
return this.rules[e];
|
|
51
51
|
}
|
|
52
52
|
buildRuleFunction(e, r) {
|
|
53
|
-
return (
|
|
54
|
-
if (
|
|
53
|
+
return (i) => {
|
|
54
|
+
if (s(i) && !this.mandatoryRules.includes(e))
|
|
55
55
|
return !0;
|
|
56
|
-
const
|
|
57
|
-
return typeof
|
|
56
|
+
const a = this.getRule(e)(r)(i);
|
|
57
|
+
return typeof a == "string" ? a : a === !0 ? !0 : this.buildRuleFunctionMessage(e, r, i);
|
|
58
58
|
};
|
|
59
59
|
}
|
|
60
|
-
buildRuleFunctionMessage(e, r,
|
|
61
|
-
const
|
|
62
|
-
if (typeof
|
|
63
|
-
const u = z(
|
|
64
|
-
if (!(u in
|
|
60
|
+
buildRuleFunctionMessage(e, r, i) {
|
|
61
|
+
const a = this.getMessage(e)(this.formattedName, r);
|
|
62
|
+
if (typeof a == "object") {
|
|
63
|
+
const u = z(i);
|
|
64
|
+
if (!(u in a))
|
|
65
65
|
throw new Error(`The message for the "${e}" rule of the "${u}" type is missing.`);
|
|
66
|
-
return $(
|
|
66
|
+
return $(a[u]);
|
|
67
67
|
}
|
|
68
|
-
return $(
|
|
68
|
+
return $(a);
|
|
69
69
|
}
|
|
70
70
|
pushRuleFunction(e, r) {
|
|
71
71
|
if (e in this.conditions && !this.conditions[e])
|
|
72
72
|
return this;
|
|
73
|
-
const
|
|
74
|
-
return this.ruleFunctions.push(
|
|
73
|
+
const i = this.buildRuleFunction(e, r);
|
|
74
|
+
return this.ruleFunctions.push(i), this;
|
|
75
75
|
}
|
|
76
76
|
getRuleFunctions() {
|
|
77
77
|
return this.ruleFunctions;
|
|
@@ -89,9 +89,9 @@ class x {
|
|
|
89
89
|
if (this.shouldSkip)
|
|
90
90
|
return !0;
|
|
91
91
|
for (const r of this.ruleFunctions) {
|
|
92
|
-
const
|
|
93
|
-
if (typeof
|
|
94
|
-
return
|
|
92
|
+
const i = r(e);
|
|
93
|
+
if (typeof i == "string")
|
|
94
|
+
return i;
|
|
95
95
|
}
|
|
96
96
|
return !0;
|
|
97
97
|
}
|
|
@@ -110,8 +110,8 @@ class x {
|
|
|
110
110
|
/**
|
|
111
111
|
* Passes if the field's value is a date that occurs after the specified date.
|
|
112
112
|
*/
|
|
113
|
-
after(e, r,
|
|
114
|
-
return this.apply(this.after.name, { date: e, format: r, displayFormat:
|
|
113
|
+
after(e, r, i, a = !0) {
|
|
114
|
+
return this.apply(this.after.name, { date: e, format: r, displayFormat: i, strict: a });
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Passes if the field's value contains only letters.
|
|
@@ -152,8 +152,8 @@ class x {
|
|
|
152
152
|
/**
|
|
153
153
|
* Passes if the field's value is a date that occurs before the specified date.
|
|
154
154
|
*/
|
|
155
|
-
before(e, r,
|
|
156
|
-
return this.apply(this.before.name, { date: e, format: r, displayFormat:
|
|
155
|
+
before(e, r, i, a = !0) {
|
|
156
|
+
return this.apply(this.before.name, { date: e, format: r, displayFormat: i, strict: a });
|
|
157
157
|
}
|
|
158
158
|
/**
|
|
159
159
|
* Passes if the field's value is between the specified minimum and maximum values.
|
|
@@ -174,7 +174,7 @@ class x {
|
|
|
174
174
|
return this.apply(this.boolean.name);
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
177
|
-
* Passes if the field's value contains all the specified values.
|
|
177
|
+
* Passes if the field's value contains all of the specified values.
|
|
178
178
|
*/
|
|
179
179
|
containsAll(e) {
|
|
180
180
|
return this.apply(this.containsAll.name, { values: e });
|
|
@@ -275,12 +275,6 @@ class x {
|
|
|
275
275
|
https() {
|
|
276
276
|
return this.apply(this.https.name);
|
|
277
277
|
}
|
|
278
|
-
/**
|
|
279
|
-
* Passes if the field's value is one of the specified values.
|
|
280
|
-
*/
|
|
281
|
-
in(e) {
|
|
282
|
-
return this.apply(this.in.name, { values: e });
|
|
283
|
-
}
|
|
284
278
|
/**
|
|
285
279
|
* Passes if the field's value is an integer.
|
|
286
280
|
*/
|
|
@@ -341,6 +335,18 @@ class x {
|
|
|
341
335
|
minLength(e) {
|
|
342
336
|
return this.apply(this.minLength.name, { length: e });
|
|
343
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Passes if the field's value does not contain all of the specified values together.
|
|
340
|
+
*/
|
|
341
|
+
notContainsAll(e) {
|
|
342
|
+
return this.apply(this.notContainsAll.name, { values: e });
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Passes if the field's value does not contain any of the specified values.
|
|
346
|
+
*/
|
|
347
|
+
notContainsAny(e) {
|
|
348
|
+
return this.apply(this.notContainsAny.name, { values: e });
|
|
349
|
+
}
|
|
344
350
|
/**
|
|
345
351
|
* Passes if the field's value is not equal to the specified value.
|
|
346
352
|
*/
|
|
@@ -350,8 +356,8 @@ class x {
|
|
|
350
356
|
/**
|
|
351
357
|
* Passes if the field's value is not one of the specified values.
|
|
352
358
|
*/
|
|
353
|
-
|
|
354
|
-
return this.apply(this.
|
|
359
|
+
notOneOf(e) {
|
|
360
|
+
return this.apply(this.notOneOf.name, { values: e });
|
|
355
361
|
}
|
|
356
362
|
/**
|
|
357
363
|
* Passes if the field's value is a number.
|
|
@@ -365,6 +371,12 @@ class x {
|
|
|
365
371
|
numeric() {
|
|
366
372
|
return this.apply(this.numeric.name);
|
|
367
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Passes if the field's value is one of the specified values.
|
|
376
|
+
*/
|
|
377
|
+
oneOf(e) {
|
|
378
|
+
return this.apply(this.oneOf.name, { values: e });
|
|
379
|
+
}
|
|
368
380
|
/**
|
|
369
381
|
* Passes if the field's value matches the specified regular expression.
|
|
370
382
|
*/
|
|
@@ -413,6 +425,18 @@ class x {
|
|
|
413
425
|
stringBetweenLength(e, r) {
|
|
414
426
|
return this.apply(this.stringBetweenLength.name, { min: e, max: r });
|
|
415
427
|
}
|
|
428
|
+
/**
|
|
429
|
+
* Passes if the field's value contains all of the specified text.
|
|
430
|
+
*/
|
|
431
|
+
stringContainsAll(e) {
|
|
432
|
+
return this.apply(this.stringContainsAll.name, { values: e });
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Passes if the field's value contains at least one of the specified text.
|
|
436
|
+
*/
|
|
437
|
+
stringContainsAny(e) {
|
|
438
|
+
return this.apply(this.stringContainsAny.name, { values: e });
|
|
439
|
+
}
|
|
416
440
|
/**
|
|
417
441
|
* Passes if the field's value matches the specified string length.
|
|
418
442
|
*/
|
|
@@ -431,6 +455,18 @@ class x {
|
|
|
431
455
|
stringMinLength(e) {
|
|
432
456
|
return this.apply(this.stringMinLength.name, { length: e });
|
|
433
457
|
}
|
|
458
|
+
/**
|
|
459
|
+
* Passes if the field's value does not contain all of the specified text together.
|
|
460
|
+
*/
|
|
461
|
+
stringNotContainsAll(e) {
|
|
462
|
+
return this.apply(this.stringNotContainsAll.name, { values: e });
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Passes if the field's value does not contain any of the specified text.
|
|
466
|
+
*/
|
|
467
|
+
stringNotContainsAny(e) {
|
|
468
|
+
return this.apply(this.stringNotContainsAny.name, { values: e });
|
|
469
|
+
}
|
|
434
470
|
/**
|
|
435
471
|
* Passes if the field's value contains only unique items, with optional ignored values.
|
|
436
472
|
*/
|
|
@@ -456,7 +492,7 @@ class x {
|
|
|
456
492
|
return typeof e == "object" ? (this.conditions = e, this) : (e || (this.shouldSkip = !0), this);
|
|
457
493
|
}
|
|
458
494
|
}
|
|
459
|
-
const
|
|
495
|
+
const _ = {
|
|
460
496
|
accepted: (t) => `The ${t} field must be accepted.`,
|
|
461
497
|
alpha: (t) => `The ${t} field must only contain letters.`,
|
|
462
498
|
alphaDash: (t) => `The ${t} field must only contain letters, numbers, dashes and underscores.`,
|
|
@@ -465,24 +501,24 @@ const v = {
|
|
|
465
501
|
array: (t) => `The ${t} field must be an array.`,
|
|
466
502
|
ascii: (t) => `The ${t} field must only contain ASCII characters and symbols.`,
|
|
467
503
|
between: (t, e) => {
|
|
468
|
-
const { min: r, max:
|
|
504
|
+
const { min: r, max: i } = e;
|
|
469
505
|
return {
|
|
470
|
-
number: `The ${t} field must be between ${n(r)} and ${n(
|
|
471
|
-
array: `The ${t} field must contain items where each item is between ${n(r)} and ${n(
|
|
506
|
+
number: `The ${t} field must be between ${n(r)} and ${n(i)}.`,
|
|
507
|
+
array: `The ${t} field must contain items where each item is between ${n(r)} and ${n(i)}.`
|
|
472
508
|
};
|
|
473
509
|
},
|
|
474
510
|
betweenLength: (t, e) => {
|
|
475
|
-
const { min: r, max:
|
|
476
|
-
return `The ${t} field must be between ${n(r)} and ${n(
|
|
511
|
+
const { min: r, max: i } = e;
|
|
512
|
+
return `The ${t} field must be between ${n(r)} and ${n(i)} items.`;
|
|
477
513
|
},
|
|
478
514
|
boolean: (t) => `The ${t} field must be a boolean value.`,
|
|
479
515
|
containsAll: (t, e) => {
|
|
480
516
|
const { values: r } = e;
|
|
481
|
-
return `The ${t} field must contain all of the following: ${r.join(", ")}.`;
|
|
517
|
+
return `The ${t} field must contain all of the following values: ${r.join(", ")}.`;
|
|
482
518
|
},
|
|
483
519
|
containsAny: (t, e) => {
|
|
484
520
|
const { values: r } = e;
|
|
485
|
-
return `The ${t} field must contain at least one of the following: ${r.join(", ")}.`;
|
|
521
|
+
return `The ${t} field must contain at least one of the following values: ${r.join(", ")}.`;
|
|
486
522
|
},
|
|
487
523
|
declined: (t) => `The ${t} field must be declined.`,
|
|
488
524
|
different: (t, e) => {
|
|
@@ -502,10 +538,10 @@ const v = {
|
|
|
502
538
|
},
|
|
503
539
|
file: (t) => `The ${t} field must be a file.`,
|
|
504
540
|
fileBetweenSize: (t, e) => {
|
|
505
|
-
const { min: r, max:
|
|
541
|
+
const { min: r, max: i } = e;
|
|
506
542
|
return {
|
|
507
|
-
file: `The ${t} field must be between ${n(r)} and ${n(
|
|
508
|
-
array: `The ${t} field must contain items where each item is between ${n(r)} and ${n(
|
|
543
|
+
file: `The ${t} field must be between ${n(r)} and ${n(i)} kilobytes.`,
|
|
544
|
+
array: `The ${t} field must contain items where each item is between ${n(r)} and ${n(i)} kilobytes.`
|
|
509
545
|
};
|
|
510
546
|
},
|
|
511
547
|
fileMaxSize: (t, e) => {
|
|
@@ -531,10 +567,6 @@ const v = {
|
|
|
531
567
|
},
|
|
532
568
|
http: (t) => `The ${t} field must start with either "http://" or "https://".`,
|
|
533
569
|
https: (t) => `The ${t} field must start with "http://".`,
|
|
534
|
-
in: (t, e) => {
|
|
535
|
-
const { values: r } = e;
|
|
536
|
-
return `The ${t} field must be one of the following: ${r.join(", ")}.`;
|
|
537
|
-
},
|
|
538
570
|
integer: (t) => `The ${t} field must be an integer.`,
|
|
539
571
|
json: (t) => `The ${t} field must be a valid JSON string.`,
|
|
540
572
|
length: (t, e) => {
|
|
@@ -564,16 +596,28 @@ const v = {
|
|
|
564
596
|
const { length: r } = e;
|
|
565
597
|
return `The ${t} field must be at least ${n(r)} items.`;
|
|
566
598
|
},
|
|
599
|
+
notContainsAll: (t, e) => {
|
|
600
|
+
const { values: r } = e;
|
|
601
|
+
return `The ${t} field must not contain all of the following values together: ${r.join(", ")}.`;
|
|
602
|
+
},
|
|
603
|
+
notContainsAny: (t, e) => {
|
|
604
|
+
const { values: r } = e;
|
|
605
|
+
return `The ${t} field must not contain any of the following values: ${r.join(", ")}.`;
|
|
606
|
+
},
|
|
567
607
|
notEquals: (t, e) => {
|
|
568
608
|
const { value: r } = e;
|
|
569
609
|
return `The ${t} field must not be equal to ${r}.`;
|
|
570
610
|
},
|
|
571
|
-
|
|
611
|
+
notOneOf: (t, e) => {
|
|
572
612
|
const { values: r } = e;
|
|
573
|
-
return `The ${t} field must not be one of the following: ${r.join(", ")}.`;
|
|
613
|
+
return `The ${t} field must not be one of the following values: ${r.join(", ")}.`;
|
|
574
614
|
},
|
|
575
615
|
number: (t) => `The ${t} field must be a number.`,
|
|
576
616
|
numeric: (t) => `The ${t} field must be a number.`,
|
|
617
|
+
oneOf: (t, e) => {
|
|
618
|
+
const { values: r } = e;
|
|
619
|
+
return `The ${t} field must be one of the following values: ${r.join(", ")}.`;
|
|
620
|
+
},
|
|
577
621
|
regex: (t) => `The ${t} field must match the required format.`,
|
|
578
622
|
required: (t) => `The ${t} field is required.`,
|
|
579
623
|
same: (t, e) => {
|
|
@@ -593,12 +637,20 @@ const v = {
|
|
|
593
637
|
},
|
|
594
638
|
string: (t) => `The ${t} field must be a string.`,
|
|
595
639
|
stringBetweenLength: (t, e) => {
|
|
596
|
-
const { min: r, max:
|
|
640
|
+
const { min: r, max: i } = e;
|
|
597
641
|
return {
|
|
598
|
-
string: `The ${t} field must be between ${n(r)} and ${n(
|
|
599
|
-
array: `The ${t} field must contain items where each item is between ${n(r)} and ${n(
|
|
642
|
+
string: `The ${t} field must be between ${n(r)} and ${n(i)} characters.`,
|
|
643
|
+
array: `The ${t} field must contain items where each item is between ${n(r)} and ${n(i)} characters.`
|
|
600
644
|
};
|
|
601
645
|
},
|
|
646
|
+
stringContainsAll: (t, e) => {
|
|
647
|
+
const { values: r } = e;
|
|
648
|
+
return `The ${t} field must contain all of the following text: ${r.join(", ")}.`;
|
|
649
|
+
},
|
|
650
|
+
stringContainsAny: (t, e) => {
|
|
651
|
+
const { values: r } = e;
|
|
652
|
+
return `The ${t} field must contain at least one of the following text: ${r.join(", ")}.`;
|
|
653
|
+
},
|
|
602
654
|
stringLength: (t, e) => {
|
|
603
655
|
const { length: r } = e;
|
|
604
656
|
return {
|
|
@@ -620,6 +672,14 @@ const v = {
|
|
|
620
672
|
array: `The ${t} field must contain items where each item is at least ${n(r)} characters.`
|
|
621
673
|
};
|
|
622
674
|
},
|
|
675
|
+
stringNotContainsAll: (t, e) => {
|
|
676
|
+
const { values: r } = e;
|
|
677
|
+
return `The ${t} field must not contain all of the following text together: ${r.join(", ")}.`;
|
|
678
|
+
},
|
|
679
|
+
stringNotContainsAny: (t, e) => {
|
|
680
|
+
const { values: r } = e;
|
|
681
|
+
return `The ${t} field must not contain any of the following text: ${r.join(", ")}.`;
|
|
682
|
+
},
|
|
623
683
|
unique: (t) => `The ${t} field has already been taken.`,
|
|
624
684
|
uppercase: (t) => `The ${t} field must be uppercase.`,
|
|
625
685
|
url: (t) => `The ${t} field must be a valid URL.`
|
|
@@ -632,15 +692,15 @@ const v = {
|
|
|
632
692
|
array: () => "此欄位必須是一個陣列",
|
|
633
693
|
ascii: () => "此欄位只能包含ASCII字元和符號",
|
|
634
694
|
between: (t, e) => {
|
|
635
|
-
const { min: r, max:
|
|
695
|
+
const { min: r, max: i } = e;
|
|
636
696
|
return {
|
|
637
|
-
number: `此欄位必須介於${n(r)}到${n(
|
|
638
|
-
array: `此欄位中的每個項目都必須介於${n(r)}到${n(
|
|
697
|
+
number: `此欄位必須介於${n(r)}到${n(i)}`,
|
|
698
|
+
array: `此欄位中的每個項目都必須介於${n(r)}到${n(i)}`
|
|
639
699
|
};
|
|
640
700
|
},
|
|
641
701
|
betweenLength: (t, e) => {
|
|
642
|
-
const { min: r, max:
|
|
643
|
-
return `此欄位必須介於${n(r)}到${n(
|
|
702
|
+
const { min: r, max: i } = e;
|
|
703
|
+
return `此欄位必須介於${n(r)}到${n(i)}個項目之間`;
|
|
644
704
|
},
|
|
645
705
|
boolean: () => "此欄位必須是一個布林值",
|
|
646
706
|
containsAll: (t, e) => {
|
|
@@ -669,10 +729,10 @@ const v = {
|
|
|
669
729
|
},
|
|
670
730
|
file: () => "此欄位必須是檔案",
|
|
671
731
|
fileBetweenSize: (t, e) => {
|
|
672
|
-
const { min: r, max:
|
|
732
|
+
const { min: r, max: i } = e;
|
|
673
733
|
return {
|
|
674
|
-
file: `此欄位必須介於${n(r)}到${n(
|
|
675
|
-
array: `此欄位中的每個項目都必須介於${n(r)}到${n(
|
|
734
|
+
file: `此欄位必須介於${n(r)}到${n(i)} KB之間`,
|
|
735
|
+
array: `此欄位中的每個項目都必須介於${n(r)}到${n(i)} KB之間`
|
|
676
736
|
};
|
|
677
737
|
},
|
|
678
738
|
fileMaxSize: (t, e) => {
|
|
@@ -698,10 +758,6 @@ const v = {
|
|
|
698
758
|
},
|
|
699
759
|
http: () => "此欄位必須以 http:// 或 https:// 開頭",
|
|
700
760
|
https: () => "此欄位必須以 https:// 開頭",
|
|
701
|
-
in: (t, e) => {
|
|
702
|
-
const { values: r } = e;
|
|
703
|
-
return `此欄位必須是以下之一:${r.join(", ")}`;
|
|
704
|
-
},
|
|
705
761
|
integer: () => "此欄位必須是整數",
|
|
706
762
|
json: () => "此欄位必須是有效的 JSON 字串",
|
|
707
763
|
length: (t, e) => {
|
|
@@ -716,6 +772,10 @@ const v = {
|
|
|
716
772
|
array: `此欄位中的每個項目都不能大於${n(r)}`
|
|
717
773
|
};
|
|
718
774
|
},
|
|
775
|
+
maxLength: (t, e) => {
|
|
776
|
+
const { length: r } = e;
|
|
777
|
+
return `此欄位不能大於${n(r)}個項目`;
|
|
778
|
+
},
|
|
719
779
|
min: (t, e) => {
|
|
720
780
|
const { min: r } = e;
|
|
721
781
|
return {
|
|
@@ -723,16 +783,32 @@ const v = {
|
|
|
723
783
|
array: `此欄位中的每個項目都不能小於${n(r)}`
|
|
724
784
|
};
|
|
725
785
|
},
|
|
786
|
+
minLength: (t, e) => {
|
|
787
|
+
const { length: r } = e;
|
|
788
|
+
return `此欄位不能小於${n(r)}個項目`;
|
|
789
|
+
},
|
|
790
|
+
notContainsAll: (t, e) => {
|
|
791
|
+
const { values: r } = e;
|
|
792
|
+
return `此欄位不能同時包含以下所有值:${r.join(", ")}`;
|
|
793
|
+
},
|
|
794
|
+
notContainsAny: (t, e) => {
|
|
795
|
+
const { values: r } = e;
|
|
796
|
+
return `此欄位不能包含以下任何值:${r.join(", ")}`;
|
|
797
|
+
},
|
|
726
798
|
notEquals: (t, e) => {
|
|
727
799
|
const { value: r } = e;
|
|
728
800
|
return `此欄位不能是${r}`;
|
|
729
801
|
},
|
|
730
|
-
|
|
802
|
+
notOneOf: (t, e) => {
|
|
731
803
|
const { values: r } = e;
|
|
732
|
-
return
|
|
804
|
+
return `此欄位不能是以下任何值:${r.join(", ")}`;
|
|
733
805
|
},
|
|
734
806
|
number: () => "此欄位必須是數字",
|
|
735
807
|
numeric: () => "此欄位必須是數字",
|
|
808
|
+
oneOf: (t, e) => {
|
|
809
|
+
const { values: r } = e;
|
|
810
|
+
return `此欄位必須是以下任何值:${r.join(", ")}`;
|
|
811
|
+
},
|
|
736
812
|
regex: () => "此欄位必須符合所需的格式",
|
|
737
813
|
required: () => "此欄位為必填",
|
|
738
814
|
same: (t, e) => {
|
|
@@ -752,12 +828,20 @@ const v = {
|
|
|
752
828
|
},
|
|
753
829
|
string: () => "此欄位必須是字串",
|
|
754
830
|
stringBetweenLength: (t, e) => {
|
|
755
|
-
const { min: r, max:
|
|
831
|
+
const { min: r, max: i } = e;
|
|
756
832
|
return {
|
|
757
|
-
string: `此欄位必須介於${n(r)}到${n(
|
|
758
|
-
array: `此欄位中的每個項目都必須介於${n(r)}到${n(
|
|
833
|
+
string: `此欄位必須介於${n(r)}到${n(i)}個字元之間`,
|
|
834
|
+
array: `此欄位中的每個項目都必須介於${n(r)}到${n(i)}個字元之間`
|
|
759
835
|
};
|
|
760
836
|
},
|
|
837
|
+
stringContainsAll: (t, e) => {
|
|
838
|
+
const { values: r } = e;
|
|
839
|
+
return `此欄位必須包含以下所有文字:${r.join(", ")}`;
|
|
840
|
+
},
|
|
841
|
+
stringContainsAny: (t, e) => {
|
|
842
|
+
const { values: r } = e;
|
|
843
|
+
return `此欄位必須包含以下其中一個文字:${r.join(", ")}`;
|
|
844
|
+
},
|
|
761
845
|
stringLength: (t, e) => {
|
|
762
846
|
const { length: r } = e;
|
|
763
847
|
return {
|
|
@@ -779,49 +863,57 @@ const v = {
|
|
|
779
863
|
array: `此欄位中的每個項目都不能小於${n(r)}個字元`
|
|
780
864
|
};
|
|
781
865
|
},
|
|
866
|
+
stringNotContainsAll: (t, e) => {
|
|
867
|
+
const { values: r } = e;
|
|
868
|
+
return `此欄位不能同時包含以下所有文字:${r.join(", ")}`;
|
|
869
|
+
},
|
|
870
|
+
stringNotContainsAny: (t, e) => {
|
|
871
|
+
const { values: r } = e;
|
|
872
|
+
return `此欄位不能包含以下任何文字:${r.join(", ")}`;
|
|
873
|
+
},
|
|
782
874
|
unique: () => "此欄位已經存在",
|
|
783
875
|
uppercase: () => "此欄位必須是大寫",
|
|
784
876
|
url: () => "此欄位必須是有效的網址"
|
|
785
|
-
},
|
|
786
|
-
en:
|
|
877
|
+
}, j = {
|
|
878
|
+
en: _,
|
|
787
879
|
"zh-TW": q
|
|
788
|
-
},
|
|
789
|
-
if (
|
|
880
|
+
}, M = () => (t) => s(t) ? !1 : ["y", "yes", "on", "1", "true"].includes(String(t).toLowerCase()), F = () => (t) => s(t) ? !1 : /^[a-zA-Z]+$/.test(String(t)), k = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9-_]+$/.test(String(t)), O = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9-_.]+$/.test(String(t)), B = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9]+$/.test(String(t)), D = () => (t) => Array.isArray(t), E = () => (t) => s(t) ? !1 : /^[\x20-\x7E]+$/.test(String(t)), h = ({ max: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e <= t : Array.isArray(e) ? e.every((r) => h({ max: t })(r)) : !1, c = ({ min: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e >= t : Array.isArray(e) ? e.every((r) => c({ min: t })(r)) : !1, N = ({ min: t, max: e }) => (r) => s(r) ? !1 : c({ min: t })(r) && h({ max: e })(r), A = ({ 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, W = ({ min: t, max: e }) => (r) => s(r) ? !1 : w({ length: t })(r) && A({ length: e })(r), Z = () => (t) => s(t) ? !1 : typeof t == "boolean", p = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? t.every((r) => e.includes(r)) : !1, b = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? t.some((r) => e.includes(r)) : !1, K = () => (t) => s(t) ? !1 : ["n", "no", "off", "0", "false"].includes(String(t).toLowerCase()), I = ({ value: t }) => (e) => s(e) ? !1 : e !== t, J = () => (t) => s(t) ? !1 : Array.isArray(t) ? new Set(t).size === t.length : !0, P = () => (t) => s(t) ? !1 : /^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)), U = () => (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).endsWith(t), G = ({ value: t }) => (e) => e === t, H = () => (t) => t instanceof File, 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, 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, Q = ({ min: t, max: e }) => (r) => s(r) ? !1 : m({ size: t })(r) && f({ size: e })(r), T = ({ size: t }) => (e) => {
|
|
881
|
+
if (s(e))
|
|
790
882
|
return !1;
|
|
791
883
|
if (e instanceof File) {
|
|
792
|
-
const r = t * 1024,
|
|
793
|
-
return e.size >= r && e.size <
|
|
884
|
+
const r = t * 1024, i = (t + 1) * 1024;
|
|
885
|
+
return e.size >= r && e.size < i;
|
|
794
886
|
}
|
|
795
|
-
return Array.isArray(e) ? e.every((r) =>
|
|
796
|
-
},
|
|
797
|
-
if (
|
|
887
|
+
return Array.isArray(e) ? e.every((r) => T({ size: t })(r)) : !1;
|
|
888
|
+
}, o = ({ value: t }) => (e) => s(e) ? !1 : String(e).startsWith(t), X = () => (t) => s(t) ? !1 : o({ value: "http://" })(t) || o({ value: "https://" })(t), Y = () => (t) => s(t) ? !1 : o({ value: "https://" })(t), g = () => (t) => s(t) ? !1 : typeof t == "number", ee = () => (t) => s(t) ? !1 : g()(t) && Number.isInteger(t), te = () => (t) => {
|
|
889
|
+
if (s(t))
|
|
798
890
|
return !1;
|
|
799
891
|
try {
|
|
800
892
|
return JSON.parse(String(t)), !0;
|
|
801
893
|
} catch {
|
|
802
894
|
return !1;
|
|
803
895
|
}
|
|
804
|
-
},
|
|
805
|
-
if (
|
|
896
|
+
}, re = ({ length: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.length === t : !1, ne = () => (t) => s(t) ? !1 : String(t) === String(t).toLowerCase(), se = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? !t.every((r) => e.includes(r)) : !1, ie = ({ values: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? !t.some((r) => e.includes(r)) : !1, ae = ({ value: t }) => (e) => e !== t, le = ({ values: t }) => (e) => s(e) ? !1 : !t.includes(e), R = () => (t) => typeof t == "string", ue = () => (t) => s(t) ? !1 : R()(t) ? /^-?\d+(\.\d+)?$/.test(String(t)) : g()(t), oe = ({ values: t }) => (e) => s(e) ? !1 : t.includes(e), he = ({ expression: t }) => (e) => {
|
|
897
|
+
if (s(e))
|
|
806
898
|
return !1;
|
|
807
899
|
if (!(t instanceof RegExp))
|
|
808
900
|
throw new TypeError("The expression provided is not a valid RegExp.");
|
|
809
901
|
return t.test(String(e));
|
|
810
|
-
},
|
|
811
|
-
accepted:
|
|
812
|
-
alpha:
|
|
902
|
+
}, ce = () => (t) => !s(t), fe = ({ value: t }) => (e) => s(e) ? !1 : Array.isArray(e) ? e.every((r) => r === t) : e === t, L = ({ size: t }) => (e) => s(e) ? !1 : typeof e == "number" ? e === t : Array.isArray(e) ? e.every((r) => L({ size: t })(r)) : !1, y = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length <= t : Array.isArray(e) ? e.every((r) => y({ 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, me = ({ min: t, max: e }) => (r) => s(r) ? !1 : d({ length: t })(r) && y({ length: e })(r), v = ({ length: t }) => (e) => s(e) ? !1 : typeof e == "string" ? e.length === t : Array.isArray(e) ? e.every((r) => v({ length: t })(r)) : !1, ge = ({ values: t }) => (e) => s(e) ? !1 : typeof e == "string" ? !t.every((r) => e.includes(r)) : !1, ye = ({ values: t }) => (e) => s(e) ? !1 : typeof e == "string" ? !t.some((r) => e.includes(r)) : !1, de = ({ values: t, ignored: e = [] }) => (r) => s(r) ? !1 : (Array.isArray(e) ? e : [e]).some((i) => i === r) ? !0 : !t.some((i) => i === r), $e = () => (t) => s(t) ? !1 : String(t) === String(t).toUpperCase(), pe = () => (t) => s(t) ? !1 : /^(https?):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}.*$/.test(String(t)), be = {
|
|
903
|
+
accepted: M,
|
|
904
|
+
alpha: F,
|
|
813
905
|
alphaDash: k,
|
|
814
|
-
alphaDashDot:
|
|
906
|
+
alphaDashDot: O,
|
|
815
907
|
alphaNum: B,
|
|
816
908
|
array: D,
|
|
817
909
|
ascii: E,
|
|
818
|
-
between:
|
|
819
|
-
betweenLength:
|
|
910
|
+
between: N,
|
|
911
|
+
betweenLength: W,
|
|
820
912
|
boolean: Z,
|
|
821
|
-
containsAll:
|
|
822
|
-
containsAny:
|
|
823
|
-
declined:
|
|
824
|
-
different:
|
|
913
|
+
containsAll: p,
|
|
914
|
+
containsAny: b,
|
|
915
|
+
declined: K,
|
|
916
|
+
different: I,
|
|
825
917
|
distinct: J,
|
|
826
918
|
domain: P,
|
|
827
919
|
email: U,
|
|
@@ -831,47 +923,53 @@ const v = {
|
|
|
831
923
|
fileBetweenSize: Q,
|
|
832
924
|
fileMaxSize: f,
|
|
833
925
|
fileMinSize: m,
|
|
834
|
-
fileSize:
|
|
926
|
+
fileSize: T,
|
|
835
927
|
http: X,
|
|
836
928
|
https: Y,
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
maxLength: b,
|
|
929
|
+
integer: ee,
|
|
930
|
+
json: te,
|
|
931
|
+
length: re,
|
|
932
|
+
lowercase: ne,
|
|
933
|
+
max: h,
|
|
934
|
+
maxLength: A,
|
|
844
935
|
min: c,
|
|
845
|
-
minLength:
|
|
936
|
+
minLength: w,
|
|
937
|
+
notContainsAll: se,
|
|
938
|
+
notContainsAny: ie,
|
|
846
939
|
notEquals: ae,
|
|
847
|
-
|
|
940
|
+
notOneOf: le,
|
|
848
941
|
number: g,
|
|
849
|
-
numeric:
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
942
|
+
numeric: ue,
|
|
943
|
+
oneOf: oe,
|
|
944
|
+
regex: he,
|
|
945
|
+
required: ce,
|
|
946
|
+
same: fe,
|
|
947
|
+
size: L,
|
|
948
|
+
startsWith: o,
|
|
949
|
+
string: R,
|
|
950
|
+
stringBetweenLength: me,
|
|
951
|
+
stringContainsAll: p,
|
|
952
|
+
stringContainsAny: b,
|
|
953
|
+
stringLength: v,
|
|
858
954
|
stringMaxLength: y,
|
|
859
955
|
stringMinLength: d,
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
956
|
+
stringNotContainsAll: ge,
|
|
957
|
+
stringNotContainsAny: ye,
|
|
958
|
+
unique: de,
|
|
959
|
+
uppercase: $e,
|
|
960
|
+
url: pe
|
|
863
961
|
};
|
|
864
|
-
class
|
|
962
|
+
class we {
|
|
865
963
|
constructor({
|
|
866
964
|
fallbackLocale: e,
|
|
867
965
|
locale: r,
|
|
868
|
-
plugins:
|
|
966
|
+
plugins: i
|
|
869
967
|
} = {}) {
|
|
870
968
|
l(this, "locale", "en");
|
|
871
969
|
l(this, "fallbackLocale", "en");
|
|
872
970
|
l(this, "locales", {});
|
|
873
971
|
l(this, "rules", {});
|
|
874
|
-
this.registerLocales(
|
|
972
|
+
this.registerLocales(j), this.registerRules(be), e && this.setFallbackLocale(e), r && this.setLocale(r), i && i.forEach((a) => this.registerPlugin(a));
|
|
875
973
|
}
|
|
876
974
|
getLocale() {
|
|
877
975
|
return this.locale;
|
|
@@ -890,7 +988,7 @@ class $e {
|
|
|
890
988
|
return this.fallbackLocale = e, this;
|
|
891
989
|
}
|
|
892
990
|
defineField(e) {
|
|
893
|
-
return new
|
|
991
|
+
return new C({
|
|
894
992
|
name: e,
|
|
895
993
|
locale: this.locale,
|
|
896
994
|
fallbackLocale: this.fallbackLocale,
|
|
@@ -900,7 +998,7 @@ class $e {
|
|
|
900
998
|
}
|
|
901
999
|
registerLocales(e) {
|
|
902
1000
|
return this.locales = Object.keys(e).reduce(
|
|
903
|
-
(r,
|
|
1001
|
+
(r, i) => (r[i] = { ...this.locales[i], ...e[i] }, r),
|
|
904
1002
|
{ ...this.locales }
|
|
905
1003
|
), this;
|
|
906
1004
|
}
|
|
@@ -914,6 +1012,6 @@ class $e {
|
|
|
914
1012
|
}
|
|
915
1013
|
}
|
|
916
1014
|
export {
|
|
917
|
-
|
|
918
|
-
|
|
1015
|
+
C as FieldValidator,
|
|
1016
|
+
we as FormValidator
|
|
919
1017
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(u=typeof globalThis<"u"?globalThis:u||self,l(u.Fortress={}))})(this,function(u){"use strict";var ce=Object.defineProperty;var fe=(u,l,n)=>l in u?ce(u,l,{enumerable:!0,configurable:!0,writable:!0,value:n}):u[l]=n;var h=(u,l,n)=>(fe(u,typeof l!="symbol"?l+"":l,n),n);const l=t=>t.replace(/([^\x20-\x7E])([\x20-\x7E])/gu,"$1 $2").replace(/([\x20-\x7E])([^\x20-\x7E])/gu,"$1 $2").replace(/ +/g," "),n=(t,e=0)=>new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e}).format(t),z=t=>Object.prototype.toString.call(t).toLowerCase().slice(8,-1),i=t=>t==null||t===""||Array.isArray(t)&&t.length<1;class b{constructor({name:e,locale:r,fallbackLocale:s,locales:a,rules:o}){h(this,"name");h(this,"locale");h(this,"fallbackLocale");h(this,"locales");h(this,"rules");h(this,"ruleFunctions",[]);h(this,"conditions",{});h(this,"shouldSkip",!1);this.name=e,this.locale=r,this.fallbackLocale=s,this.locales=a,this.rules=o}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 s=>{if(i(s)&&!this.mandatoryRules.includes(e))return!0;const a=this.getRule(e)(r)(s);return typeof a=="string"?a:a===!0?!0:this.buildRuleFunctionMessage(e,r,s)}}buildRuleFunctionMessage(e,r,s){const a=this.getMessage(e)(this.formattedName,r);if(typeof a=="object"){const o=z(s);if(!(o in a))throw new Error(`The message for the "${e}" rule of the "${o}" type is missing.`);return l(a[o])}return l(a)}pushRuleFunction(e,r){if(e in this.conditions&&!this.conditions[e])return this;const s=this.buildRuleFunction(e,r);return this.ruleFunctions.push(s),this}getRuleFunctions(){return this.ruleFunctions}collect(){return this.shouldSkip?[]:this.getRuleFunctions()}validate(e){if(this.shouldSkip)return!0;for(const r of this.ruleFunctions){const s=r(e);if(typeof s=="string")return s}return!0}apply(e,r={}){return this.pushRuleFunction(e,r)}accepted(){return this.apply(this.accepted.name)}after(e,r,s,a=!0){return this.apply(this.after.name,{date:e,format:r,displayFormat:s,strict:a})}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)}ascii(){return this.apply(this.ascii.name)}before(e,r,s,a=!0){return this.apply(this.before.name,{date:e,format:r,displayFormat:s,strict:a})}between(e,r){return this.apply(this.between.name,{min:e,max:r})}betweenLength(e,r){return this.apply(this.betweenLength.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)}fileBetweenSize(e,r){return this.apply(this.fileBetweenSize.name,{min:e,max:r})}fileMaxSize(e){return this.apply(this.fileMaxSize.name,{size:e})}fileMinSize(e){return this.apply(this.fileMinSize.name,{size:e})}fileSize(e){return this.apply(this.fileSize.name,{size:e})}http(){return this.apply(this.http.name)}https(){return this.apply(this.https.name)}in(e){return this.apply(this.in.name,{values:e})}integer(){return this.apply(this.integer.name)}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})}length(e){return this.apply(this.length.name,{length:e})}lowercase(){return this.apply(this.lowercase.name)}max(e){return this.apply(this.max.name,{max:e})}maxLength(e){return this.apply(this.maxLength.name,{length:e})}min(e){return this.apply(this.min.name,{min:e})}minLength(e){return this.apply(this.minLength.name,{length:e})}notEquals(e){return this.apply(this.notEquals.name,{value:e})}notIn(e){return this.apply(this.notIn.name,{values:e})}number(){return this.apply(this.number.name)}numeric(){return this.apply(this.numeric.name)}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)}stringBetweenLength(e,r){return this.apply(this.stringBetweenLength.name,{min:e,max:r})}stringLength(e){return this.apply(this.stringLength.name,{length:e})}stringMaxLength(e){return this.apply(this.stringMaxLength.name,{length:e})}stringMinLength(e){return this.apply(this.stringMinLength.name,{length: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 x={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.`,ascii:t=>`The ${t} field must only contain ASCII characters and symbols.`,between:(t,e)=>{const{min:r,max:s}=e;return{number:`The ${t} field must be between ${n(r)} and ${n(s)}.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(s)}.`}},betweenLength:(t,e)=>{const{min:r,max:s}=e;return`The ${t} field must be between ${n(r)} and ${n(s)} items.`},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: ${r.join(", ")}.`},containsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following: ${r.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.`,fileBetweenSize:(t,e)=>{const{min:r,max:s}=e;return{file:`The ${t} field must be between ${n(r)} and ${n(s)} kilobytes.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(s)} kilobytes.`}},fileMaxSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must not be greater than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)} kilobytes.`}},fileMinSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be at least ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is at least ${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 either "http://" or "https://".`,https:t=>`The ${t} field must start with "http://".`,in:(t,e)=>{const{values:r}=e;return`The ${t} field must be one of the following: ${r.join(", ")}.`},integer:t=>`The ${t} field must be an integer.`,json:t=>`The ${t} field must be a valid JSON string.`,length:(t,e)=>{const{length:r}=e;return`The ${t} field must be ${n(r)} items.`},lowercase:t=>`The ${t} field must be lowercase.`,max:(t,e)=>{const{max:r}=e;return{number:`The ${t} field must not be greater than ${n(r)}.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)}.`}},maxLength:(t,e)=>{const{length:r}=e;return`The ${t} field must not be greater than ${n(r)} items.`},min:(t,e)=>{const{min:r}=e;return{number:`The ${t} field must be at least ${n(r)}.`,array:`The ${t} field must contain items where each item is at least ${n(r)}.`}},minLength:(t,e)=>{const{length:r}=e;return`The ${t} field must be at least ${n(r)} items.`},notEquals:(t,e)=>{const{value:r}=e;return`The ${t} field must not be equal to ${r}.`},notIn:(t,e)=>{const{values:r}=e;return`The ${t} field must not be one of the following: ${r.join(", ")}.`},number:t=>`The ${t} field must be a number.`,numeric:t=>`The ${t} field must be a number.`,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.`,stringBetweenLength:(t,e)=>{const{min:r,max:s}=e;return{string:`The ${t} field must be between ${n(r)} and ${n(s)} characters.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(s)} characters.`}},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.`}},stringMaxLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must not be greater than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)} characters.`}},stringMinLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be at least ${n(r)} characters.`,array:`The ${t} field must contain items where each item is at least ${n(r)} characters.`}},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:()=>"此欄位必須是一個陣列",ascii:()=>"此欄位只能包含ASCII字元和符號",between:(t,e)=>{const{min:r,max:s}=e;return{number:`此欄位必須介於${n(r)}到${n(s)}`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(s)}`}},betweenLength:(t,e)=>{const{min:r,max:s}=e;return`此欄位必須介於${n(r)}到${n(s)}個項目之間`},boolean:()=>"此欄位必須是一個布林值",containsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有項目:${r.join(", ")}`},containsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個項目:${r.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:()=>"此欄位必須是檔案",fileBetweenSize:(t,e)=>{const{min:r,max:s}=e;return{file:`此欄位必須介於${n(r)}到${n(s)} KB之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(s)} KB之間`}},fileMaxSize:(t,e)=>{const{size:r}=e;return{file:`此欄位不能大於${n(r)} KB`,array:`此欄位中的每個項目都不能大於${n(r)} KB`}},fileMinSize:(t,e)=>{const{size:r}=e;return{file:`此欄位不能小於${n(r)} KB`,array:`此欄位中的每個項目都不能小於${n(r)} KB`}},fileSize:(t,e)=>{const{size:r}=e;return{file:`此欄位必須是${n(r)} KB`,array:`此欄位中的每個項目都必須是${n(r)} KB`}},http:()=>"此欄位必須以 http:// 或 https:// 開頭",https:()=>"此欄位必須以 https:// 開頭",in:(t,e)=>{const{values:r}=e;return`此欄位必須是以下之一:${r.join(", ")}`},integer:()=>"此欄位必須是整數",json:()=>"此欄位必須是有效的 JSON 字串",length:(t,e)=>{const{length:r}=e;return`此欄位必須包含${n(r)}個項目`},lowercase:()=>"此欄位必須是小寫",max:(t,e)=>{const{max:r}=e;return{number:`此欄位不能大於${n(r)}`,array:`此欄位中的每個項目都不能大於${n(r)}`}},min:(t,e)=>{const{min:r}=e;return{number:`此欄位不能小於${n(r)}`,array:`此欄位中的每個項目都不能小於${n(r)}`}},notEquals:(t,e)=>{const{value:r}=e;return`此欄位不能是${r}`},notIn:(t,e)=>{const{values:r}=e;return`此欄位不能是以下之一:${r.join(", ")}`},number:()=>"此欄位必須是數字",numeric:()=>"此欄位必須是數字",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:()=>"此欄位必須是字串",stringBetweenLength:(t,e)=>{const{min:r,max:s}=e;return{string:`此欄位必須介於${n(r)}到${n(s)}個字元之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(s)}個字元之間`}},stringLength:(t,e)=>{const{length:r}=e;return{string:`此欄位必須是${n(r)}個字元`,array:`此欄位中的每個項目都必須是${n(r)}個字元`}},stringMaxLength:(t,e)=>{const{length:r}=e;return{string:`此欄位不能大於${n(r)}個字元`,array:`此欄位中的每個項目都不能大於${n(r)}個字元`}},stringMinLength:(t,e)=>{const{length:r}=e;return{string:`此欄位不能小於${n(r)}個字元`,array:`此欄位中的每個項目都不能小於${n(r)}個字元`}},unique:()=>"此欄位已經存在",uppercase:()=>"此欄位必須是大寫",url:()=>"此欄位必須是有效的網址"}},v=()=>t=>i(t)?!1:["y","yes","on","1","true"].includes(String(t).toLowerCase()),q=()=>t=>i(t)?!1:/^[a-zA-Z]+$/.test(String(t)),M=()=>t=>i(t)?!1:/^[a-zA-Z0-9-_]+$/.test(String(t)),F=()=>t=>i(t)?!1:/^[a-zA-Z0-9-_.]+$/.test(String(t)),_=()=>t=>i(t)?!1:/^[a-zA-Z0-9]+$/.test(String(t)),k=()=>t=>Array.isArray(t),j=()=>t=>i(t)?!1:/^[\x20-\x7E]+$/.test(String(t)),f=({max:t})=>e=>i(e)?!1:typeof e=="number"?e<=t:Array.isArray(e)?e.every(r=>f({max:t})(r)):!1,m=({min:t})=>e=>i(e)?!1:typeof e=="number"?e>=t:Array.isArray(e)?e.every(r=>m({min:t})(r)):!1,B=({min:t,max:e})=>r=>i(r)?!1:m({min:t})(r)&&f({max:e})(r),w=({length:t})=>e=>i(e)?!1:Array.isArray(e)?e.length<=t:!1,T=({length:t})=>e=>i(e)?!1:Array.isArray(e)?e.length>=t:!1,D=({min:t,max:e})=>r=>i(r)?!1:T({length:t})(r)&&w({length:e})(r),E=()=>t=>i(t)?!1:typeof t=="boolean",W=({values:t})=>e=>i(e)||!Array.isArray(e)?!1:t.every(r=>e.includes(r)),I=({values:t})=>e=>i(e)||!Array.isArray(e)?!1:t.some(r=>e.includes(r)),Z=()=>t=>i(t)?!1:["n","no","off","0","false"].includes(String(t).toLowerCase()),C=({value:t})=>e=>i(e)?!1:e!==t,K=()=>t=>i(t)?!1:Array.isArray(t)?new Set(t).size===t.length:!0,N=()=>t=>i(t)?!1:/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),O=()=>t=>i(t)?!1:/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),V=({value:t})=>e=>i(e)?!1:String(e).endsWith(t),J=({value:t})=>e=>e===t,P=()=>t=>t instanceof File,d=({size:t})=>e=>i(e)?!1:e instanceof File?e.size<=t*1024:Array.isArray(e)?e.every(r=>d({size:t})(r)):!1,g=({size:t})=>e=>i(e)?!1:e instanceof File?e.size>=t*1024:Array.isArray(e)?e.every(r=>g({size:t})(r)):!1,U=({min:t,max:e})=>r=>i(r)?!1:g({size:t})(r)&&d({size:e})(r),R=({size:t})=>e=>{if(i(e))return!1;if(e instanceof File){const r=t*1024,s=(t+1)*1024;return e.size>=r&&e.size<s}return Array.isArray(e)?e.every(r=>R({size:t})(r)):!1},c=({value:t})=>e=>i(e)?!1:String(e).startsWith(t),G=()=>t=>i(t)?!1:c({value:"http://"})(t)||c({value:"https://"})(t),H=()=>t=>i(t)?!1:c({value:"https://"})(t),Q=({values:t})=>e=>i(e)?!1:Array.isArray(e)?e.every(r=>t.includes(r)):t.includes(e),y=()=>t=>i(t)?!1:typeof t=="number",X=()=>t=>i(t)?!1:y()(t)&&Number.isInteger(t),Y=()=>t=>{if(i(t))return!1;try{return JSON.parse(String(t)),!0}catch{return!1}},ee=({length:t})=>e=>i(e)?!1:Array.isArray(e)?e.length===t:!1,te=()=>t=>i(t)?!1:String(t)===String(t).toLowerCase(),re=({value:t})=>e=>e!==t,ne=({values:t})=>e=>i(e)?!1:Array.isArray(e)?e.every(r=>!t.includes(r)):!t.includes(e),A=()=>t=>typeof t=="string",se=()=>t=>i(t)?!1:A()(t)?/^-?\d+(\.\d+)?$/.test(String(t)):y()(t),ie=({expression:t})=>e=>{if(i(e))return!1;if(!(t instanceof RegExp))throw new TypeError("The expression provided is not a valid RegExp.");return t.test(String(e))},ae=()=>t=>!i(t),le=({value:t})=>e=>i(e)?!1:Array.isArray(e)?e.every(r=>r===t):e===t,L=({size:t})=>e=>i(e)?!1:typeof e=="number"?e===t:Array.isArray(e)?e.every(r=>L({size:t})(r)):!1,$=({length:t})=>e=>i(e)?!1:typeof e=="string"?e.length<=t:Array.isArray(e)?e.every(r=>$({length:t})(r)):!1,p=({length:t})=>e=>i(e)?!1:typeof e=="string"?e.length>=t:Array.isArray(e)?e.every(r=>p({length:t})(r)):!1,ue=({min:t,max:e})=>r=>i(r)?!1:p({length:t})(r)&&$({length:e})(r),S=({length:t})=>e=>i(e)?!1:typeof e=="string"?e.length===t:Array.isArray(e)?e.every(r=>S({length:t})(r)):!1,he={accepted:v,alpha:q,alphaDash:M,alphaDashDot:F,alphaNum:_,array:k,ascii:j,between:B,betweenLength:D,boolean:E,containsAll:W,containsAny:I,declined:Z,different:C,distinct:K,domain:N,email:O,endsWith:V,equals:J,file:P,fileBetweenSize:U,fileMaxSize:d,fileMinSize:g,fileSize:R,http:G,https:H,in:Q,integer:X,json:Y,length:ee,lowercase:te,max:f,maxLength:w,min:m,minLength:T,notEquals:re,notIn:ne,number:y,numeric:se,regex:ie,required:ae,same:le,size:L,startsWith:c,string:A,stringBetweenLength:ue,stringLength:S,stringMaxLength:$,stringMinLength:p,unique:({values:t,ignored:e=[]})=>r=>i(r)?!1:(Array.isArray(e)?e:[e]).some(s=>s===r)?!0:!t.some(s=>s===r),uppercase:()=>t=>i(t)?!1:String(t)===String(t).toUpperCase(),url:()=>t=>i(t)?!1:/^(https?):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}.*$/.test(String(t))};class oe{constructor({fallbackLocale:e,locale:r,plugins:s}={}){h(this,"locale","en");h(this,"fallbackLocale","en");h(this,"locales",{});h(this,"rules",{});this.registerLocales(x),this.registerRules(he),e&&this.setFallbackLocale(e),r&&this.setLocale(r),s&&s.forEach(a=>this.registerPlugin(a))}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 b({name:e,locale:this.locale,fallbackLocale:this.fallbackLocale,locales:this.locales,rules:this.rules})}registerLocales(e){return this.locales=Object.keys(e).reduce((r,s)=>(r[s]={...this.locales[s],...e[s]},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)}}u.FieldValidator=b,u.FormValidator=oe,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(u,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(u=typeof globalThis<"u"?globalThis:u||self,l(u.Fortress={}))})(this,function(u){"use strict";var me=Object.defineProperty;var ge=(u,l,n)=>l in u?me(u,l,{enumerable:!0,configurable:!0,writable:!0,value:n}):u[l]=n;var o=(u,l,n)=>(ge(u,typeof l!="symbol"?l+"":l,n),n);const l=t=>t.replace(/([^\x20-\x7E])([\x20-\x7E])/gu,"$1 $2").replace(/([\x20-\x7E])([^\x20-\x7E])/gu,"$1 $2").replace(/ +/g," "),n=(t,e=0)=>new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e}).format(t),z=t=>Object.prototype.toString.call(t).toLowerCase().slice(8,-1),s=t=>t==null||t===""||Array.isArray(t)&&t.length<1;class b{constructor({name:e,locale:r,fallbackLocale:i,locales:a,rules:h}){o(this,"name");o(this,"locale");o(this,"fallbackLocale");o(this,"locales");o(this,"rules");o(this,"ruleFunctions",[]);o(this,"conditions",{});o(this,"shouldSkip",!1);this.name=e,this.locale=r,this.fallbackLocale=i,this.locales=a,this.rules=h}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 i=>{if(s(i)&&!this.mandatoryRules.includes(e))return!0;const a=this.getRule(e)(r)(i);return typeof a=="string"?a:a===!0?!0:this.buildRuleFunctionMessage(e,r,i)}}buildRuleFunctionMessage(e,r,i){const a=this.getMessage(e)(this.formattedName,r);if(typeof a=="object"){const h=z(i);if(!(h in a))throw new Error(`The message for the "${e}" rule of the "${h}" type is missing.`);return l(a[h])}return l(a)}pushRuleFunction(e,r){if(e in this.conditions&&!this.conditions[e])return this;const i=this.buildRuleFunction(e,r);return this.ruleFunctions.push(i),this}getRuleFunctions(){return this.ruleFunctions}collect(){return this.shouldSkip?[]:this.getRuleFunctions()}validate(e){if(this.shouldSkip)return!0;for(const r of this.ruleFunctions){const i=r(e);if(typeof i=="string")return i}return!0}apply(e,r={}){return this.pushRuleFunction(e,r)}accepted(){return this.apply(this.accepted.name)}after(e,r,i,a=!0){return this.apply(this.after.name,{date:e,format:r,displayFormat:i,strict:a})}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)}ascii(){return this.apply(this.ascii.name)}before(e,r,i,a=!0){return this.apply(this.before.name,{date:e,format:r,displayFormat:i,strict:a})}between(e,r){return this.apply(this.between.name,{min:e,max:r})}betweenLength(e,r){return this.apply(this.betweenLength.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)}fileBetweenSize(e,r){return this.apply(this.fileBetweenSize.name,{min:e,max:r})}fileMaxSize(e){return this.apply(this.fileMaxSize.name,{size:e})}fileMinSize(e){return this.apply(this.fileMinSize.name,{size:e})}fileSize(e){return this.apply(this.fileSize.name,{size:e})}http(){return this.apply(this.http.name)}https(){return this.apply(this.https.name)}integer(){return this.apply(this.integer.name)}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})}length(e){return this.apply(this.length.name,{length:e})}lowercase(){return this.apply(this.lowercase.name)}max(e){return this.apply(this.max.name,{max:e})}maxLength(e){return this.apply(this.maxLength.name,{length:e})}min(e){return this.apply(this.min.name,{min:e})}minLength(e){return this.apply(this.minLength.name,{length: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})}number(){return this.apply(this.number.name)}numeric(){return this.apply(this.numeric.name)}oneOf(e){return this.apply(this.oneOf.name,{values:e})}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)}stringBetweenLength(e,r){return this.apply(this.stringBetweenLength.name,{min:e,max:r})}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})}stringMaxLength(e){return this.apply(this.stringMaxLength.name,{length:e})}stringMinLength(e){return this.apply(this.stringMinLength.name,{length:e})}stringNotContainsAll(e){return this.apply(this.stringNotContainsAll.name,{values:e})}stringNotContainsAny(e){return this.apply(this.stringNotContainsAny.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 C={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.`,ascii:t=>`The ${t} field must only contain ASCII characters and symbols.`,between:(t,e)=>{const{min:r,max:i}=e;return{number:`The ${t} field must be between ${n(r)} and ${n(i)}.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(i)}.`}},betweenLength:(t,e)=>{const{min:r,max:i}=e;return`The ${t} field must be between ${n(r)} and ${n(i)} items.`},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.join(", ")}.`},containsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following values: ${r.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.`,fileBetweenSize:(t,e)=>{const{min:r,max:i}=e;return{file:`The ${t} field must be between ${n(r)} and ${n(i)} kilobytes.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(i)} kilobytes.`}},fileMaxSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must not be greater than ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)} kilobytes.`}},fileMinSize:(t,e)=>{const{size:r}=e;return{file:`The ${t} field must be at least ${n(r)} kilobytes.`,array:`The ${t} field must contain items where each item is at least ${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 either "http://" or "https://".`,https:t=>`The ${t} field must start with "http://".`,integer:t=>`The ${t} field must be an integer.`,json:t=>`The ${t} field must be a valid JSON string.`,length:(t,e)=>{const{length:r}=e;return`The ${t} field must be ${n(r)} items.`},lowercase:t=>`The ${t} field must be lowercase.`,max:(t,e)=>{const{max:r}=e;return{number:`The ${t} field must not be greater than ${n(r)}.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)}.`}},maxLength:(t,e)=>{const{length:r}=e;return`The ${t} field must not be greater than ${n(r)} items.`},min:(t,e)=>{const{min:r}=e;return{number:`The ${t} field must be at least ${n(r)}.`,array:`The ${t} field must contain items where each item is at least ${n(r)}.`}},minLength:(t,e)=>{const{length:r}=e;return`The ${t} field must be at least ${n(r)} items.`},notContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain all of the following values together: ${r.join(", ")}.`},notContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain any of the following values: ${r.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.join(", ")}.`},number:t=>`The ${t} field must be a number.`,numeric:t=>`The ${t} field must be a number.`,oneOf:(t,e)=>{const{values:r}=e;return`The ${t} field must be one of the following values: ${r.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.`,stringBetweenLength:(t,e)=>{const{min:r,max:i}=e;return{string:`The ${t} field must be between ${n(r)} and ${n(i)} characters.`,array:`The ${t} field must contain items where each item is between ${n(r)} and ${n(i)} characters.`}},stringContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must contain all of the following text: ${r.join(", ")}.`},stringContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must contain at least one of the following text: ${r.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.`}},stringMaxLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must not be greater than ${n(r)} characters.`,array:`The ${t} field must contain items where each item is not greater than ${n(r)} characters.`}},stringMinLength:(t,e)=>{const{length:r}=e;return{string:`The ${t} field must be at least ${n(r)} characters.`,array:`The ${t} field must contain items where each item is at least ${n(r)} characters.`}},stringNotContainsAll:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain all of the following text together: ${r.join(", ")}.`},stringNotContainsAny:(t,e)=>{const{values:r}=e;return`The ${t} field must not contain any of the following text: ${r.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:()=>"此欄位必須是一個陣列",ascii:()=>"此欄位只能包含ASCII字元和符號",between:(t,e)=>{const{min:r,max:i}=e;return{number:`此欄位必須介於${n(r)}到${n(i)}`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(i)}`}},betweenLength:(t,e)=>{const{min:r,max:i}=e;return`此欄位必須介於${n(r)}到${n(i)}個項目之間`},boolean:()=>"此欄位必須是一個布林值",containsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有項目:${r.join(", ")}`},containsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個項目:${r.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:()=>"此欄位必須是檔案",fileBetweenSize:(t,e)=>{const{min:r,max:i}=e;return{file:`此欄位必須介於${n(r)}到${n(i)} KB之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(i)} KB之間`}},fileMaxSize:(t,e)=>{const{size:r}=e;return{file:`此欄位不能大於${n(r)} KB`,array:`此欄位中的每個項目都不能大於${n(r)} KB`}},fileMinSize:(t,e)=>{const{size:r}=e;return{file:`此欄位不能小於${n(r)} KB`,array:`此欄位中的每個項目都不能小於${n(r)} KB`}},fileSize:(t,e)=>{const{size:r}=e;return{file:`此欄位必須是${n(r)} KB`,array:`此欄位中的每個項目都必須是${n(r)} KB`}},http:()=>"此欄位必須以 http:// 或 https:// 開頭",https:()=>"此欄位必須以 https:// 開頭",integer:()=>"此欄位必須是整數",json:()=>"此欄位必須是有效的 JSON 字串",length:(t,e)=>{const{length:r}=e;return`此欄位必須包含${n(r)}個項目`},lowercase:()=>"此欄位必須是小寫",max:(t,e)=>{const{max:r}=e;return{number:`此欄位不能大於${n(r)}`,array:`此欄位中的每個項目都不能大於${n(r)}`}},maxLength:(t,e)=>{const{length:r}=e;return`此欄位不能大於${n(r)}個項目`},min:(t,e)=>{const{min:r}=e;return{number:`此欄位不能小於${n(r)}`,array:`此欄位中的每個項目都不能小於${n(r)}`}},minLength:(t,e)=>{const{length:r}=e;return`此欄位不能小於${n(r)}個項目`},notContainsAll:(t,e)=>{const{values:r}=e;return`此欄位不能同時包含以下所有值:${r.join(", ")}`},notContainsAny:(t,e)=>{const{values:r}=e;return`此欄位不能包含以下任何值:${r.join(", ")}`},notEquals:(t,e)=>{const{value:r}=e;return`此欄位不能是${r}`},notOneOf:(t,e)=>{const{values:r}=e;return`此欄位不能是以下任何值:${r.join(", ")}`},number:()=>"此欄位必須是數字",numeric:()=>"此欄位必須是數字",oneOf:(t,e)=>{const{values:r}=e;return`此欄位必須是以下任何值:${r.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:()=>"此欄位必須是字串",stringBetweenLength:(t,e)=>{const{min:r,max:i}=e;return{string:`此欄位必須介於${n(r)}到${n(i)}個字元之間`,array:`此欄位中的每個項目都必須介於${n(r)}到${n(i)}個字元之間`}},stringContainsAll:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下所有文字:${r.join(", ")}`},stringContainsAny:(t,e)=>{const{values:r}=e;return`此欄位必須包含以下其中一個文字:${r.join(", ")}`},stringLength:(t,e)=>{const{length:r}=e;return{string:`此欄位必須是${n(r)}個字元`,array:`此欄位中的每個項目都必須是${n(r)}個字元`}},stringMaxLength:(t,e)=>{const{length:r}=e;return{string:`此欄位不能大於${n(r)}個字元`,array:`此欄位中的每個項目都不能大於${n(r)}個字元`}},stringMinLength:(t,e)=>{const{length:r}=e;return{string:`此欄位不能小於${n(r)}個字元`,array:`此欄位中的每個項目都不能小於${n(r)}個字元`}},stringNotContainsAll:(t,e)=>{const{values:r}=e;return`此欄位不能同時包含以下所有文字:${r.join(", ")}`},stringNotContainsAny:(t,e)=>{const{values:r}=e;return`此欄位不能包含以下任何文字:${r.join(", ")}`},unique:()=>"此欄位已經存在",uppercase:()=>"此欄位必須是大寫",url:()=>"此欄位必須是有效的網址"}},_=()=>t=>s(t)?!1:["y","yes","on","1","true"].includes(String(t).toLowerCase()),j=()=>t=>s(t)?!1:/^[a-zA-Z]+$/.test(String(t)),q=()=>t=>s(t)?!1:/^[a-zA-Z0-9-_]+$/.test(String(t)),M=()=>t=>s(t)?!1:/^[a-zA-Z0-9-_.]+$/.test(String(t)),F=()=>t=>s(t)?!1:/^[a-zA-Z0-9]+$/.test(String(t)),k=()=>t=>Array.isArray(t),O=()=>t=>s(t)?!1:/^[\x20-\x7E]+$/.test(String(t)),c=({max:t})=>e=>s(e)?!1:typeof e=="number"?e<=t:Array.isArray(e)?e.every(r=>c({max:t})(r)):!1,m=({min:t})=>e=>s(e)?!1:typeof e=="number"?e>=t:Array.isArray(e)?e.every(r=>m({min:t})(r)):!1,B=({min:t,max:e})=>r=>s(r)?!1:m({min:t})(r)&&c({max:e})(r),A=({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,D=({min:t,max:e})=>r=>s(r)?!1:w({length:t})(r)&&A({length:e})(r),E=()=>t=>s(t)?!1:typeof t=="boolean",T=({values:t})=>e=>s(e)?!1:Array.isArray(e)?t.every(r=>e.includes(r)):!1,R=({values:t})=>e=>s(e)?!1:Array.isArray(e)?t.some(r=>e.includes(r)):!1,W=()=>t=>s(t)?!1:["n","no","off","0","false"].includes(String(t).toLowerCase()),N=({value:t})=>e=>s(e)?!1:e!==t,Z=()=>t=>s(t)?!1:Array.isArray(t)?new Set(t).size===t.length:!0,K=()=>t=>s(t)?!1:/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(String(t)),I=()=>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).endsWith(t),J=({value:t})=>e=>e===t,P=()=>t=>t instanceof File,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,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,U=({min:t,max:e})=>r=>s(r)?!1:y({size:t})(r)&&g({size:e})(r),L=({size:t})=>e=>{if(s(e))return!1;if(e instanceof File){const r=t*1024,i=(t+1)*1024;return e.size>=r&&e.size<i}return Array.isArray(e)?e.every(r=>L({size:t})(r)):!1},f=({value:t})=>e=>s(e)?!1:String(e).startsWith(t),G=()=>t=>s(t)?!1:f({value:"http://"})(t)||f({value:"https://"})(t),H=()=>t=>s(t)?!1:f({value:"https://"})(t),d=()=>t=>s(t)?!1:typeof t=="number",Q=()=>t=>s(t)?!1:d()(t)&&Number.isInteger(t),X=()=>t=>{if(s(t))return!1;try{return JSON.parse(String(t)),!0}catch{return!1}},Y=({length:t})=>e=>s(e)?!1:Array.isArray(e)?e.length===t:!1,ee=()=>t=>s(t)?!1:String(t)===String(t).toLowerCase(),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=({value:t})=>e=>e!==t,se=({values:t})=>e=>s(e)?!1:!t.includes(e),v=()=>t=>typeof t=="string",ie=()=>t=>s(t)?!1:v()(t)?/^-?\d+(\.\d+)?$/.test(String(t)):d()(t),ae=({values:t})=>e=>s(e)?!1:t.includes(e),le=({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))},ue=()=>t=>!s(t),oe=({value:t})=>e=>s(e)?!1:Array.isArray(e)?e.every(r=>r===t):e===t,S=({size:t})=>e=>s(e)?!1:typeof e=="number"?e===t:Array.isArray(e)?e.every(r=>S({size:t})(r)):!1,$=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length<=t:Array.isArray(e)?e.every(r=>$({length:t})(r)):!1,p=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length>=t:Array.isArray(e)?e.every(r=>p({length:t})(r)):!1,he=({min:t,max:e})=>r=>s(r)?!1:p({length:t})(r)&&$({length:e})(r),x=({length:t})=>e=>s(e)?!1:typeof e=="string"?e.length===t:Array.isArray(e)?e.every(r=>x({length:t})(r)):!1,fe={accepted:_,alpha:j,alphaDash:q,alphaDashDot:M,alphaNum:F,array:k,ascii:O,between:B,betweenLength:D,boolean:E,containsAll:T,containsAny:R,declined:W,different:N,distinct:Z,domain:K,email:I,endsWith:V,equals:J,file:P,fileBetweenSize:U,fileMaxSize:g,fileMinSize:y,fileSize:L,http:G,https:H,integer:Q,json:X,length:Y,lowercase:ee,max:c,maxLength:A,min:m,minLength:w,notContainsAll:te,notContainsAny:re,notEquals:ne,notOneOf:se,number:d,numeric:ie,oneOf:ae,regex:le,required:ue,same:oe,size:S,startsWith:f,string:v,stringBetweenLength:he,stringContainsAll:T,stringContainsAny:R,stringLength:x,stringMaxLength:$,stringMinLength:p,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,unique:({values:t,ignored:e=[]})=>r=>s(r)?!1:(Array.isArray(e)?e:[e]).some(i=>i===r)?!0:!t.some(i=>i===r),uppercase:()=>t=>s(t)?!1:String(t)===String(t).toUpperCase(),url:()=>t=>s(t)?!1:/^(https?):\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}.*$/.test(String(t))};class ce{constructor({fallbackLocale:e,locale:r,plugins:i}={}){o(this,"locale","en");o(this,"fallbackLocale","en");o(this,"locales",{});o(this,"rules",{});this.registerLocales(C),this.registerRules(fe),e&&this.setFallbackLocale(e),r&&this.setLocale(r),i&&i.forEach(a=>this.registerPlugin(a))}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 b({name:e,locale:this.locale,fallbackLocale:this.fallbackLocale,locales:this.locales,rules:this.rules})}registerLocales(e){return this.locales=Object.keys(e).reduce((r,i)=>(r[i]={...this.locales[i],...e[i]},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)}}u.FieldValidator=b,u.FormValidator=ce,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringContainsAllRuleArguments extends RuleArguments {
|
|
3
|
+
values: string[];
|
|
4
|
+
}
|
|
5
|
+
declare const stringContainsAllRule: Rule<StringContainsAllRuleArguments>;
|
|
6
|
+
export default stringContainsAllRule;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringContainsAnyRuleArguments extends RuleArguments {
|
|
3
|
+
values: string[];
|
|
4
|
+
}
|
|
5
|
+
declare const stringContainsAnyRule: Rule<StringContainsAnyRuleArguments>;
|
|
6
|
+
export default stringContainsAnyRule;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringNotContainsAllRuleArguments extends RuleArguments {
|
|
3
|
+
values: string[];
|
|
4
|
+
}
|
|
5
|
+
declare const stringContainsAllRule: Rule<StringNotContainsAllRuleArguments>;
|
|
6
|
+
export default stringContainsAllRule;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Rule, RuleArguments } from '@kklab/fortress-validator-types';
|
|
2
|
+
export interface StringNotContainsAnyRuleArguments extends RuleArguments {
|
|
3
|
+
values: string[];
|
|
4
|
+
}
|
|
5
|
+
declare const stringContainsAnyRule: Rule<StringNotContainsAnyRuleArguments>;
|
|
6
|
+
export default stringContainsAnyRule;
|
package/package.json
CHANGED
package/dist/rules/in.d.ts
DELETED
package/dist/rules/notIn.d.ts
DELETED