# ptz-validations

> Validate your js objects.

Latest version **3.0.1** (published 2017-06-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install ptz-validations
pnpm add ptz-validations
yarn add ptz-validations
bun add ptz-validations
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2017-06-29 |
| First published | 2017-04-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | github.com/angeloocana |
| Maintainers | alanmarcell, angeloocana |

## Links

- npm: https://www.npmjs.com/package/ptz-validations
- Repository: https://github.com/polutz/ptz-validations
- Homepage: https://github.com/polutz/ptz-validations#readme
- Issues: https://github.com/polutz/ptz-validations/issues
- npm.io page: https://npm.io/package/ptz-validations

## Dependencies (4)

- [ramda](https://npm.io/package/ramda.md) ^0.24.1
- [ptz-fp](https://npm.io/package/ptz-fp.md) ^1.0.1
- [ptz-log](https://npm.io/package/ptz-log.md) ^1.1.0
- [shortid](https://npm.io/package/shortid.md) ^2.2.8

## Recent versions

- 3.0.1 (latest) — 2017-06-29
- 3.0.0 — 2017-06-25
- 2.0.3 — 2017-06-20
- 2.0.2 — 2017-06-19
- 2.0.1 — 2017-06-06
- 2.0.0 — 2017-06-03
- 1.2.2 — 2017-04-29
- 1.2.1 — 2017-04-26
- 1.2.0 — 2017-04-25
- 1.1.0 — 2017-04-24
- 1.0.0 — 2017-04-24

## README

# ptz-validations

[![Build Status](https://travis-ci.org/polutz/ptz-validations.svg)](https://travis-ci.org/polutz/ptz-validations)
[![NPM](https://img.shields.io/npm/v/ptz-validations.svg)](https://www.npmjs.com/package/ptz-validations)
[![codecov.io](http://codecov.io/github/polutz/ptz-validations/coverage.svg)](http://codecov.io/github/polutz/ptz-validations)
[![Dependency Status](https://gemnasium.com/polutz/ptz-validations.svg)](https://gemnasium.com/polutz/ptz-validations)
[![bitHound Score](https://www.bithound.io/github/gotwarlost/istanbul/badges/score.svg)](https://www.bithound.io/github/polutz/ptz-validations)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)

## Translations
[pt-br](https://github.com/polutz/ptz-validations/blob/master/README.pt-br.md)
[en-us](https://github.com/polutz/ptz-validations/blob/master/README.md)

Validate your js objects.


## Use

### Install
```bash
    npm install --save ptz-validations
```

### How to use
Example test of how to create a function to validate user:
```typescript
    import * as assert from 'ptz-assert';
    import * as V from './index';

    describe('ptz-validations', () => {
        it('createUser example', () => {

            // Optional interface for Typescript projects
            interface IUser {
                id: string;
                userName: string;
                password: string;
                email: string;
                weight?: number;
                birthday?: Date;
            }

            const validateUser = V.validate<IUser>({
                id: [
                    V.generateId
                ],
                displayName: [
                    V.required,
                    V.isString,
                    V.min(2),
                    V.max(100)
                ],
                userName: [
                    V.required,
                    V.isString,
                    V.min(2),
                    V.max(40),
                    V.toLowerCase
                ],
                password: [
                    V.required,
                    V.isString,
                    V.min(6),
                    V.max(40)
                ],
                email: [
                    V.required,
                    V.isEmail
                ],
                weight: [
                    V.isNumber,
                    V.min(1),
                    V.max(1000)
                ],
                birthday: [
                    V.isDate,
                    V.min(new Date('1800-01-01')),
                    V.max(new Date())
                ]
            });

            const user = validateUser({
                userName: 'angeloocana',
                password: 'abcd',
                email: 'angeloocana@gmail.com',
                weight: 90,
                birthday: '1992-06-28'
            });

            const expectedUser = {
                id: 'hfk397d',
                userName: 'angeloocana',
                password: 'abcd',
                email: 'angeloocana@gmail.com',
                weight: 90,
                birthday: new Date('1992-06-28'),
                errors: [{
                    propName: 'displayName',
                    errorMsg: 'ERROR_REQUIRED'
                }, {
                    propName: 'password',
                    errorMsg: 'ERROR_MIN'
                }]
            };

            assert.ok(user.id, 'generate id');
            assert.equal(user.userName, expectedUser.userName, 'set userName');
            assert.equal(user.password, expectedUser.password, 'set password');
            assert.equal(user.email, expectedUser.email, 'set email');
            assert.equal(user.weight, expectedUser.weight, 'set weight');
            assert.equal(user.birthday.toString(), expectedUser.birthday.toString(), 'set birthday');
            assert.deepEqual(user.errors, expectedUser.errors, 'add errors');
        });
    });

```

## Contribute

### NPM Global packages
```bash
    npm install -g ts-node babel-cli
```

### Setup
```bash
    npm install   
```

### Test
```bash
    npm test
```

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