# scheme-validator

> Simple lib for object validation by scheme

Latest version **0.0.4** (published 2016-04-25) · ISC license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2016-04-25 |
| First published | 2016-03-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Dmitri Boronin |
| Maintainers | ryzii74 |
| Keywords | validator, scheme, object scheme, object, scheme validation |

## Links

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

## Alternatives

- [@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
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.0.4 (latest) — 2016-04-25
- 0.0.3 — 2016-03-31
- 0.0.2 — 2016-03-31
- 0.0.1 — 2016-03-31

## README

# scheme-validator 
[![Build Status](https://travis-ci.org/Ryzii74/scheme-validator.svg?branch=master)](https://travis-ci.org/Ryzii74/scheme-validator) [![Code Climate](https://codeclimate.com/github/Ryzii74/scheme-validator/badges/gpa.svg)](https://codeclimate.com/github/Ryzii74/scheme-validator) [![Coverage Status](https://coveralls.io/repos/github/Ryzii74/scheme-validator/badge.svg?branch=master)](https://coveralls.io/github/Ryzii74/scheme-validator?branch=master)

Simple lib for object validation by scheme for node.js

## install

npm install scheme-validation

## usage

### Use scheme

```javascript
var schemeLib = require('scheme-validator');
var validationScheme = schemeLib(validators[method]);
var validationResult = validationScheme(<object scheme>).validate(data);
```

### Scheme validators

```javascript
var scheme = {
    name : {
        required : true, // requiredField,
        type : "string"  // type of string
    },
    age : {
        type : "number" // type of number
    },
    sex : {
        enum : [ "male", "female" ] //limited array of accepted values 
    },
    licenseAggrement : {
      value : true  // fixed value for parameter
    },
    version : {
        validator : (value) => { // custom function for user validation
          return !!value; 
        }
    },
    address : {
        structure : { // address field is an object with some structure, that recursively validated too
            city : {
                type : "string",
                required : true
            },
            street : {
                type : "string"
            },
            houseNumber : {
                type : "number"
            }
        }
    }
}
```

If field is not required and have no value in validated data - result will be successful!


### Validation result structure

```javascript
//successfull result
var validationResult = { success : true };

//unsuccessfull result
var validationResult = { 
    success : false,
    error : {
        key : "name", // field name from scheme with validation error,
                      // "address.city" if error in strucrute (inner object)
        text : "..."  // some error text
    }
};
```

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