# validator-it

> Just validate it, based on [validator](https://github.com/chriso/validator.js).

Latest version **2.1.0** (published 2017-10-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install validator-it
pnpm add validator-it
yarn add validator-it
bun add validator-it
```

## 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 | 2.1.0 |
| Published | 2017-10-11 |
| First published | 2015-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | nswbmw |
| Keywords | validate, validator, schema |

## Links

- npm: https://www.npmjs.com/package/validator-it
- Repository: https://github.com/nswbmw/validator-it
- Homepage: https://github.com/nswbmw/validator-it#readme
- Issues: https://github.com/nswbmw/validator-it/issues
- npm.io page: https://npm.io/package/validator-it

## Dependencies (3)

- [flat](https://npm.io/package/flat.md) ^4.0.0
- [validator](https://npm.io/package/validator.md) ^9.0.0
- [object-path](https://npm.io/package/object-path.md) ^0.11.4

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2017-10-11
- 2.0.0 — 2017-10-11
- 1.1.0 — 2015-11-13
- 1.0.1 — 2015-11-12
- 1.0.0 — 2015-11-12

## README

## validator-it

Just validate it, based on [validator](https://github.com/chriso/validator.js).

### Install

```
npm i validator-it
```

### Examples

```
var validatorIt = require('validator-it');

var validatePosts = validatorIt({
  author: {
    _id: validatorIt.isMongoId(),
    name: function checkName(name) { 
      if (['nswbmw', 'jack'].indexOf(name) === -1) {
        throw new Error('You are not admin.');
      }
    },
    email: validatorIt.isEmail()
  },
  content: validatorIt.isByteLength(10)
});

validatePosts({
  author: {
    _id: '5643263df301e3550988b3c8',
    name: 'nswbmw',
    email: 'foo@bar.com'
  },
  content: 'abcdefghijk'
});
// return true

validatePosts({
  author: {
    _id: 'abc',
    name: 'nswbmw',
    email: 'foo@bar.com'
  }
});
// return false

validatePosts({
  author: {
    _id: 'abc',
    name: 'nswbmw',
    email: 'foo@bar.com'
  }
}, true);
// throw
// [author._id: abc] ✖ isMongoId

validatePosts({
  author: {
    _id: '5643263df301e3550988b3c8',
    name: 'guest',
    email: 'foo@bar.com'
  }
});
// throw
// You are not admin.

validatorIt.isEmail()('foo@bar.com') // { key: 'isEmail', value: true }
validatorIt.contains('foo')('foo@bar.com') // { key: 'contains(foo)', value: true }

validatorIt.validator.isEmail('foo@bar.com') // true
validatorIt.validator.contains('foo@bar.com', 'foo') // true
```

More examples see [test](./test.js).

### License

MIT

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