1.0.34 • Published 2 years ago

object-validatordb v1.0.34

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years 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

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.34

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago