@sinclair/typebox 0.24.9 → 0.24.10
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 +6 -0
- package/package.json +1 -1
- package/value/check.js +8 -0
- package/value/create.js +6 -1
- package/value/errors.js +6 -0
package/compiler/compiler.js
CHANGED
|
@@ -183,6 +183,12 @@ var TypeCompiler;
|
|
|
183
183
|
}
|
|
184
184
|
function* String(schema, value) {
|
|
185
185
|
yield `(typeof ${value} === 'string')`;
|
|
186
|
+
if (schema.minLength !== undefined) {
|
|
187
|
+
yield `(${value}.length >= ${schema.minLength})`;
|
|
188
|
+
}
|
|
189
|
+
if (schema.maxLength !== undefined) {
|
|
190
|
+
yield `(${value}.length <= ${schema.maxLength})`;
|
|
191
|
+
}
|
|
186
192
|
if (schema.pattern !== undefined) {
|
|
187
193
|
const local = PushLocal(`const local = new RegExp('${schema.pattern}');`);
|
|
188
194
|
yield `(${local}.test(${value}))`;
|
package/package.json
CHANGED
package/value/check.js
CHANGED
|
@@ -176,6 +176,14 @@ var ValueCheck;
|
|
|
176
176
|
if (!(typeof value === 'string')) {
|
|
177
177
|
return false;
|
|
178
178
|
}
|
|
179
|
+
if (schema.minLength !== undefined) {
|
|
180
|
+
if (!(value.length >= schema.minLength))
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
if (schema.maxLength !== undefined) {
|
|
184
|
+
if (!(value.length <= schema.maxLength))
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
179
187
|
if (schema.pattern !== undefined) {
|
|
180
188
|
const regex = new RegExp(schema.pattern);
|
|
181
189
|
if (!regex.test(value))
|
package/value/create.js
CHANGED
|
@@ -207,6 +207,11 @@ var ValueCreate;
|
|
|
207
207
|
if (schema.default !== undefined) {
|
|
208
208
|
return schema.default;
|
|
209
209
|
}
|
|
210
|
+
else if (schema.minLength !== undefined) {
|
|
211
|
+
return globalThis.Array.from({ length: schema.minLength })
|
|
212
|
+
.map(() => '.')
|
|
213
|
+
.join('');
|
|
214
|
+
}
|
|
210
215
|
else {
|
|
211
216
|
return '';
|
|
212
217
|
}
|
|
@@ -241,7 +246,7 @@ var ValueCreate;
|
|
|
241
246
|
if (schema.default !== undefined) {
|
|
242
247
|
return schema.default;
|
|
243
248
|
}
|
|
244
|
-
else if (schema.minByteLength) {
|
|
249
|
+
else if (schema.minByteLength !== undefined) {
|
|
245
250
|
return new globalThis.Uint8Array(schema.minByteLength);
|
|
246
251
|
}
|
|
247
252
|
else {
|
package/value/errors.js
CHANGED
|
@@ -172,6 +172,12 @@ var ValueErrors;
|
|
|
172
172
|
if (!(typeof value === 'string')) {
|
|
173
173
|
return yield { schema, path, value, message: 'Expected string' };
|
|
174
174
|
}
|
|
175
|
+
if (schema.minLength !== undefined && !(value.length >= schema.minLength)) {
|
|
176
|
+
yield { schema, path, value, message: `Expected string length greater or equal to ${schema.minLength}` };
|
|
177
|
+
}
|
|
178
|
+
if (schema.maxLength !== undefined && !(value.length <= schema.maxLength)) {
|
|
179
|
+
yield { schema, path, value, message: `Expected string length less or equal to ${schema.maxLength}` };
|
|
180
|
+
}
|
|
175
181
|
if (schema.pattern !== undefined) {
|
|
176
182
|
const regex = new RegExp(schema.pattern);
|
|
177
183
|
if (!regex.test(value)) {
|