# smn-validate

> Validate object properties in JavaScript

Latest version **1.0.0** (published 2017-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install smn-validate
pnpm add smn-validate
yarn add smn-validate
bun add smn-validate
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-06-02 |
| First published | 2017-06-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ítalo Andrade |
| Maintainers | smn-official |
| Keywords | smn, validate |

## Links

- npm: https://www.npmjs.com/package/smn-validate
- Repository: https://github.com/smn-official/smn-validate
- Homepage: https://github.com/smn-official/smn-validate#readme
- Issues: https://github.com/smn-official/smn-validate/issues
- npm.io page: https://npm.io/package/smn-validate

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-06-02

## README

[![SMN Logo](http://smn.com.br/content/img/logotipo/light-lying.svg)](http://smn.com.br/)

# smn-validate
Validate object properties in JavaScript.

(Works only with Node 7 or superior)
```js
/* On your controller */

let params = {
    nome: 'Natal 2017',
    data: '2017-12-25'
};

try {
    await scope.inserirFeriado(params);
} catch (error) {
    // Error handling
}
```

```js
/* On your scope */

let validate = require('smn-validate');

module.exports = {
    inserirFeriado
};

async function inserirFeriado(params) {
    let validation = {
        nome: {
            required: true,
            string: true,
            maxLength: 100
        },
        data: {
            required: true,
            date: true
        }
    };

    await validate(params, validation);
}
```

## Installation

```bash
$ npm install smn-validate
```
## How it works

* Validates each property of an object with specific settings.
* It can be nested.

## Parameters

You should put those properties on your validation settings:

### required: true
When it is required. (but NULL still a valid value)
e.g.:
```js
let validation = {
    id: {
        required: true
    }
}
```
### number: {type} [String]
When it should be a number. Types: integer, smallint, bigint.
e.g.:
```js
let validation = {
    idade: {
        number: 'smallint'
    }
}
```
### string: true
When it should be a string.
e.g.:
```js
let validation = {
    nome: {
        string: true
    }
}
```
### maxLength: {max} [Integer]
When the length of it should be limited.
e.g.:
```js
let validation = {
    email: {
        string: true,
        maxLength: 255
    }
}
```
### date: true
When it should be a date.
e.g.:
```js
let validation = {
    dataExpiracao: {
        date: true
    }
}
```
### boolean: true
When it should be boolean.
e.g.:
```js
let validation = {
    ativo: {
        boolean: true
    }
}
```
### validation: {nest array child} [Array]
When the property is an Array of objects that each item should be also validated.
e.g.:
```js
let validation = {
    usuarios: {
        validation: {
            nome: {
                required: true,
                string: true
            }
        }
    }
}
```
### validation: {nest object child} [Object]
When the property is an Object that should also be validated.
e.g.:
```js
let validation = {
    filho: {
        validation: {
            nome: {
                required: true,
                string: true
            }
        }
    }
}
```
### array: {validation setting} [Object]
When the property is an Array of values that each value should be also validated.
e.g.:
```js
// names = ['Leonardo', 'Donatello', 'Raphael', 'Michelangelo']

let validation = {
    names: {
        array: {
            string: true
        }
    }
}
```

## People

[List of all contributors](https://github.com/smn-official/smn-colorize/graphs/contributors)

## License

  [MIT](LICENSE)

---
_Source: https://npm.io/package/smn-validate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
