# rta-validator

> A light-weight arguments validator

Latest version **1.0.0** (published 2018-04-30) · ISC license · 0 weekly downloads

## Install

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

## 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 | 2018-04-30 |
| First published | 2018-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bnaya Zilberfarb |
| Maintainers | bnayazil |
| Keywords | arguments, validator |

## Links

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

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10

## 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) — 2018-04-30

## README

# Run Time Arguments Validator
A simple and light-weight arguments validator

## Install
Using NPM:
```
npm i --save rta-validator
```

In Node.js:
```
const rtaValidator = require('rta-validator')
```

## API
`rtaValidator` accept two arguments:
- `tasks` - Array of tasks to validate.
- `errorHandler` - Callback method to handle cases of error (optional).

`task` expect three properties:
- `name` - Arguments name, use for informative errors.
- `type` - The expected types (support in multiple types) for argument, type property accept three cases: type name as string, array of types name, type shortcuts as string.
- `val` - The argument we validate.

## Supported Types
| Type name 	| Type shortcuts name 	| Description                          	|
|-----------	|---------------------	|--------------------------------------	|
| object    	| o                   	| typeof object and not array or error 	|
| function  	| f                   	| typeof function                      	|
| string    	| s                   	| typeof string                        	|
| number    	| n                   	| typeof number                        	|
| array     	| a                   	| typeof array                         	|
| undefined 	| u                   	| typeof undefined                     	|
| boolean   	| b                   	| typeof boolean and not 1/0 (numbers) 	|
| error     	| e                   	| typeof error                         	|

## Examples
Multiple arguments
```
const rtaValidator = require('rta-validator')

rtaValidator([
    {name: 'foo', type: 'object', val: {foo: 'bar'}},
    {name: 'baz', type: 'o', val: {baz: 'bar'}},
    {name: 'baz', type: ['o', 'undefined'], val: undefined},
]) // void - all values pass validation
```

Failing validation
```
rtaValidator([
    {name: 'baz', type: ['o', 'undefined'], val: ['baz']},
]) // Throw exception
```

Custom error handler
```
rtaValidator([
    {name: 'baz', type: ['o', 'undefined'], val: ['baz']},
], (err) => err) // return error
```

Custom validator
```
rtaValidator([
    {name: 'baz', type: (v) => v === 3, val: 3},
], (err) => err) // return error
```

## Test
Install dependencies via NPM:
```
npm i
```

Run test suites:
```
npm test
```

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