Giter Site home page Giter Site logo

mrbrunelli / object-validator Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 157 KB

A simple object validator for tiny schemas

Home Page: https://www.npmjs.com/package/@mrbrunelli/object-validator

License: MIT License

JavaScript 1.40% Shell 1.99% TypeScript 96.61%
javascript object-validator fields-validator schema-validator validator

object-validator's Introduction

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.

object-validator's People

Contributors

mrbrunelli avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.