validate-promise
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -69,3 +69,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}); | ||
exports.whitelist = exports.required = exports.lessthan = exports.int = exports.greaterthan = exports.equals = exports.blacklist = exports.before = exports.after = undefined; | ||
exports.whitelist = exports.required = exports.lessthan = exports.int = exports.greaterthan = exports.float = exports.equals = exports.blacklist = exports.before = exports.after = undefined; | ||
@@ -88,19 +88,23 @@ var _after = __webpack_require__(2); | ||
var _greaterthan = __webpack_require__(6); | ||
var _float = __webpack_require__(6); | ||
var _float2 = _interopRequireDefault(_float); | ||
var _greaterthan = __webpack_require__(7); | ||
var _greaterthan2 = _interopRequireDefault(_greaterthan); | ||
var _int = __webpack_require__(7); | ||
var _int = __webpack_require__(8); | ||
var _int2 = _interopRequireDefault(_int); | ||
var _lessthan = __webpack_require__(8); | ||
var _lessthan = __webpack_require__(9); | ||
var _lessthan2 = _interopRequireDefault(_lessthan); | ||
var _required = __webpack_require__(9); | ||
var _required = __webpack_require__(10); | ||
var _required2 = _interopRequireDefault(_required); | ||
var _whitelist = __webpack_require__(10); | ||
var _whitelist = __webpack_require__(11); | ||
@@ -169,4 +173,7 @@ var _whitelist2 = _interopRequireDefault(_whitelist); | ||
} | ||
ret[k].push(err.reason); | ||
if (ret[k].indexOf(err.reason) === -1) { | ||
ret[k].push(err.reason); | ||
} | ||
}); | ||
if (errors.length === 0) { | ||
@@ -185,2 +192,3 @@ resolve(true); | ||
exports.equals = _equals2.default; | ||
exports.float = _float2.default; | ||
exports.greaterthan = _greaterthan2.default; | ||
@@ -321,2 +329,43 @@ exports.int = _int2.default; | ||
/** | ||
* Check if a value can be coerced to an integer | ||
* @param {String} value To validate | ||
* @param {Object} row Form data | ||
* @param {Function} msg Error message function | ||
* @param {*} arg Validation arguement | ||
* @return {Promise} . | ||
*/ | ||
exports.default = function (value, row, msg, arg) { | ||
if (typeof arg === 'function') { | ||
arg = arg(value, row); | ||
} | ||
var float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/; | ||
if (arg !== null) { | ||
if (arg.min !== undefined && parseInt(value, 10) < parseInt(arg.min, 10)) { | ||
return Promise.reject(msg(value, row, arg)); | ||
} | ||
if (arg.max && parseInt(value, 10) > parseInt(arg.max, 10)) { | ||
return Promise.reject(msg(value, row, arg)); | ||
} | ||
} | ||
if (float.test(value)) { | ||
return Promise.resolve(); | ||
} | ||
return Promise.reject(msg(value, row, arg)); | ||
}; | ||
/***/ }, | ||
/* 7 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
@@ -349,3 +398,3 @@ | ||
/***/ }, | ||
/* 7 */ | ||
/* 8 */ | ||
/***/ function(module, exports) { | ||
@@ -391,3 +440,3 @@ | ||
/***/ }, | ||
/* 8 */ | ||
/* 9 */ | ||
/***/ function(module, exports) { | ||
@@ -420,8 +469,7 @@ | ||
} | ||
console.log('less than,', parseInt(value, 10), ' < ', parseInt(compare, 10)); | ||
if (parseInt(value, 10) < parseInt(compare, 10)) { | ||
console.log('----resolve'); | ||
return Promise.resolve(); | ||
} | ||
console.log('-----reject'); | ||
return Promise.reject(msg(value, row, arg)); | ||
@@ -431,3 +479,3 @@ }; | ||
/***/ }, | ||
/* 9 */ | ||
/* 10 */ | ||
/***/ function(module, exports) { | ||
@@ -459,3 +507,3 @@ | ||
/***/ }, | ||
/* 10 */ | ||
/* 11 */ | ||
/***/ function(module, exports) { | ||
@@ -462,0 +510,0 @@ |
{ | ||
"name": "validate-promise", | ||
"version": "2.0.4", | ||
"version": "2.0.5", | ||
"description": "Promised based validaation library", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -71,3 +71,3 @@ // @flow | ||
} | ||
if (ret[k].indexOf(err.reason) !== -1) { | ||
if (ret[k].indexOf(err.reason) === -1) { | ||
ret[k].push(err.reason); | ||
@@ -74,0 +74,0 @@ } |
@@ -53,2 +53,3 @@ import {expect} from 'chai'; | ||
it('fails the validation', () => { | ||
console.log('failed = ', failed); | ||
expect(failed).to.be.an('object'); | ||
@@ -55,0 +56,0 @@ expect(failed).to.have.key('age'); |
@@ -105,3 +105,3 @@ import {expect} from 'chai'; | ||
expect(failedMin.age).to.be.an('array'); | ||
expect(failedMin.age[0]).to.equal('7 not an float'); | ||
expect(failedMin.age[0]).to.equal('7 not a float'); | ||
}); | ||
@@ -108,0 +108,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
65078
1606