@streamscloud/kit 0.9.17 → 0.9.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/validation/validation-schemas/array-validations.d.ts +3 -0
- package/dist/core/validation/validation-schemas/array-validations.js +20 -0
- package/dist/core/validation/validation-schemas/index.d.ts +2 -1
- package/dist/core/validation/validation-schemas/index.js +1 -0
- package/dist/core/validation/validation-schemas/types.d.ts +4 -0
- package/dist/core/validation/validation-schemas/validation-localization.d.ts +2 -0
- package/dist/core/validation/validation-schemas/validation-localization.js +14 -0
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ValidationLocalization } from './validation-localization';
|
|
2
|
+
import * as yup from 'yup';
|
|
3
|
+
export const arrayValidationSchema = (rules) => {
|
|
4
|
+
const msg = new ValidationLocalization();
|
|
5
|
+
const minItems = rules.minItems > 0 ? rules.minItems : 0;
|
|
6
|
+
const maxItems = rules.maxItems !== null && rules.maxItems >= 0 && rules.maxItems >= minItems ? rules.maxItems : undefined;
|
|
7
|
+
let schema = yup.array();
|
|
8
|
+
if (maxItems !== undefined) {
|
|
9
|
+
schema = schema.max(maxItems, msg.maxItems(maxItems));
|
|
10
|
+
}
|
|
11
|
+
if (minItems === 1) {
|
|
12
|
+
return schema.min(1, msg.required);
|
|
13
|
+
}
|
|
14
|
+
else if (minItems > 1) {
|
|
15
|
+
return schema.min(minItems, msg.minItems(minItems));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return schema;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export type { TextValidation, TextWithFormatValidation, NumberValidation, MinNumberValidation } from './types';
|
|
1
|
+
export type { TextValidation, TextWithFormatValidation, NumberValidation, MinNumberValidation, ArrayValidation } from './types';
|
|
2
2
|
export { emailValidationSchema, nullableEmailValidationSchema } from './email-validation';
|
|
3
3
|
export { textValidationSchema, formattedTextValidationSchema } from './text-validations';
|
|
4
4
|
export { handleValidationSchema } from './handle-validations';
|
|
5
5
|
export { numberValidationSchema, minNumberValidationSchema } from './number-validations';
|
|
6
|
+
export { arrayValidationSchema } from './array-validations';
|
|
@@ -2,3 +2,4 @@ export { emailValidationSchema, nullableEmailValidationSchema } from './email-va
|
|
|
2
2
|
export { textValidationSchema, formattedTextValidationSchema } from './text-validations';
|
|
3
3
|
export { handleValidationSchema } from './handle-validations';
|
|
4
4
|
export { numberValidationSchema, minNumberValidationSchema } from './number-validations';
|
|
5
|
+
export { arrayValidationSchema } from './array-validations';
|
|
@@ -5,5 +5,7 @@ export declare class ValidationLocalization {
|
|
|
5
5
|
get maxLength(): (length: number) => string;
|
|
6
6
|
get min(): (val: number) => string;
|
|
7
7
|
get max(): (val: number) => string;
|
|
8
|
+
get minItems(): (count: number) => string;
|
|
9
|
+
get maxItems(): (count: number) => string;
|
|
8
10
|
get badFormat(): string;
|
|
9
11
|
}
|
|
@@ -18,6 +18,12 @@ export class ValidationLocalization {
|
|
|
18
18
|
get max() {
|
|
19
19
|
return loc.max[AppLocale.current];
|
|
20
20
|
}
|
|
21
|
+
get minItems() {
|
|
22
|
+
return loc.minItems[AppLocale.current];
|
|
23
|
+
}
|
|
24
|
+
get maxItems() {
|
|
25
|
+
return loc.maxItems[AppLocale.current];
|
|
26
|
+
}
|
|
21
27
|
get badFormat() {
|
|
22
28
|
return loc.badFormat[AppLocale.current];
|
|
23
29
|
}
|
|
@@ -47,6 +53,14 @@ const loc = {
|
|
|
47
53
|
en: (val) => `Must be at most ${val}`,
|
|
48
54
|
no: (val) => `Kan ikke være mer enn ${val}`
|
|
49
55
|
},
|
|
56
|
+
minItems: {
|
|
57
|
+
en: (count) => `Must contain at least ${count} items`,
|
|
58
|
+
no: (count) => `Må inneholde minst ${count} elementer`
|
|
59
|
+
},
|
|
60
|
+
maxItems: {
|
|
61
|
+
en: (count) => `Must contain at most ${count} item${count === 1 ? '' : 's'}`,
|
|
62
|
+
no: (count) => `Kan ikke inneholde mer enn ${count} element${count === 1 ? '' : 'er'}`
|
|
63
|
+
},
|
|
50
64
|
badFormat: {
|
|
51
65
|
en: 'Invalid format',
|
|
52
66
|
no: 'Ugyldig format'
|