https://github.com/mrbrunelli/object-validator
A simple object validator for tiny schemas
https://github.com/mrbrunelli/object-validator
fields-validator javascript object-validator schema-validator validator
Last synced: 12 months ago
JSON representation
A simple object validator for tiny schemas
- Host: GitHub
- URL: https://github.com/mrbrunelli/object-validator
- Owner: mrbrunelli
- License: mit
- Created: 2022-02-04T21:14:29.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-18T21:01:03.000Z (over 3 years ago)
- Last Synced: 2025-04-12T23:44:47.151Z (12 months ago)
- Topics: fields-validator, javascript, object-validator, schema-validator, validator
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@mrbrunelli/object-validator
- Size: 153 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Object Validator
A Javascript object validator for tiny schemas.
[](https://nodei.co/npm/@mrbrunelli/object-validator/)

## Get started
```sh
yarn add @mrbrunelli/object-validator
```
#### How to use
```ts
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.
```js
// Work only Node 14 or >
if (objectExample?.foo?.bar?.message === 'Hello!') // anything...
```
Node 12 require massive validations.
```js
if (objectExample && objectExample.foo && objectExample.foo.bar && objectExample.foo.bar.example === 'Hello!') // anything...
```
In this case, using a validator is better and safe.
```js
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.