1.0.34 • Published 1 year ago

object-validatordb v1.0.34

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

This library allows you to easily check if an object has the names of its keys and expected value types. github: https://github.com/DiegoBreeg/object-validator.git

$ npm i object-validatordb

Import or require the library to your code and instantiate

const  {ObjectValidator} = require('object-validatordb')
const validator = new ObjectValidator()
import { ObjectValidator } from "object-validatordb"
const validator = new ObjectValidator()

Validator has a method called validate() that takes two parameters. -dummy: which will receive the object to be validated. -rules: an object with the validation rules. If dummy follows the rules described in rules validator returns true, otherwise it returns false

ObjectValidator.validate(dummy: any, rule: any): boolean
const dummy = { name: 'Joe', lastName: 'doe', age: 27}
const rules = {name: String, lastName: String, age: Number}
validator.validate(dummy, rules) //true
const dummy = { name: 'Joe', lastName: 'doe'}
const rules = {name: String, lastName: String, age: Number}
validator.validate(dummy, rules) //false

Rules also accepts Arrays and Objects.

const dummy = {
    name: 'Joe',
    lastName: 'Doe',
    age: 27,
    hobbies: ['programing', 'read books', 'commit to github' ]
}

const rules = {
    name: String,
    lastName: String,
    age: Number,
    hobbies: []
}

validator.validate(dummy, rules) //true
1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.34

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago