🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

field-validator

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

field-validator - npm Package Compare versions

Comparing version

to
0.1.2

10

lib/field-validator.js

@@ -122,2 +122,12 @@ var dataTypes = {

//Check uniq constraint
if (restriction.uniq) {
var uniqArr = item.filter(function(v, index) {
return item.indexOf(v) === index
});
if(item.length>uniqArr.length){
errors.push(errorGen(key,'has duplicate elements'));
}
}
}

@@ -124,0 +134,0 @@

3

package.json
{
"name": "field-validator",
"version": "0.0.2",
"version": "0.1.2",
"description": "config based validator for form like fields",

@@ -27,2 +27,3 @@ "main": "lib/field-validator",

"devDependencies": {
"chai": "^3.4.1",
"grunt": "^0.4.5",

@@ -29,0 +30,0 @@ "grunt-contrib-jshint": "^0.11.3",

@@ -49,13 +49,14 @@ # field-validator [![npm version](https://badge.fury.io/js/field-validator.svg)](http://badge.fury.io/js/field-validator)

|name|description|datatype|examples
|-----|----------|---------|-------
|required|set field to be required |boolean|true
|type|set field type|string|'string'
|maxLength|set max length of string or array|number|10
|minLength|set min length of string or array|number|1
|max|set max value of number|number|1001
|min|set min value of number|number|-38
|elementType|set element type of array|string|'string'
|name|description|datatype|examples|default
|-----|----------|---------|-------|-------
|required|set field to be required |boolean|true|false
|type|set field type|string|'string'|
|maxLength|set max length of string or array|number|10|
|minLength|set min length of string or array|number|1|
|max|set max value of number|number|1001|
|min|set min value of number|number|-38|
|elementType|set element type of array|string|'string'|
|uniqElement|allow an array has uniq constraint for elements|boolean|true|false
About field type and elementType, currently fv could support several primitive types:
Supported field types:
```

@@ -65,28 +66,25 @@ boolean

string
Array
```
For elementType, currently fv could support several primitive types:
```
boolean
number
string
```
fv thinks null,undefined should not be one of dataTypes. Symbol is not supported also.
* fv.newInstance(restrictions,options)
* fv.newInstance(restrictions,options)
Create fv instances(called fvObj in following introductions) by given restrictions and options
* fvObj.perform(data)
* fvObj.perform(data)
Perform validation on given data. The data should be a pure json object.And currently, it can only check data whose properties types are string,number,boolean and array.
* fv.getState
Return the state of the latest perform operation. eg, true means validation passed.
* fv.getState
Return the state of the latest perform operation. E.g. true means validation passed.
### Browser Unit test
### Contributing
Please feel free to send your changes.
#### Build
```
npm run-script build
```
#### Unit test
Open test/report/jasmine_report.html in your browser

@@ -93,0 +91,0 @@