2.0.8 • Published 2 years ago

@mrbrunelli/object-validator v2.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Object Validator

A Javascript object validator for tiny schemas.

NPM

Test

Get started

 yarn add @mrbrunelli/object-validator

How to use

import Validate from '@mrbrunelli/object-validator'

const objectExample = {
  foo: {
    bar: {
      message: 'Hello!'
    }
  }
}

const isValid = Validate.isValid(objectExample, [
  ['foo'],
  ['foo.bar.message', 'Hello!']
])
console.log(isValid) // returns true

Why

Validating multiple fields can be very tiring in old Node versions.

  // Work only Node 14 or >
  if (objectExample?.foo?.bar?.message === 'Hello!') // anything...

Node 12 require massive validations.

  if (objectExample && objectExample.foo && objectExample.foo.bar && objectExample.foo.bar.example === 'Hello!') // anything...

In this case, using a validator is better and safe.

  if (Validator.isValid(objectExample, [['foo.bar.example', 'Hello!']])) // anything...

Now imagine validating multiple fields and values ​​from a single object in a old version of Node. Very tiring and verbose.

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago