<commit_before># Obey

Asynchronous Data Modelling and Validation.

[![CircleCI](https://img.shields.io/circleci/project/TechnologyAdvice/obey/master.svg)](https://circleci.com/gh/TechnologyAdvice/obey)
[![Code Climate](https://img.shields.io/codeclimate/github/TechnologyAdvice/obey.svg)](https://codeclimate.com/github/TechnologyAdvice/obey)
[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/TechnologyAdvice/obey.svg)](https://codeclimate.com/github/TechnologyAdvice/obey/coverage)
![Dependencies](https://img.shields.io/david/technologyadvice/obey.svg)
[![Known Vulnerabilities](https://snyk.io/test/npm/obey/badge.svg)](https://snyk.io/test/npm/obey)

## Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [API Documentaion](#api-documentation)
- [Rules](#rules)
- [Models](#models)
- [Validation](#validation)
  - [Validating Partials](#validating-partials)
  - [Validation Error Handling](#validation-error-handling)
- [Definition Properties](#definition-properties)
- [Types](#types)
  - [Adding New Types](#adding-new-types)
    - [Adding Single-Method Type](#adding-single-method-type)
    - [Adding Type with Subs](#adding-type-with-subs)
- [Allow](#allow)
- [Modifiers](#modifiers)
  - [Creating Modifiers](#creating-modifiers)
- [Creators](#creators)
  - [Creating Creators](#creating-creators)
- [Strict Mode](#strict-mode)
- [Asynchronous Validation](#asynchronous-validation)
- [Contributing](#contributing)
- [License](#license)

## Introduction

Obey is a library for creating asynchronous data models and rules. The core goal of the project is to provide methods for managing data models both through synchronous and asynchronous validation and alignment using [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).

## Installation

Obey can be installed via [NPM](https://www.npmjs.com/package/obey): `npm install obey --save`

## API Documentation

Detailed [API Documentation](API.md) is available for assistance in using, modifying, or [contibuting](#contributing) to the Obey library.

## Rules

> Rules are core definitions of how a value should be validated:

```javascript
import obey from 'obey'

const firstName = obey.rule({ type: 'string', min: 2, max: 45, required: true })
```

## Models

> Models allow for creating validation rules for entire object schemas. The following demonstrates a model being created with Obey:

```javascript
import obey from 'obey'

const userModel = obey.model({
  id: { type: 'uuid', creator: 'uuid', required: true },
  email: { type: 'email', required: true },
  password: { type: 'string', modifier: 'encryptPassword', required: true },
  fname: { type: 'string', description: 'First Name' },
  lname: { type: 'string', description: 'Last Name', empty: true },
  suffix: { type: 'string', allowNull: true },
  phone: { type: 'phone:numeric', min: 7, max: 10 },
  // Array
  labels: { type: 'array', values: {
    type: 'object', keys: {
      label: { type: 'string' }
    }
  }},
  // Nested object
  address: { type: 'object', keys: {
    street: { type: 'string', max: 45 },
    city:  { type: 'string', max: 45 },
    state: { type: 'string', max: 2, modifier: 'upperCase' },
    zip: { type: 'number', min: 10000, max: 99999 }
  }},
  // Key-independent object validation
  permissions: { type: 'object', values: {
    type: 'string'
  }},
  account: { type: 'string', allow: [ 'user', 'admin' ], default: 'user' }
})
```<commit_msg>doc(readme): adds phoneType prop to demo requireIf<commit_after># Obey

Asynchronous Data Modelling and Validation.

[![CircleCI](https://img.shields.io/circleci/project/TechnologyAdvice/obey/master.svg)](https://circleci.com/gh/TechnologyAdvice/obey)
[![Code Climate](https://img.shields.io/codeclimate/github/TechnologyAdvice/obey.svg)](https://codeclimate.com/github/TechnologyAdvice/obey)
[![Test Coverage](https://img.shields.io/codeclimate/coverage/github/TechnologyAdvice/obey.svg)](https://codeclimate.com/github/TechnologyAdvice/obey/coverage)
![Dependencies](https://img.shields.io/david/technologyadvice/obey.svg)
[![Known Vulnerabilities](https://snyk.io/test/npm/obey/badge.svg)](https://snyk.io/test/npm/obey)

## Contents

- [Introduction](#introduction)
- [Installation](#installation)
- [API Documentaion](#api-documentation)
- [Rules](#rules)
- [Models](#models)
- [Validation](#validation)
  - [Validating Partials](#validating-partials)
  - [Validation Error Handling](#validation-error-handling)
- [Definition Properties](#definition-properties)
- [Types](#types)
  - [Adding New Types](#adding-new-types)
    - [Adding Single-Method Type](#adding-single-method-type)
    - [Adding Type with Subs](#adding-type-with-subs)
- [Allow](#allow)
- [Modifiers](#modifiers)
  - [Creating Modifiers](#creating-modifiers)
- [Creators](#creators)
  - [Creating Creators](#creating-creators)
- [Strict Mode](#strict-mode)
- [Asynchronous Validation](#asynchronous-validation)
- [Contributing](#contributing)
- [License](#license)

## Introduction

Obey is a library for creating asynchronous data models and rules. The core goal of the project is to provide methods for managing data models both through synchronous and asynchronous validation and alignment using [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).

## Installation

Obey can be installed via [NPM](https://www.npmjs.com/package/obey): `npm install obey --save`

## API Documentation

Detailed [API Documentation](API.md) is available for assistance in using, modifying, or [contibuting](#contributing) to the Obey library.

## Rules

> Rules are core definitions of how a value should be validated:

```javascript
import obey from 'obey'

const firstName = obey.rule({ type: 'string', min: 2, max: 45, required: true })
```

## Models

> Models allow for creating validation rules for entire object schemas. The following demonstrates a model being created with Obey:

```javascript
import obey from 'obey'

const userModel = obey.model({
  id: { type: 'uuid', creator: 'uuid', required: true },
  email: { type: 'email', required: true },
  password: { type: 'string', modifier: 'encryptPassword', required: true },
  fname: { type: 'string', description: 'First Name' },
  lname: { type: 'string', description: 'Last Name', empty: true },
  suffix: { type: 'string', allowNull: true },
  phone: { type: 'phone:numeric', min: 7, max: 10 },
  phoneType: { type: 'string', requireIf: 'phone' },
  // Array
  labels: { type: 'array', values: {
    type: 'object', keys: {
      label: { type: 'string' }
    }
  }},
  // Nested object
  address: { type: 'object', keys: {
    street: { type: 'string', max: 45 },
    city:  { type: 'string', max: 45 },
    state: { type: 'string', max: 2, modifier: 'upperCase' },
    zip: { type: 'number', min: 10000, max: 99999 }
  }},
  // Key-independent object validation
  permissions: { type: 'object', values: {
    type: 'string'
  }},
  account: { type: 'string', allow: [ 'user', 'admin' ], default: 'user' }
})
```
{'fraction_non_alphanumeric': 0.16379553798362045, 'fraction_numerical': 0.005930528099406947, 'mean_word_length': 4.777324632952691, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 22, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '152672', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2198, 'n_words': 567}