@sinclair/typebox 0.25.5 → 0.25.7
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/compiler/compiler.js +26 -25
- package/errors/errors.js +25 -22
- package/package.json +1 -1
- package/value/check.js +25 -22
package/compiler/compiler.js
CHANGED
|
@@ -105,6 +105,9 @@ exports.TypeCompilerUnknownTypeError = TypeCompilerUnknownTypeError;
|
|
|
105
105
|
/** Compiles Types for Runtime Type Checking */
|
|
106
106
|
var TypeCompiler;
|
|
107
107
|
(function (TypeCompiler) {
|
|
108
|
+
function IsNumber(value) {
|
|
109
|
+
return typeof value === 'number';
|
|
110
|
+
}
|
|
108
111
|
// -------------------------------------------------------------------
|
|
109
112
|
// Types
|
|
110
113
|
// -------------------------------------------------------------------
|
|
@@ -113,11 +116,11 @@ var TypeCompiler;
|
|
|
113
116
|
}
|
|
114
117
|
function* Array(schema, value) {
|
|
115
118
|
const expression = CreateExpression(schema.items, 'value');
|
|
116
|
-
if (schema.minItems
|
|
119
|
+
if (IsNumber(schema.minItems))
|
|
117
120
|
yield `(${value}.length >= ${schema.minItems})`;
|
|
118
|
-
if (schema.maxItems
|
|
121
|
+
if (IsNumber(schema.maxItems))
|
|
119
122
|
yield `(${value}.length <= ${schema.maxItems})`;
|
|
120
|
-
if (schema.uniqueItems
|
|
123
|
+
if (schema.uniqueItems === true)
|
|
121
124
|
yield `(new Set(${value}).size === ${value}.length)`;
|
|
122
125
|
yield `(Array.isArray(${value}) && ${value}.every(value => ${expression}))`;
|
|
123
126
|
}
|
|
@@ -129,13 +132,13 @@ var TypeCompiler;
|
|
|
129
132
|
}
|
|
130
133
|
function* Date(schema, value) {
|
|
131
134
|
yield `(${value} instanceof Date)`;
|
|
132
|
-
if (schema.exclusiveMinimumTimestamp
|
|
135
|
+
if (IsNumber(schema.exclusiveMinimumTimestamp))
|
|
133
136
|
yield `(${value}.getTime() > ${schema.exclusiveMinimumTimestamp})`;
|
|
134
|
-
if (schema.exclusiveMaximumTimestamp
|
|
137
|
+
if (IsNumber(schema.exclusiveMaximumTimestamp))
|
|
135
138
|
yield `(${value}.getTime() < ${schema.exclusiveMaximumTimestamp})`;
|
|
136
|
-
if (schema.minimumTimestamp
|
|
139
|
+
if (IsNumber(schema.minimumTimestamp))
|
|
137
140
|
yield `(${value}.getTime() >= ${schema.minimumTimestamp})`;
|
|
138
|
-
if (schema.maximumTimestamp
|
|
141
|
+
if (IsNumber(schema.maximumTimestamp))
|
|
139
142
|
yield `(${value}.getTime() <= ${schema.maximumTimestamp})`;
|
|
140
143
|
}
|
|
141
144
|
function* Function(schema, value) {
|
|
@@ -143,15 +146,15 @@ var TypeCompiler;
|
|
|
143
146
|
}
|
|
144
147
|
function* Integer(schema, value) {
|
|
145
148
|
yield `(typeof ${value} === 'number' && Number.isInteger(${value}))`;
|
|
146
|
-
if (schema.multipleOf
|
|
149
|
+
if (IsNumber(schema.multipleOf))
|
|
147
150
|
yield `(${value} % ${schema.multipleOf} === 0)`;
|
|
148
|
-
if (schema.exclusiveMinimum
|
|
151
|
+
if (IsNumber(schema.exclusiveMinimum))
|
|
149
152
|
yield `(${value} > ${schema.exclusiveMinimum})`;
|
|
150
|
-
if (schema.exclusiveMaximum
|
|
153
|
+
if (IsNumber(schema.exclusiveMaximum))
|
|
151
154
|
yield `(${value} < ${schema.exclusiveMaximum})`;
|
|
152
|
-
if (schema.minimum
|
|
155
|
+
if (IsNumber(schema.minimum))
|
|
153
156
|
yield `(${value} >= ${schema.minimum})`;
|
|
154
|
-
if (schema.maximum
|
|
157
|
+
if (IsNumber(schema.maximum))
|
|
155
158
|
yield `(${value} <= ${schema.maximum})`;
|
|
156
159
|
}
|
|
157
160
|
function* Literal(schema, value) {
|
|
@@ -170,22 +173,22 @@ var TypeCompiler;
|
|
|
170
173
|
}
|
|
171
174
|
function* Number(schema, value) {
|
|
172
175
|
yield `(typeof ${value} === 'number')`;
|
|
173
|
-
if (schema.multipleOf
|
|
176
|
+
if (IsNumber(schema.multipleOf))
|
|
174
177
|
yield `(${value} % ${schema.multipleOf} === 0)`;
|
|
175
|
-
if (schema.exclusiveMinimum
|
|
178
|
+
if (IsNumber(schema.exclusiveMinimum))
|
|
176
179
|
yield `(${value} > ${schema.exclusiveMinimum})`;
|
|
177
|
-
if (schema.exclusiveMaximum
|
|
180
|
+
if (IsNumber(schema.exclusiveMaximum))
|
|
178
181
|
yield `(${value} < ${schema.exclusiveMaximum})`;
|
|
179
|
-
if (schema.minimum
|
|
182
|
+
if (IsNumber(schema.minimum))
|
|
180
183
|
yield `(${value} >= ${schema.minimum})`;
|
|
181
|
-
if (schema.maximum
|
|
184
|
+
if (IsNumber(schema.maximum))
|
|
182
185
|
yield `(${value} <= ${schema.maximum})`;
|
|
183
186
|
}
|
|
184
187
|
function* Object(schema, value) {
|
|
185
188
|
yield `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))`;
|
|
186
|
-
if (schema.minProperties
|
|
189
|
+
if (IsNumber(schema.minProperties))
|
|
187
190
|
yield `(Object.keys(${value}).length >= ${schema.minProperties})`;
|
|
188
|
-
if (schema.maxProperties
|
|
191
|
+
if (IsNumber(schema.maxProperties))
|
|
189
192
|
yield `(Object.keys(${value}).length <= ${schema.maxProperties})`;
|
|
190
193
|
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
191
194
|
if (schema.additionalProperties === false) {
|
|
@@ -246,12 +249,10 @@ var TypeCompiler;
|
|
|
246
249
|
}
|
|
247
250
|
function* String(schema, value) {
|
|
248
251
|
yield `(typeof ${value} === 'string')`;
|
|
249
|
-
if (schema.minLength
|
|
252
|
+
if (IsNumber(schema.minLength))
|
|
250
253
|
yield `(${value}.length >= ${schema.minLength})`;
|
|
251
|
-
|
|
252
|
-
if (schema.maxLength !== undefined) {
|
|
254
|
+
if (IsNumber(schema.maxLength))
|
|
253
255
|
yield `(${value}.length <= ${schema.maxLength})`;
|
|
254
|
-
}
|
|
255
256
|
if (schema.pattern !== undefined) {
|
|
256
257
|
const local = PushLocal(`new RegExp(/${schema.pattern}/);`);
|
|
257
258
|
yield `(${local}.test(${value}))`;
|
|
@@ -279,9 +280,9 @@ var TypeCompiler;
|
|
|
279
280
|
}
|
|
280
281
|
function* Uint8Array(schema, value) {
|
|
281
282
|
yield `(${value} instanceof Uint8Array)`;
|
|
282
|
-
if (schema.maxByteLength)
|
|
283
|
+
if (IsNumber(schema.maxByteLength))
|
|
283
284
|
yield `(${value}.length <= ${schema.maxByteLength})`;
|
|
284
|
-
if (schema.minByteLength)
|
|
285
|
+
if (IsNumber(schema.minByteLength))
|
|
285
286
|
yield `(${value}.length >= ${schema.minByteLength})`;
|
|
286
287
|
}
|
|
287
288
|
function* Unknown(schema, value) {
|
package/errors/errors.js
CHANGED
|
@@ -97,15 +97,18 @@ exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
|
|
|
97
97
|
/** Provides functionality to generate a sequence of errors against a TypeBox type. */
|
|
98
98
|
var ValueErrors;
|
|
99
99
|
(function (ValueErrors) {
|
|
100
|
+
function IsNumber(value) {
|
|
101
|
+
return typeof value === 'number';
|
|
102
|
+
}
|
|
100
103
|
function* Any(schema, references, path, value) { }
|
|
101
104
|
function* Array(schema, references, path, value) {
|
|
102
105
|
if (!globalThis.Array.isArray(value)) {
|
|
103
106
|
return yield { type: ValueErrorType.Array, schema, path, value, message: `Expected array` };
|
|
104
107
|
}
|
|
105
|
-
if (schema.minItems
|
|
108
|
+
if (IsNumber(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
106
109
|
yield { type: ValueErrorType.ArrayMinItems, schema, path, value, message: `Expected array length to be greater or equal to ${schema.minItems}` };
|
|
107
110
|
}
|
|
108
|
-
if (schema.maxItems
|
|
111
|
+
if (IsNumber(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
109
112
|
yield { type: ValueErrorType.ArrayMinItems, schema, path, value, message: `Expected array length to be less or equal to ${schema.maxItems}` };
|
|
110
113
|
}
|
|
111
114
|
if (schema.uniqueItems === true && !(new Set(value).size === value.length)) {
|
|
@@ -127,16 +130,16 @@ var ValueErrors;
|
|
|
127
130
|
if (!(value instanceof globalThis.Date)) {
|
|
128
131
|
return yield { type: ValueErrorType.Date, schema, path, value, message: `Expected Date object` };
|
|
129
132
|
}
|
|
130
|
-
if (schema.exclusiveMinimumTimestamp && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
133
|
+
if (IsNumber(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
131
134
|
yield { type: ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value, message: `Expected Date timestamp to be greater than ${schema.exclusiveMinimum}` };
|
|
132
135
|
}
|
|
133
|
-
if (schema.exclusiveMaximumTimestamp && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
136
|
+
if (IsNumber(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
134
137
|
yield { type: ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value, message: `Expected Date timestamp to be less than ${schema.exclusiveMaximum}` };
|
|
135
138
|
}
|
|
136
|
-
if (schema.minimumTimestamp && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
139
|
+
if (IsNumber(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
137
140
|
yield { type: ValueErrorType.DateMinimumTimestamp, schema, path, value, message: `Expected Date timestamp to be greater or equal to ${schema.minimum}` };
|
|
138
141
|
}
|
|
139
|
-
if (schema.maximumTimestamp && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
142
|
+
if (IsNumber(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
140
143
|
yield { type: ValueErrorType.DateMaximumTimestamp, schema, path, value, message: `Expected Date timestamp to be less or equal to ${schema.maximum}` };
|
|
141
144
|
}
|
|
142
145
|
}
|
|
@@ -152,19 +155,19 @@ var ValueErrors;
|
|
|
152
155
|
if (!globalThis.Number.isInteger(value)) {
|
|
153
156
|
yield { type: ValueErrorType.Integer, schema, path, value, message: `Expected integer` };
|
|
154
157
|
}
|
|
155
|
-
if (schema.multipleOf && !(value % schema.multipleOf === 0)) {
|
|
158
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
156
159
|
yield { type: ValueErrorType.IntegerMultipleOf, schema, path, value, message: `Expected integer to be a multiple of ${schema.multipleOf}` };
|
|
157
160
|
}
|
|
158
|
-
if (schema.exclusiveMinimum && !(value > schema.exclusiveMinimum)) {
|
|
161
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
159
162
|
yield { type: ValueErrorType.IntegerExclusiveMinimum, schema, path, value, message: `Expected integer to be greater than ${schema.exclusiveMinimum}` };
|
|
160
163
|
}
|
|
161
|
-
if (schema.exclusiveMaximum && !(value < schema.exclusiveMaximum)) {
|
|
164
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
162
165
|
yield { type: ValueErrorType.IntegerExclusiveMaximum, schema, path, value, message: `Expected integer to be less than ${schema.exclusiveMaximum}` };
|
|
163
166
|
}
|
|
164
|
-
if (schema.minimum && !(value >= schema.minimum)) {
|
|
167
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
165
168
|
yield { type: ValueErrorType.IntegerMinimum, schema, path, value, message: `Expected integer to be greater or equal to ${schema.minimum}` };
|
|
166
169
|
}
|
|
167
|
-
if (schema.maximum && !(value <= schema.maximum)) {
|
|
170
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
168
171
|
yield { type: ValueErrorType.IntegerMaximum, schema, path, value, message: `Expected integer to be less or equal to ${schema.maximum}` };
|
|
169
172
|
}
|
|
170
173
|
}
|
|
@@ -186,19 +189,19 @@ var ValueErrors;
|
|
|
186
189
|
if (!(typeof value === 'number')) {
|
|
187
190
|
return yield { type: ValueErrorType.Number, schema, path, value, message: `Expected number` };
|
|
188
191
|
}
|
|
189
|
-
if (schema.multipleOf && !(value % schema.multipleOf === 0)) {
|
|
192
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
190
193
|
yield { type: ValueErrorType.NumberMultipleOf, schema, path, value, message: `Expected number to be a multiple of ${schema.multipleOf}` };
|
|
191
194
|
}
|
|
192
|
-
if (schema.exclusiveMinimum && !(value > schema.exclusiveMinimum)) {
|
|
195
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
193
196
|
yield { type: ValueErrorType.NumberExclusiveMinimum, schema, path, value, message: `Expected number to be greater than ${schema.exclusiveMinimum}` };
|
|
194
197
|
}
|
|
195
|
-
if (schema.exclusiveMaximum && !(value < schema.exclusiveMaximum)) {
|
|
198
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
196
199
|
yield { type: ValueErrorType.NumberExclusiveMaximum, schema, path, value, message: `Expected number to be less than ${schema.exclusiveMaximum}` };
|
|
197
200
|
}
|
|
198
|
-
if (schema.minimum && !(value >= schema.minimum)) {
|
|
201
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
199
202
|
yield { type: ValueErrorType.NumberMaximum, schema, path, value, message: `Expected number to be greater or equal to ${schema.minimum}` };
|
|
200
203
|
}
|
|
201
|
-
if (schema.maximum && !(value <= schema.maximum)) {
|
|
204
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
202
205
|
yield { type: ValueErrorType.NumberMinumum, schema, path, value, message: `Expected number to be less or equal to ${schema.maximum}` };
|
|
203
206
|
}
|
|
204
207
|
}
|
|
@@ -206,10 +209,10 @@ var ValueErrors;
|
|
|
206
209
|
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
207
210
|
return yield { type: ValueErrorType.Object, schema, path, value, message: `Expected object` };
|
|
208
211
|
}
|
|
209
|
-
if (schema.minProperties
|
|
212
|
+
if (IsNumber(schema.minProperties) && !(globalThis.Object.keys(value).length >= schema.minProperties)) {
|
|
210
213
|
yield { type: ValueErrorType.ObjectMinProperties, schema, path, value, message: `Expected object to have at least ${schema.minProperties} properties` };
|
|
211
214
|
}
|
|
212
|
-
if (schema.maxProperties
|
|
215
|
+
if (IsNumber(schema.maxProperties) && !(globalThis.Object.keys(value).length <= schema.maxProperties)) {
|
|
213
216
|
yield { type: ValueErrorType.ObjectMaxProperties, schema, path, value, message: `Expected object to have less than ${schema.minProperties} properties` };
|
|
214
217
|
}
|
|
215
218
|
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
@@ -284,10 +287,10 @@ var ValueErrors;
|
|
|
284
287
|
if (!(typeof value === 'string')) {
|
|
285
288
|
return yield { type: ValueErrorType.String, schema, path, value, message: 'Expected string' };
|
|
286
289
|
}
|
|
287
|
-
if (schema.minLength
|
|
290
|
+
if (IsNumber(schema.minLength) && !(value.length >= schema.minLength)) {
|
|
288
291
|
yield { type: ValueErrorType.StringMinLength, schema, path, value, message: `Expected string length greater or equal to ${schema.minLength}` };
|
|
289
292
|
}
|
|
290
|
-
if (schema.maxLength
|
|
293
|
+
if (IsNumber(schema.maxLength) && !(value.length <= schema.maxLength)) {
|
|
291
294
|
yield { type: ValueErrorType.StringMaxLength, schema, path, value, message: `Expected string length less or equal to ${schema.maxLength}` };
|
|
292
295
|
}
|
|
293
296
|
if (schema.pattern !== undefined) {
|
|
@@ -349,10 +352,10 @@ var ValueErrors;
|
|
|
349
352
|
if (!(value instanceof globalThis.Uint8Array)) {
|
|
350
353
|
return yield { type: ValueErrorType.Uint8Array, schema, path, value, message: `Expected Uint8Array` };
|
|
351
354
|
}
|
|
352
|
-
if (schema.maxByteLength && !(value.length <= schema.maxByteLength)) {
|
|
355
|
+
if (IsNumber(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
353
356
|
yield { type: ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value, message: `Expected Uint8Array to have a byte length less or equal to ${schema.maxByteLength}` };
|
|
354
357
|
}
|
|
355
|
-
if (schema.minByteLength && !(value.length >= schema.minByteLength)) {
|
|
358
|
+
if (IsNumber(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
356
359
|
yield { type: ValueErrorType.Uint8ArrayMinByteLength, schema, path, value, message: `Expected Uint8Array to have a byte length greater or equal to ${schema.maxByteLength}` };
|
|
357
360
|
}
|
|
358
361
|
}
|
package/package.json
CHANGED
package/value/check.js
CHANGED
|
@@ -39,6 +39,9 @@ class ValueCheckUnknownTypeError extends Error {
|
|
|
39
39
|
exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
|
|
40
40
|
var ValueCheck;
|
|
41
41
|
(function (ValueCheck) {
|
|
42
|
+
function IsNumber(value) {
|
|
43
|
+
return typeof value === 'number';
|
|
44
|
+
}
|
|
42
45
|
function Any(schema, references, value) {
|
|
43
46
|
return true;
|
|
44
47
|
}
|
|
@@ -46,10 +49,10 @@ var ValueCheck;
|
|
|
46
49
|
if (!globalThis.Array.isArray(value)) {
|
|
47
50
|
return false;
|
|
48
51
|
}
|
|
49
|
-
if (schema.minItems
|
|
52
|
+
if (IsNumber(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
50
53
|
return false;
|
|
51
54
|
}
|
|
52
|
-
if (schema.maxItems
|
|
55
|
+
if (IsNumber(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
53
56
|
return false;
|
|
54
57
|
}
|
|
55
58
|
if (schema.uniqueItems === true && !(new Set(value).size === value.length)) {
|
|
@@ -67,16 +70,16 @@ var ValueCheck;
|
|
|
67
70
|
if (!(value instanceof globalThis.Date)) {
|
|
68
71
|
return false;
|
|
69
72
|
}
|
|
70
|
-
if (schema.exclusiveMinimumTimestamp && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
73
|
+
if (IsNumber(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
71
74
|
return false;
|
|
72
75
|
}
|
|
73
|
-
if (schema.exclusiveMaximumTimestamp && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
76
|
+
if (IsNumber(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
74
77
|
return false;
|
|
75
78
|
}
|
|
76
|
-
if (schema.minimumTimestamp && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
79
|
+
if (IsNumber(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
77
80
|
return false;
|
|
78
81
|
}
|
|
79
|
-
if (schema.maximumTimestamp && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
82
|
+
if (IsNumber(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
80
83
|
return false;
|
|
81
84
|
}
|
|
82
85
|
return true;
|
|
@@ -91,19 +94,19 @@ var ValueCheck;
|
|
|
91
94
|
if (!globalThis.Number.isInteger(value)) {
|
|
92
95
|
return false;
|
|
93
96
|
}
|
|
94
|
-
if (schema.multipleOf
|
|
97
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
95
98
|
return false;
|
|
96
99
|
}
|
|
97
|
-
if (schema.exclusiveMinimum
|
|
100
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
98
101
|
return false;
|
|
99
102
|
}
|
|
100
|
-
if (schema.exclusiveMaximum
|
|
103
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
101
104
|
return false;
|
|
102
105
|
}
|
|
103
|
-
if (schema.minimum
|
|
106
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
104
107
|
return false;
|
|
105
108
|
}
|
|
106
|
-
if (schema.maximum
|
|
109
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
107
110
|
return false;
|
|
108
111
|
}
|
|
109
112
|
return true;
|
|
@@ -121,19 +124,19 @@ var ValueCheck;
|
|
|
121
124
|
if (!(typeof value === 'number')) {
|
|
122
125
|
return false;
|
|
123
126
|
}
|
|
124
|
-
if (schema.multipleOf && !(value % schema.multipleOf === 0)) {
|
|
127
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
125
128
|
return false;
|
|
126
129
|
}
|
|
127
|
-
if (schema.exclusiveMinimum && !(value > schema.exclusiveMinimum)) {
|
|
130
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
128
131
|
return false;
|
|
129
132
|
}
|
|
130
|
-
if (schema.exclusiveMaximum && !(value < schema.exclusiveMaximum)) {
|
|
133
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
131
134
|
return false;
|
|
132
135
|
}
|
|
133
|
-
if (schema.minimum && !(value >= schema.minimum)) {
|
|
136
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
134
137
|
return false;
|
|
135
138
|
}
|
|
136
|
-
if (schema.maximum && !(value <= schema.maximum)) {
|
|
139
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
137
140
|
return false;
|
|
138
141
|
}
|
|
139
142
|
return true;
|
|
@@ -142,10 +145,10 @@ var ValueCheck;
|
|
|
142
145
|
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
143
146
|
return false;
|
|
144
147
|
}
|
|
145
|
-
if (schema.minProperties
|
|
148
|
+
if (IsNumber(schema.minProperties) && !(globalThis.Object.keys(value).length >= schema.minProperties)) {
|
|
146
149
|
return false;
|
|
147
150
|
}
|
|
148
|
-
if (schema.maxProperties
|
|
151
|
+
if (IsNumber(schema.maxProperties) && !(globalThis.Object.keys(value).length <= schema.maxProperties)) {
|
|
149
152
|
return false;
|
|
150
153
|
}
|
|
151
154
|
const propertyKeys = globalThis.Object.keys(schema.properties);
|
|
@@ -223,11 +226,11 @@ var ValueCheck;
|
|
|
223
226
|
if (!(typeof value === 'string')) {
|
|
224
227
|
return false;
|
|
225
228
|
}
|
|
226
|
-
if (schema.minLength
|
|
229
|
+
if (IsNumber(schema.minLength)) {
|
|
227
230
|
if (!(value.length >= schema.minLength))
|
|
228
231
|
return false;
|
|
229
232
|
}
|
|
230
|
-
if (schema.maxLength
|
|
233
|
+
if (IsNumber(schema.maxLength)) {
|
|
231
234
|
if (!(value.length <= schema.maxLength))
|
|
232
235
|
return false;
|
|
233
236
|
}
|
|
@@ -273,10 +276,10 @@ var ValueCheck;
|
|
|
273
276
|
if (!(value instanceof globalThis.Uint8Array)) {
|
|
274
277
|
return false;
|
|
275
278
|
}
|
|
276
|
-
if (schema.maxByteLength && !(value.length <= schema.maxByteLength)) {
|
|
279
|
+
if (IsNumber(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
277
280
|
return false;
|
|
278
281
|
}
|
|
279
|
-
if (schema.minByteLength && !(value.length >= schema.minByteLength)) {
|
|
282
|
+
if (IsNumber(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
280
283
|
return false;
|
|
281
284
|
}
|
|
282
285
|
return true;
|