New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

valideus

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

valideus

0 dependencies validation library

latest
Source
npmnpm
Version
0.0.4
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Valideus: Data Validation for JavaScript Projects

Valideus is a lightweight library that simplifies data validation in your JavaScript applications. It provides a user-friendly API for defining validation rules and ensuring your data adheres to those rules.

Installation

Install Valideus using npm:

npm install valideus

Usage

  • Import the Package:
import Valideus from 'valideus'; // Assuming ES Modules
  • Create a Validator Instance:
const validation = new Valideus() 
  • Define Validation Rules:
validation.addField(new FieldBuilder().setName("required_field").setRequired(true)) //Required field
validation.addField(new FieldBuilder().setName("minlim").setMinLength(5)) //Minimum length limit
validation.addField(new FieldBuilder().setName("maxlim").setMaxLength(5)) //Maximum length limit

//Or combined
validation.addField(
    new FieldBuilder()
        .setName("full_power")
        .setMaxLength(100))
        .setMinimuLength(10) 
        .setRequired(true)
  • Validate Your Data:
validation.validate({
    required_field: "Required field',
    minlim: '123', // <-- here is an error because min length is 5 
    //maxlim: empt    <-- no error here because its not required AND NOT INCLUDED.
    full_power: '' // <-- here is an error as well because its required but its empty 
})
  • Use the validation output
if(errors) return // Simple as that because if there are no errors it will return null

or you can print them:

errors.forEach(error => console.error(error.name.concat(":", error.error)))

Keywords

validation

FAQs

Package last updated on 12 Apr 2024

Did you know?

Socket

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.

Install

Related posts