mastercheck
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -148,2 +148,35 @@ /** | ||
/** | ||
* Generate the format of type ObjectArray | ||
* @param {Object} option | ||
* @param {Array} format | ||
* @example | ||
* var option = { | ||
* required: true, // Existence check. Default do not check. | ||
* minLength: 0, // Minimum length check. Default do not check. | ||
* maxLength: 20, // Maximum length check. Default do not check. | ||
* }; | ||
*/ | ||
Array: function(option, format) { | ||
option = option || {}; | ||
this.check = function(data) { | ||
if (!option.required && data === undefined) { | ||
return; | ||
} | ||
if (data === undefined) { | ||
return 'This field is required'; | ||
} | ||
if (!Array.isArray(data)) { | ||
return data + ' should be an Array'; | ||
} | ||
if (option.hasOwnProperty('minLength') && option.minLength > data.length) { | ||
return data + ' length should be above ' + option.minLength; | ||
} | ||
if (option.hasOwnProperty('maxLength') && option.maxLength < data.length) { | ||
return data + ' length should be below ' + option.maxLength; | ||
} | ||
}; | ||
this.format = format; | ||
}, | ||
/** | ||
* Generate the format of type ObjectMap | ||
@@ -222,3 +255,3 @@ * @param {Object} option | ||
} else if (typeof master[i] !== 'undefined') { | ||
errs.push({ key: i, value: JSON.stringify(master[i]), message: '' }); | ||
errs.push({ key: i, value: JSON.stringify(master[i]), message: 'Format Error.' }); | ||
} | ||
@@ -263,3 +296,3 @@ } | ||
} else if (typeof master[key] !== 'undefined') { | ||
errs.push({ key: key, value: JSON.stringify(master[key]), message: '' }); | ||
errs.push({ key: key, value: JSON.stringify(master[key]), message: 'Format Error.' }); | ||
} | ||
@@ -266,0 +299,0 @@ } |
{ | ||
"name": "mastercheck", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "mastercheck", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -12,3 +12,3 @@ MasterCheck | ||
## Usage | ||
### Quick Start | ||
### Example | ||
``` | ||
@@ -60,3 +60,3 @@ var mastercheck = require('mastercheck'); | ||
### Format Part Option | ||
### Example Format Part Option | ||
#### MasterCheck.Number | ||
@@ -104,2 +104,14 @@ ``` | ||
``` | ||
#### MasterCheck.Array | ||
``` | ||
// For a array of 0-20 have length. Includ { bool: Boolean, num: Number }. | ||
mastercheck.format('Array', { | ||
required: true // Existance check. Default do not check. | ||
minLength: 0, // Minimum length check. Default do not check. | ||
maxLength: 20, // Maximum length check. Default do not check. | ||
}, [ | ||
bool: new mastercheck.Boolean(), | ||
num: new mastercheck.Number() | ||
]); | ||
``` | ||
#### MasterCheck.Map | ||
@@ -106,0 +118,0 @@ ``` |
33150
619
129