mastercheck
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -7,2 +7,3 @@ /** | ||
*/ | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
@@ -15,2 +16,4 @@ | ||
this._idAttribute = '_id'; | ||
// key map. used to check `existIn`. | ||
this._keyMap = {}; | ||
} | ||
@@ -25,5 +28,6 @@ | ||
*/ | ||
MasterCheck.prototype.setup = function(formatData, idAttribute) { | ||
MasterCheck.prototype.setup = function(formatData, idAttribute, keyMap) { | ||
this._formatData = formatData || this._formatData; | ||
this._idAttribute = idAttribute || this._idAttribute; | ||
_.extend(this._keyMap, keyMap || {}); | ||
}; | ||
@@ -86,2 +90,3 @@ | ||
* select: [ 'apple_a1', 'apple_b2', 'apple_c3' ], // Select match check. Default do not check. | ||
* existIn: 'Item', // exist in keyMap check. Default do not check. | ||
* }; | ||
@@ -114,2 +119,5 @@ */ | ||
} | ||
if (_option.hasOwnProperty('existIn') && this._keyMap.hasOwnProperty(_option.existIn) && !~this._keyMap[_option.existIn].indexOf(data)) { | ||
return data + ' should be exist in ' + _option.existIn; | ||
} | ||
}; | ||
@@ -241,3 +249,5 @@ }, | ||
} | ||
return new Format(option, format); | ||
var f = new Format(option, format); | ||
f._keyMap = this._keyMap; | ||
return f; | ||
}; | ||
@@ -244,0 +254,0 @@ |
{ | ||
"name": "mastercheck", | ||
"version": "0.2.10", | ||
"description": "mastercheck", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha -r should -R spec --recursive test", | ||
"jshint": "jshint lib/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/yuhei-a/mastercheck.git" | ||
}, | ||
"keywords": [ | ||
"mastercheck", | ||
"master", | ||
"data", | ||
"check" | ||
], | ||
"author": "Yuhei Aihara", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/yuhei-a/mastercheck/issues" | ||
}, | ||
"dependencies": { | ||
"async": "~0.2.10" | ||
}, | ||
"devDependencies": { | ||
"should": "~3.1.3", | ||
"mocha": "~1.17.1", | ||
"jshint": "~2.4.4" | ||
} | ||
"name": "mastercheck", | ||
"version": "0.2.11", | ||
"description": "mastercheck", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha -r should -R spec --recursive test", | ||
"jshint": "jshint lib/*.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/yuhei-a/mastercheck.git" | ||
}, | ||
"keywords": [ | ||
"mastercheck", | ||
"master", | ||
"data", | ||
"check" | ||
], | ||
"author": "Yuhei Aihara", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/yuhei-a/mastercheck/issues" | ||
}, | ||
"dependencies": { | ||
"async": "~0.2.10", | ||
"lodash": "~2.4.1" | ||
}, | ||
"devDependencies": { | ||
"should": "~3.1.3", | ||
"mocha": "~1.17.1", | ||
"jshint": "~2.4.4" | ||
} | ||
} |
@@ -12,3 +12,3 @@ var should = require('should'); | ||
obj: { | ||
code: masterCheck.format('String', { minLength: 1, maxLength: 10 }), | ||
code: masterCheck.format('String', { minLength: 1, maxLength: 10, existIn: 'B' }), | ||
type: masterCheck.format('String', { select: [ 'Dog', 'Cat' ] }), | ||
@@ -34,3 +34,3 @@ bool: masterCheck.format('Boolean', function(parents) { | ||
}; | ||
masterCheck.setup(format); | ||
masterCheck.setup(format, '_id', { B: [ 'test1_1', 'test2_1' ] }); | ||
done(); | ||
@@ -243,2 +243,27 @@ }); | ||
}); | ||
it('Exist in keyMap check test.', function(done) { | ||
var dataList = [ | ||
{ | ||
_id: 'test1', | ||
obj: { | ||
code: 'test1_1' | ||
}, | ||
arr: [] | ||
}, | ||
{ | ||
_id: 'test2', | ||
obj: { | ||
code: 'test2_2' | ||
}, | ||
arr: [] | ||
} | ||
]; | ||
masterCheck.check('A', dataList, function(err, result) { | ||
should.not.exist(err); | ||
should.exist(result); | ||
result.should.eql({ test2: [ { key: 'obj.code', value: 'test2_2', message: 'test2_2 should be exist in B' } ] }); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -245,0 +270,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35692
672
2
+ Addedlodash@~2.4.1
+ Addedlodash@2.4.2(transitive)