dalila 1.5.1 → 1.5.2
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/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/router/validation.js +20 -2
- package/package.json +1 -1
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.js
CHANGED
|
@@ -14,6 +14,24 @@ function toLength(value) {
|
|
|
14
14
|
return value;
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
|
+
function toNumericOrLength(value) {
|
|
18
|
+
if (typeof value === 'number') {
|
|
19
|
+
return Number.isFinite(value) ? value : null;
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
const trimmed = value.trim();
|
|
23
|
+
if (trimmed.length === 0)
|
|
24
|
+
return 0;
|
|
25
|
+
const numeric = Number(trimmed);
|
|
26
|
+
if (Number.isFinite(numeric))
|
|
27
|
+
return numeric;
|
|
28
|
+
return value.length;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(value)) {
|
|
31
|
+
return value.length;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
17
35
|
function toNumber(value) {
|
|
18
36
|
if (typeof value === 'number')
|
|
19
37
|
return Number.isFinite(value) ? value : null;
|
|
@@ -50,7 +68,7 @@ function buildBuiltinRule(name, rawArg, message) {
|
|
|
50
68
|
if (min === null)
|
|
51
69
|
return () => undefined;
|
|
52
70
|
return value => {
|
|
53
|
-
const size =
|
|
71
|
+
const size = toNumericOrLength(value);
|
|
54
72
|
if (size === null)
|
|
55
73
|
return undefined;
|
|
56
74
|
return size >= min ? undefined : fail(`Must be at least ${min}.`);
|
|
@@ -61,7 +79,7 @@ function buildBuiltinRule(name, rawArg, message) {
|
|
|
61
79
|
if (max === null)
|
|
62
80
|
return () => undefined;
|
|
63
81
|
return value => {
|
|
64
|
-
const size =
|
|
82
|
+
const size = toNumericOrLength(value);
|
|
65
83
|
if (size === null)
|
|
66
84
|
return undefined;
|
|
67
85
|
return size <= max ? undefined : fail(`Must be at most ${max}.`);
|