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

vabu-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vabu-js

Easy JS validation using the builder pattern

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

image-removebg-preview (2)

npm version GitHub Workflow Status (event)

Description

VabuJS is a validation libray that allows you to build complex validations in an easy and clear way

First steps

Installation

Use your favourite package manager

npm install --save vabu-js

Basic example

import { ValidatorBuilder } from 'vabu-js'

const nameValidation = new ValidatorBuilder()
  .setValue('My awesome name')
  .notNull()
  .notEmpty()
  .validate()

  if (nameValidation.isValid()) {
    console.log(nameValidation.getErrorMessage())
  }

Object validation

import { ModelValidator, validators } from '../src/index'

        const obj = new ModelValidator()
          .setValue({
              name: 'M'
          })
          .setValidations({
            name: {
                validators.notNull,
                minLenght: validators.minLength(2)
            }
        })
          .validate()

Examples

Array validation

const arrayValidation = new ValidatorBuilder()
  .setValue([1, 2, 3])
  .isArray()
  .each((val) => val > 2)
  .validate()

  if (!arrayValidation.isValid()) {
    alert(arrayValidation.getErrorMessage())
  }

Custom validation

const userValidation = new ValidatorBuilder()
  .setValue({ name: 'Jonh', age: 21 })
  .notNull()
  .customValidation(user => user.age >= 18)
  .validate()

  if (!userValidation.isValid()) {
    alert(userValidation.getErrorMessage())
  }

Keywords

typescript

FAQs

Package last updated on 14 Apr 2022

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