validator
validator copied to clipboard
use of DEFINED_RULES on docs
I suggest to add DEFINED_RULES use on docs.
This is an example:
import { validate, setLocales, register, en, pt, DEFINED_RULES } from "robust-validator";
const isObjectRule = (value) => {
return value !== null && typeof value === 'object' && !Array.isArray(value);
};
if (!('object' in DEFINED_RULES)) {
register( // https://validator.axe-api.com/customization.html
'object', // The rule name
isObjectRule, // The rule functions
// Translations
{
en: "The field must be an object",
},
);
}
@tiagofrancafernandes thanks for the suggestion. ❤️ It's a very good idea.
But what do you think to provide a function that tells you if a rule is defined or not? An example;
import { register, isRegistered } from "robust-validator";
const isObjectRule = (value) => {
return value !== null && typeof value === "object" && !Array.isArray(value);
};
if (!isRegistered("object")) {
register("object", isObjectRule, {
en: "The field must be an object",
});
}
Also, I liked the object rule you defined. I think it would be a good idea to add that rule internally. What do you think? ☺️