<commit_before># OMValidation [![Supported Platforms](https://cocoapod-badges.herokuapp.com/p/OMValidation/badge.svg)](http://cocoadocs.org/docsets/OMValidation) [![Version](https://cocoapod-badges.herokuapp.com/v/OMValidation/badge.svg)](http://cocoadocs.org/docsets/OMPromises) [![Build Status](https://travis-ci.org/b52/OMValidation.png?branch=master)](https://travis-ci.org/b52/OMValidation)

A simple framework for data validation that tries to be as concise as possible while providing
maximum security and flexibility. The goal is to use **specifying validation methods** in a
**chaining fashion** to write the validation code as intuative as possible while being easy
to skim and maintain.

For example, consider the common use case to retrieve JSON data from an external REST API.
This involves (1) the retrieval of the JSON data, (2) validation of the de-serialized
structure and (3) mapping into a domain specific [data transfer object] for safe
usage in your business logic. The following snippet demonstrates the usage of this
library, in combination with [OMPromises], to achieve the above described.


```objc
// our DTO describing a post
@interface Post : NSObject

@property(nonatomic) NSUInteger id;
@property(nonatomic) NSUInteger userId;
@property(nonatomic) NSString *title;
@property(nonatomic) NSString *boby;

// validates and maps the data into our DTO
+ (instancetype)fromDictionary:(id)data {
    Post *post = [Post new];
    
    post.id = [[data v_has:@"id"] v_isInteger];
    post.userId = [[data v_has:@"userId"] v_isInteger];
    post.title = [[data v_has:@"title"] v_isText];
    post.body = [[data v_has:@"body"] v_isText];
    
    return post;
}

// performs the HTTP GET request and applies our mapping
+ (OMPromise<NSArray<Post *> *> *)loadAllPosts {
    return [[[OMHTTPRequest get:@"http://jsonplaceholder.typicode.com/posts"
                   parameters:nil
                      options:nil]
            httpParseJson]
            then:^(id data) {
                return OMValidationTask(^{
                    NSMutableArray *posts = [NSMutableArray new];
                    
                    for (id postData in [data v_isIterable]) {
                        [posts addObject:[Post fromDictionary:[postData v_isDictionary]]];
                    }
                    
                    return posts;
                });
            }];
}

@end
```

## Features

- [x] Fully tested and documented
- [x] Concise syntax with awesome auto-completion integration
- [x] Uses static compilation support as much as possible
- [ ] Might introduce a memory leak, see [caveats](#caveats) for more information when this
      applies and how to prevent it
<commit_msg>Add explanatory comment to README<commit_after># OMValidation [![Supported Platforms](https://cocoapod-badges.herokuapp.com/p/OMValidation/badge.svg)](http://cocoadocs.org/docsets/OMValidation) [![Version](https://cocoapod-badges.herokuapp.com/v/OMValidation/badge.svg)](http://cocoadocs.org/docsets/OMPromises) [![Build Status](https://travis-ci.org/b52/OMValidation.png?branch=master)](https://travis-ci.org/b52/OMValidation)

A simple framework for data validation that tries to be as concise as possible while providing
maximum security and flexibility. The goal is to use **specifying validation methods** in a
**chaining fashion** to write the validation code as intuative as possible while being easy
to skim and maintain.

For example, consider the common use case to retrieve JSON data from an external REST API.
This involves (1) the retrieval of the JSON data, (2) validation of the de-serialized
structure and (3) mapping into a domain specific [data transfer object] for safe
usage in your business logic. The following snippet demonstrates the usage of this
library, in combination with [OMPromises], to achieve the above described.


```objc
// our DTO describing a post
@interface Post : NSObject

@property(nonatomic) NSUInteger id;
@property(nonatomic) NSUInteger userId;
@property(nonatomic) NSString *title;
@property(nonatomic) NSString *boby;

// validates and maps the data into our DTO
+ (instancetype)fromDictionary:(id)data {
    Post *post = [Post new];
    
    post.id = [[data v_has:@"id"] v_isInteger];
    post.userId = [[data v_has:@"userId"] v_isInteger];
    post.title = [[data v_has:@"title"] v_isText];
    post.body = [[data v_has:@"body"] v_isText];
    
    return post;
}

// performs the HTTP GET request and applies our mapping
+ (OMPromise<NSArray<Post *> *> *)loadAllPosts {
    return [[[OMHTTPRequest get:@"http://jsonplaceholder.typicode.com/posts"
                   parameters:nil
                      options:nil]
            httpParseJson]
            then:^(id data) {
                // the actual validation runs in a background thread; if an exception
                // is raised, it is converted into an NSError* for you to handle, e.g.,
                // ping a reporting system if this shouldn't happen
                return OMValidationTask(^{
                    NSMutableArray *posts = [NSMutableArray new];
                    
                    for (id postData in [data v_isIterable]) {
                        [posts addObject:[Post fromDictionary:[postData v_isDictionary]]];
                    }
                    
                    return posts;
                });
            }];
}

@end
```

## Features

- [x] Fully tested and documented
- [x] Concise syntax with awesome auto-completion integration
- [x] Uses static compilation support as much as possible
- [ ] Might introduce a memory leak, see [caveats](#caveats) for more information when this
      applies and how to prevent it

{'fraction_non_alphanumeric': 0.10246478873239437, 'fraction_numerical': 0.0024647887323943664, 'mean_word_length': 3.023371104815864, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, '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': '6041657', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1524, 'n_words': 538}