Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
validate-fields-body
Advanced tools
Readme
This is a JavaScript function that validates a given form data object against a set of validation keys. The function returns an array with three elements:
npm i validate-fields-body
The first element is a boolean value that indicates whether there are any validation errors or not. The second element is an array of strings that contains the error messages for each validation failure, or null if there are no errors. The third element is an object that contains only the valid fields from the form data, or null if there are any errors. The function performs three types of validation:
Required fields: The validation keys that have a “!” prefix indicate that the corresponding field in the form data must be present and not empty. For example, “!name” means that the name field is required. Required types: The validation keys that have a “:” suffix indicate that the corresponding field in the form data must have a specific type. For example, “age:number” means that the age field must be a number. Matching keys: The validation keys that do not have any prefix or suffix indicate that the corresponding field in the form data must exist. For example, “email” means that the email field must be present. The function loops through each validation key and checks if it matches with the form data. If not, it adds an error message to the logs array and skips to the next key. If all keys are validated successfully, it returns false for errors and copies only the valid fields to the result object.
Here is an example of how to use this function:
const { useValidate } = require("validate-fields-body");
const register = (req, res) => {
// Set your fields to validate
const fieldsValidate = ["username", "email", "password", "age", "skills"];
const [InValid, logs, result] = useValidate(fieldsValidate, req.body);
if (InValid) return res.status(403).json({ success: false, message: logs });
return res.status(201).send({ success: true, data: result });
};
const fieldsValidate = ["!username", "!email", "!password", "!age", "skills"];
const fieldsValidate = [
"!username:string",
"!email:string",
"!password:string",
"!age:number",
"skills:object",
];
const fieldsValidate = ["password*3-15"];
const fieldsValidate = ["email@"];
Option | Keyword |
---|---|
! | Required Value |
:[TYPE] | Check Type |
@ | Validate Emai |
*[min-max] | Validate Length |
Thanks you!.
USDT Address
0x92072439f5cf2f35defa28a4915004971de543b0
Author by: Nero Sengtianthr.
FAQs
Validate-Fields-Body is a Javascript library for dealing with validation.
The npm package validate-fields-body receives a total of 9 weekly downloads. As such, validate-fields-body popularity was classified as not popular.
We found that validate-fields-body demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.