@vida-global/core 2.3.0 → 2.3.1
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.
|
@@ -70,6 +70,7 @@ const InstanceMethods = {
|
|
|
70
70
|
|
|
71
71
|
validateIsString(value, options) {
|
|
72
72
|
if (typeof value !== 'string') return 'must be a string';
|
|
73
|
+
if (options?.allowEmpty === false && value.length === 0) return 'must not be empty';
|
|
73
74
|
|
|
74
75
|
if (options?.length?.gte !== undefined) {
|
|
75
76
|
if (value.length < options.length.gte) return `must be greater than or equal to ${options.length.gte} characters`;
|
|
@@ -29,7 +29,7 @@ class UsersController extends VidaServerController {
|
|
|
29
29
|
- `{ presence: true }`
|
|
30
30
|
- `{ isInteger: true }` or `{ isInteger: { gte: 0, lte: 100 } }`
|
|
31
31
|
- `{ isNumber: true }` or `{ isNumber: { gte: 0, lte: 9.99 } }` — accepts integers and decimals.
|
|
32
|
-
- `{ isString: true }` or `{ isString: { length: { gte: 10, lte: 100 }, regex: /foo/ } }`
|
|
32
|
+
- `{ isString: true }` or `{ isString: { allowEmpty: false, length: { gte: 10, lte: 100 }, regex: /foo/ } }` — `allowEmpty` defaults to `true`; when `false`, it rejects `''` but allows whitespace-only strings.
|
|
33
33
|
- `{ isBoolean: true }` or `{ isBoolean: false }` (asserts the exact value)
|
|
34
34
|
- `{ isDateTime: true }`
|
|
35
35
|
- `{ isEnum: { enums: ['a', 'b', 'c'], error: 'optional message' } }`
|
|
@@ -75,6 +75,7 @@ class Schemas {
|
|
|
75
75
|
if (options?.length?.gte !== undefined) schema.minLength = options.length.gte;
|
|
76
76
|
if (options?.length?.lte !== undefined) schema.maxLength = options.length.lte;
|
|
77
77
|
if (options?.regex) schema.pattern = options.regex.source;
|
|
78
|
+
if (options?.allowEmpty === false) schema.minLength = Math.max(schema.minLength || 0, 1);
|
|
78
79
|
return schema;
|
|
79
80
|
}
|
|
80
81
|
|