Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use of DEFINED_RULES on docs #60

Closed
tiagofrancafernandes opened this issue Oct 10, 2024 · 1 comment
Closed

use of DEFINED_RULES on docs #60

tiagofrancafernandes opened this issue Oct 10, 2024 · 1 comment
Assignees
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@tiagofrancafernandes
Copy link

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",
        },
    );
}
@ozziest
Copy link
Member

ozziest commented Oct 11, 2024

@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? ☺️

@ozziest ozziest self-assigned this Oct 11, 2024
@ozziest ozziest added documentation Improvements or additions to documentation enhancement New feature or request labels Oct 11, 2024
ozziest added a commit that referenced this issue Oct 19, 2024
@ozziest ozziest mentioned this issue Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants