valgen 5.19.3 → 5.19.5
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/constants.js
CHANGED
package/package.json
CHANGED
|
@@ -50,7 +50,7 @@ export function isDateString(options) {
|
|
|
50
50
|
if (parsed.precision < precisionMinIdx) {
|
|
51
51
|
context.fail(_this, `Minimum date precision should be ${precisionMin}`, input, options);
|
|
52
52
|
}
|
|
53
|
-
if (parsed.precision > precisionMaxIdx) {
|
|
53
|
+
if (parsed.precision > precisionMaxIdx && !(input instanceof Date)) {
|
|
54
54
|
context.fail(_this, `Maximum date precision should be ${precisionMax}`, input, options);
|
|
55
55
|
}
|
|
56
56
|
return coerce ? parsed.value : input;
|
|
@@ -75,8 +75,11 @@ function coerceDateString(input, trimPrecision) {
|
|
|
75
75
|
String(d.getMinutes()).padStart(2, '0'),
|
|
76
76
|
String(d.getSeconds()).padStart(2, '0'),
|
|
77
77
|
];
|
|
78
|
-
if (precisionIndex >= 7
|
|
79
|
-
|
|
78
|
+
if (precisionIndex >= 7)
|
|
79
|
+
if (d.getMilliseconds() > 0)
|
|
80
|
+
dateParts.push(String(d.getMilliseconds()).padStart(3, '0'));
|
|
81
|
+
else
|
|
82
|
+
dateParts.push('');
|
|
80
83
|
if (precisionIndex >= 8) {
|
|
81
84
|
const tzOffset = d.getTimezoneOffset();
|
|
82
85
|
const tz = tzOffset > 0
|
|
@@ -3,7 +3,7 @@ import { type ValidationOptions, type Validator } from '../../core/index.js';
|
|
|
3
3
|
* Validates if given value is one of enum values.
|
|
4
4
|
* @validator isEnum
|
|
5
5
|
*/
|
|
6
|
-
export declare function isEnum<T1
|
|
6
|
+
export declare function isEnum<T1>(values: any, options?: ValidationOptions & {
|
|
7
7
|
caseInSensitive?: boolean;
|
|
8
8
|
enumName?: string;
|
|
9
|
-
}): Validator<T1,
|
|
9
|
+
}): Validator<T1, any>;
|
|
@@ -7,6 +7,14 @@ export function isEnum(values, options) {
|
|
|
7
7
|
const caseInSensitive = !!options?.caseInSensitive;
|
|
8
8
|
const enumName = options?.enumName;
|
|
9
9
|
// Prepare an object for fast lookup
|
|
10
|
+
if (values && typeof values === 'object' && !Array.isArray(values)) {
|
|
11
|
+
const keys = Object.keys(values).filter(k => !/^\d+$/.test(k));
|
|
12
|
+
values = keys.reduce((a, k) => {
|
|
13
|
+
if (values[k] != null)
|
|
14
|
+
a.push(values[k]);
|
|
15
|
+
return a;
|
|
16
|
+
}, []);
|
|
17
|
+
}
|
|
10
18
|
const valObj = (Array.isArray(values) ? values : [values]).reduce((a, v) => {
|
|
11
19
|
if (typeof v === 'string' && caseInSensitive)
|
|
12
20
|
a[v.toUpperCase()] = true;
|