befly 3.8.18 → 3.8.19

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.
Files changed (2) hide show
  1. package/lib/validator.ts +11 -4
  2. package/package.json +2 -2
package/lib/validator.ts CHANGED
@@ -154,22 +154,29 @@ export class Validator {
154
154
  */
155
155
  private validateNumber(value: any, name: string, min: number | null, max: number | null, spec: string | null, fieldName: string): ValidationError {
156
156
  try {
157
- if (typeof value !== 'number' || Number.isNaN(value) || !isFinite(value)) {
157
+ // 允许数字类型的字符串
158
+ let numValue = value;
159
+ if (typeof value === 'string') {
160
+ numValue = Number(value);
161
+ if (Number.isNaN(numValue) || !isFinite(numValue)) {
162
+ return `${name}(${fieldName})必须是数字`;
163
+ }
164
+ } else if (typeof numValue !== 'number' || Number.isNaN(numValue) || !isFinite(numValue)) {
158
165
  return `${name}(${fieldName})必须是数字`;
159
166
  }
160
167
 
161
- if (min !== null && value < min) {
168
+ if (min !== null && numValue < min) {
162
169
  return `${name}(${fieldName})不能小于${min}`;
163
170
  }
164
171
 
165
- if (max !== null && max > 0 && value > max) {
172
+ if (max !== null && max > 0 && numValue > max) {
166
173
  return `${name}(${fieldName})不能大于${max}`;
167
174
  }
168
175
 
169
176
  if (spec && spec.trim() !== '') {
170
177
  try {
171
178
  const regExp = new RegExp(spec);
172
- if (!regExp.test(String(value))) {
179
+ if (!regExp.test(String(numValue))) {
173
180
  return `${name}(${fieldName})格式不正确`;
174
181
  }
175
182
  } catch (error: any) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.8.18",
3
+ "version": "3.8.19",
4
4
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
5
5
  "type": "module",
6
6
  "private": false,
@@ -65,5 +65,5 @@
65
65
  "es-toolkit": "^1.41.0",
66
66
  "pathe": "^2.0.3"
67
67
  },
68
- "gitHead": "29e1bc79619581b841052206a59b124e027dfd20"
68
+ "gitHead": "0619a7cfdd889be9fdd1b187c3d6522288707df0"
69
69
  }