Specify type: Array, parse returns string value
J-F-Liu opened this issue · comments
Junfeng Liu commented
e.g.
schema({
correctOptions: {
type: Array,
minlength: 1,
},
});
Haz commented
Hi, @J-F-Liu. Array types are currently only supported in this form:
schema({
correctOptions: {
type: [String], // or other type
minlength: 1,
},
});
But it would be nice to support type: Array
. If you or someone else wants to work on that, you can start by updating these lines: https://github.com/diegohaz/schm/blob/master/packages/schm/src/parsers.js#L15-L27
Junfeng Liu commented
switch (option.name) {
case "RegExp":
return new RegExp(value, "i");
case "Date":
return new Date(/^\d{5,}$/.test(value) ? Number(value) : value);
case "Boolean":
return !(value === "false" || value === "0" || !value);
case "Number":
return Number(value);
case "Object":
return Object(value);
default:
return String(value);
^^^^^^^^^^^^^^^^^^^^
}
I think the default case should return the original value instead of convert to string.
Junfeng Liu commented
schema({
correctOptions: {
type: [String], // or other type
minlength: 1,
},
});
with this code, the minlength
validator is ignored.
Haz commented
Will open another issue for that problem.