Skip to content

Commit

Permalink
Merge pull request #8 from FieldVal/develop
Browse files Browse the repository at this point in the history
Integrated DateVal and updated error numbers
  • Loading branch information
MarcusLongmuir committed Jan 24, 2015
2 parents 090ae1a + b4b5a2c commit 5a0a4c2
Show file tree
Hide file tree
Showing 76 changed files with 1,703 additions and 4,440 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ results

npm-debug.log
node_modules
bower_components
bower_components
coverage
88 changes: 3 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,12 @@
FieldVal-JS
========

The FieldVal-JS library allows you to easily validate objects and provide readable and structured error reports.
The FieldVal-JS library allows you to easily validate data and provide readable and structured error reports.

```javascript
//Import FieldVal and FieldVal-BasicVal (some simple checks)
var FieldVal = require('fieldval');
var bval = require('fieldval-basicval');

//Have some data to validate
var data = {
my_integer: "clearly not an integer"
}

//Create a FieldVal instance using the data
var validator = new FieldVal(data);

//Get values using validator.get(field_name, field_type, required)
var my_integer = validator.get("my_integer", bval.integer(true));

//Log the result of the validation (null if no errors)
console.log(validator.end());
```

Output:
```json
{
"invalid": {
"my_integer": {
"error_message": "Incorrect field type. Expected integer.",
"error": 2,
"expected": "integer",
"received": "string"
}
},
"error_message": "One or more errors.",
"error": 0
}

```


Chaining
========
```javascript
validator.get("my_integer", bval.integer(true))
```

checks that the value is an integer and indicates that it is required (```true```).

```javascript
validator.get("my_integer", bval.integer(true), bval.minimum(42))
```

now also checks that the integer is at least ```42```. You can add as many checks as you like from [here](https://github.com/FieldVal/fieldval-basicval-js/), or just write your own - they're just functions that return errors.

FieldVal Modules
============
* FieldVal-JS (This repository)

The core of FieldVal - provides basic validation functionality such as getting keys from an object and allows chaining of checks.

* [FieldVal-BasicVal-JS](https://github.com/FieldVal/fieldval-basicval-js/)

Basic checks and errors for required fields, type checking, length and numeric rules.

* FieldVal-UI

A companion library that creates customizable forms that parse and display FieldVal error structures.


NodeJS Usage
Documentation and Examples
=============
To install the node packages, run:
```bash
npm install fieldval
npm install fieldval-basicval
```

Bower Usage
=============
The FieldVal library works both as a node package and via the browser. To install the node packages, run:
```bash
bower install fieldval
bower install fieldval-basicval
```

How to use in the browser
=============
To use in the browser, download and include the ```fieldval.js``` file from this repository and ```fieldval-basicval.js``` from [https://github.com/FieldVal/fieldval-basicval-js/](https://github.com/FieldVal/fieldval-basicval-js/).
Documentation and examples can be found at [http://fieldval.com](http://fieldval.com)

Development
=============
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fieldval",
"version": "0.2.1",
"version": "0.3.0",
"main": "fieldval.js",
"ignore": [
"coverage",
Expand Down
2 changes: 0 additions & 2 deletions coverage/coverage-final.json

This file was deleted.

0 comments on commit 5a0a4c2

Please sign in to comment.