<commit_before># fn-validator
Extendable and Isomorphic functional schema validator for browser and Node.js

```
var v = require("fn-validator");

var schema = v.object({
   firstName : v.string,
   lastName : v.all([v.string, v.minLength(2), v.maxLength(30)]),
   gender : v.enum(["Male", "Female", "Other"]),
   age : v.number,
   birthDate : v.before(new Date("2000-01-01")),
   single : v.boolean
 })

v.validate(schema, {
   ...
});
```
<commit_msg>doc with example<commit_after># fn-validator
Extendable and Isomorphic functional schema validator for browser and Node.js

--------
# Install

`npm install fn-validator --save`

--------
# Use


```
var v = require("fn-validator");

var schema = v.object({
   firstName : v.string,
   lastName : v.all([v.string, v.minLength(2), v.maxLength(30)]),
   gender : v.enum(["Male", "Female", "Other"]),
   age : v.number,
   height : v.between(160, 190),
   graduationDate : v.before(new Date("2000-01-01")),
   single : v.boolean,
   hasGirlfriend : v.optional(v.boolean)
 })

var isValid = v.validate(schema, objectToBeValidated);

if(!Object.isEmpty(result))
  //handle error
else
  // all good

```

-------

# Custom Validator


If there is an error, Return `String` value which is a error message

Return `true` or don't return anything at all if value is valid

### Define Validator

```

function customValidator(key, value, object) {
  var errorMessageString = "Value is not valid";
  if(value is not valid) {
    return errorMessageString;
  }
//  else
//    return true;
}

```

### Define schema

```

var schema = object({
  attribute: customValidator
})

```
### Validate

```
expect(v.validate(schema, objectToBeValidated)).toEqual({
  error_attribute : "Value is not valid"
})


```

{'fraction_non_alphanumeric': 0.16704805491990846, 'fraction_numerical': 0.016018306636155607, 'mean_word_length': 3.5428571428571427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '272066', 'n_tokens_mistral': 618, 'n_tokens_neox': 585, 'n_words': 157}