3 ms·
This should be a Show HN. I read the code, and I do not think this library is suitable for real-world use. Consider `makeTestType` (https://github.com/imbrn/v
by partycoder 8y ago
This should be a Show HN.
I read the code, and I do not think this library is suitable for real-world use.
Consider `makeTestType` (https://github.com/imbrn/v8n/blob/master/src/v8n.js#L973-L981 https://github.com/imbrn/v8n/blob/master/src/v8n.js#L973-L98...):
return () => value => {
return (
typeof value === type ||
(value === null && type === "null") ||
(Array.isArray(value) && type === "array")
);
};
This means that null and "null" (as a string) are now numbers.
v8n().number().test("null") // true
It also means that an array of numbers is a number... something that is counterintuitive for the user of the library.
In addition to that, most of the time you want to deal with finite numbers. A validation library should have an API that reflects this, but this is not the case for v8n.
- twiss 8y agoNo, it doesn't mean that. You can try it out here: https://runkit.com/embed/ev53mh0z4nxt https://runkit.com/embed/ev53mh0z4nxt `makeTestType("null")()(null)` return true, but `makeTestType("number")()(null)` doesn't. The signature of `makeTestType` is `type: String => () => value: Any => Boolean`.