From 79ec42073bb3e08f568b12dd24306e95d8f676cf Mon Sep 17 00:00:00 2001 From: Ricardo Lopes Date: Mon, 18 Feb 2019 17:17:03 +0000 Subject: [PATCH] Release 4.0.0 --- CHANGELOG.md | 15 ++++++++ dist/asserts/big-number-assert.js | 17 ++++++++- dist/asserts/big-number-equal-to-assert.js | 35 +++++++++++++++---- .../asserts/big-number-greater-than-assert.js | 35 +++++++++++++++---- ...-number-greater-than-or-equal-to-assert.js | 35 +++++++++++++++---- dist/asserts/big-number-less-than-assert.js | 35 +++++++++++++++---- ...big-number-less-than-or-equal-to-assert.js | 35 +++++++++++++++---- dist/asserts/phone-assert.js | 2 +- dist/asserts/uk-modulus-checking-assert.js | 4 +-- dist/asserts/uri-assert.js | 2 +- dist/asserts/us-subdivision-assert.js | 6 ++-- package.json | 2 +- 12 files changed, 184 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd266e0..eac8bb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## [v4.0.0](https://github.com/uphold/validator.js-asserts/tree/v4.0.0) (2019-02-18) +[Full Changelog](https://github.com/uphold/validator.js-asserts/compare/v3.1.0...v4.0.0) + +**Implemented enhancements:** + +- Support bignumber.js@7+ and add optional `validateSignificantDigits` flag [\#174](https://github.com/uphold/validator.js-asserts/pull/174) ([ricardobcl](https://github.com/ricardobcl)) + +**Merged pull requests:** + +- Update google-libphonenumber [\#173](https://github.com/uphold/validator.js-asserts/pull/173) ([rplopes](https://github.com/rplopes)) +- Fix mixed content issue preventing page load [\#170](https://github.com/uphold/validator.js-asserts/pull/170) ([hitmanmcc](https://github.com/hitmanmcc)) +- Update ownership [\#169](https://github.com/uphold/validator.js-asserts/pull/169) ([ruimarinho](https://github.com/ruimarinho)) +- Update README to include new asserts [\#165](https://github.com/uphold/validator.js-asserts/pull/165) ([kurayama](https://github.com/kurayama)) + ## [v3.1.0](https://github.com/uphold/validator.js-asserts/tree/v3.1.0) (2016-10-20) [Full Changelog](https://github.com/uphold/validator.js-asserts/compare/v3.0.2...v3.1.0) @@ -188,3 +202,4 @@ - Expose min and max in `NullOrString` [\#2](https://github.com/uphold/validator.js-asserts/pull/2) ([fixe](https://github.com/fixe)) - Add `Email` assert [\#1](https://github.com/uphold/validator.js-asserts/pull/1) ([fixe](https://github.com/fixe)) + diff --git a/dist/asserts/big-number-assert.js b/dist/asserts/big-number-assert.js index caae49a..575303c 100644 --- a/dist/asserts/big-number-assert.js +++ b/dist/asserts/big-number-assert.js @@ -12,12 +12,19 @@ var _validator = require('validator.js'); */ function bigNumberAssert() { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$validateSignific = _ref.validateSignificantDigits; + + let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific; + /** * Optional peer dependencies. */ const BigNumber = require('bignumber.js'); + BigNumber.DEBUG = !!validateSignificantDigits; + /** * Class name. */ @@ -30,8 +37,16 @@ function bigNumberAssert() { this.validate = value => { try { - new BigNumber(value); // eslint-disable-line no-new + const number = new BigNumber(value); + + if (Number.isNaN(number.toNumber())) { + throw new Error(`[BigNumber Error] Not a number: ${value.toString()}`); + } } catch (e) { + if (e.message.startsWith('[BigNumber Error]')) { + throw new _validator.Violation(this, value, { message: e.message }); + } + throw new _validator.Violation(this, value); } diff --git a/dist/asserts/big-number-equal-to-assert.js b/dist/asserts/big-number-equal-to-assert.js index 62d9769..22c1497 100644 --- a/dist/asserts/big-number-equal-to-assert.js +++ b/dist/asserts/big-number-equal-to-assert.js @@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = bigNumberEqualToAssert; +var _bigNumberAssert = require('./big-number-assert'); + +var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert); + var _validator = require('validator.js'); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /** * Export `BigNumberEqualToAssert`. */ +/** + * Module dependencies. + */ + function bigNumberEqualToAssert(value) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$validateSignific = _ref.validateSignificantDigits; + + let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific; + /** * Optional peer dependencies. */ const BigNumber = require('bignumber.js'); + BigNumber.DEBUG = !!validateSignificantDigits; + + /** + * Extend `Assert` with `BigNumberAssert`. + */ + + const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default }); + /** * Class name. */ @@ -28,6 +51,8 @@ function bigNumberEqualToAssert(value) { throw new Error('A value is required.'); } + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value); + this.value = new BigNumber(value); /** @@ -35,16 +60,18 @@ function bigNumberEqualToAssert(value) { */ this.validate = value => { + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value); + try { const number = new BigNumber(value); - if (!number.equals(this.value)) { + if (!number.isEqualTo(this.value)) { throw new Error(); } } catch (e) { const context = { value: this.value.toString() }; - if (e.name === 'BigNumber Error') { + if (e.message.startsWith('[BigNumber Error]')) { context.message = e.message; } @@ -56,8 +83,4 @@ function bigNumberEqualToAssert(value) { return this; } -/** - * Module dependencies. - */ - module.exports = exports['default']; \ No newline at end of file diff --git a/dist/asserts/big-number-greater-than-assert.js b/dist/asserts/big-number-greater-than-assert.js index bef7d90..1e41fcf 100644 --- a/dist/asserts/big-number-greater-than-assert.js +++ b/dist/asserts/big-number-greater-than-assert.js @@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = bigNumberGreaterThanAssert; +var _bigNumberAssert = require('./big-number-assert'); + +var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert); + var _validator = require('validator.js'); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /** * Export `BigNumberGreaterThanAssert`. */ +/** + * Module dependencies. + */ + function bigNumberGreaterThanAssert(threshold) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$validateSignific = _ref.validateSignificantDigits; + + let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific; + /** * Optional peer dependencies. */ const BigNumber = require('bignumber.js'); + BigNumber.DEBUG = !!validateSignificantDigits; + + /** + * Extend `Assert` with `BigNumberAssert`. + */ + + const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default }); + /** * Class name. */ @@ -28,6 +51,8 @@ function bigNumberGreaterThanAssert(threshold) { throw new Error('A threshold value is required.'); } + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold); + this.threshold = new BigNumber(threshold); /** @@ -35,16 +60,18 @@ function bigNumberGreaterThanAssert(threshold) { */ this.validate = value => { + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value); + try { const number = new BigNumber(value); - if (!number.greaterThan(this.threshold)) { + if (!number.isGreaterThan(this.threshold)) { throw new Error(); } } catch (e) { const context = { threshold: this.threshold.toString() }; - if (e.name === 'BigNumber Error') { + if (e.message.startsWith('[BigNumber Error]')) { context.message = e.message; } @@ -56,8 +83,4 @@ function bigNumberGreaterThanAssert(threshold) { return this; } -/** - * Module dependencies. - */ - module.exports = exports['default']; \ No newline at end of file diff --git a/dist/asserts/big-number-greater-than-or-equal-to-assert.js b/dist/asserts/big-number-greater-than-or-equal-to-assert.js index 446090c..3ec8b8f 100644 --- a/dist/asserts/big-number-greater-than-or-equal-to-assert.js +++ b/dist/asserts/big-number-greater-than-or-equal-to-assert.js @@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = bigNumberGreaterThanOrEqualToAssert; +var _bigNumberAssert = require('./big-number-assert'); + +var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert); + var _validator = require('validator.js'); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /** * Export `BigNumberGreaterThanOrEqualToAssert`. */ +/** + * Module dependencies. + */ + function bigNumberGreaterThanOrEqualToAssert(threshold) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$validateSignific = _ref.validateSignificantDigits; + + let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific; + /** * Optional peer dependencies. */ const BigNumber = require('bignumber.js'); + BigNumber.DEBUG = !!validateSignificantDigits; + + /** + * Extend `Assert` with `BigNumberAssert`. + */ + + const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default }); + /** * Class name. */ @@ -28,6 +51,8 @@ function bigNumberGreaterThanOrEqualToAssert(threshold) { throw new Error('A threshold value is required.'); } + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold); + this.threshold = new BigNumber(threshold); /** @@ -35,16 +60,18 @@ function bigNumberGreaterThanOrEqualToAssert(threshold) { */ this.validate = value => { + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value); + try { const number = new BigNumber(value); - if (!number.greaterThanOrEqualTo(this.threshold)) { + if (!number.isGreaterThanOrEqualTo(this.threshold)) { throw new Error(); } } catch (e) { const context = { threshold: this.threshold.toString() }; - if (e.name === 'BigNumber Error') { + if (e.message.startsWith('[BigNumber Error]')) { context.message = e.message; } @@ -56,8 +83,4 @@ function bigNumberGreaterThanOrEqualToAssert(threshold) { return this; } -/** - * Module dependencies. - */ - module.exports = exports['default']; \ No newline at end of file diff --git a/dist/asserts/big-number-less-than-assert.js b/dist/asserts/big-number-less-than-assert.js index 8ec2235..ce80841 100644 --- a/dist/asserts/big-number-less-than-assert.js +++ b/dist/asserts/big-number-less-than-assert.js @@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = bigNumberLessThan; +var _bigNumberAssert = require('./big-number-assert'); + +var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert); + var _validator = require('validator.js'); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /** * Export `BigNumberLessThan`. */ +/** + * Module dependencies. + */ + function bigNumberLessThan(threshold) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$validateSignific = _ref.validateSignificantDigits; + + let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific; + /** * Optional peer dependencies. */ const BigNumber = require('bignumber.js'); + BigNumber.DEBUG = !!validateSignificantDigits; + + /** + * Extend `Assert` with `BigNumberAssert`. + */ + + const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default }); + /** * Class name. */ @@ -28,6 +51,8 @@ function bigNumberLessThan(threshold) { throw new Error('A threshold value is required.'); } + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold); + this.threshold = new BigNumber(threshold); /** @@ -35,16 +60,18 @@ function bigNumberLessThan(threshold) { */ this.validate = value => { + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value); + try { const number = new BigNumber(value); - if (!number.lessThan(this.threshold)) { + if (!number.isLessThan(this.threshold)) { throw new Error(); } } catch (e) { const context = { threshold: this.threshold.toString() }; - if (e.name === 'BigNumber Error') { + if (e.message.startsWith('[BigNumber Error]')) { context.message = e.message; } @@ -56,8 +83,4 @@ function bigNumberLessThan(threshold) { return this; } -/** - * Module dependencies. - */ - module.exports = exports['default']; \ No newline at end of file diff --git a/dist/asserts/big-number-less-than-or-equal-to-assert.js b/dist/asserts/big-number-less-than-or-equal-to-assert.js index 76af7cc..6848c4a 100644 --- a/dist/asserts/big-number-less-than-or-equal-to-assert.js +++ b/dist/asserts/big-number-less-than-or-equal-to-assert.js @@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", { }); exports.default = bigNumberLessThanOrEqualToAssert; +var _bigNumberAssert = require('./big-number-assert'); + +var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert); + var _validator = require('validator.js'); +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + /** * Export `BigNumberLessThanOrEqualToAssert`. */ +/** + * Module dependencies. + */ + function bigNumberLessThanOrEqualToAssert(threshold) { + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref$validateSignific = _ref.validateSignificantDigits; + + let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific; + /** * Optional peer dependencies. */ const BigNumber = require('bignumber.js'); + BigNumber.DEBUG = !!validateSignificantDigits; + + /** + * Extend `Assert` with `BigNumberAssert`. + */ + + const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default }); + /** * Class name. */ @@ -28,6 +51,8 @@ function bigNumberLessThanOrEqualToAssert(threshold) { throw new Error('A threshold value is required.'); } + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold); + this.threshold = new BigNumber(threshold); /** @@ -35,16 +60,18 @@ function bigNumberLessThanOrEqualToAssert(threshold) { */ this.validate = value => { + new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value); + try { const number = new BigNumber(value); - if (!number.lessThanOrEqualTo(this.threshold)) { + if (!number.isLessThanOrEqualTo(this.threshold)) { throw new Error(); } } catch (e) { const context = { threshold: this.threshold.toString() }; - if (e.name === 'BigNumber Error') { + if (e.message.startsWith('[BigNumber Error]')) { context.message = e.message; } @@ -56,8 +83,4 @@ function bigNumberLessThanOrEqualToAssert(threshold) { return this; } -/** - * Module dependencies. - */ - module.exports = exports['default']; \ No newline at end of file diff --git a/dist/asserts/phone-assert.js b/dist/asserts/phone-assert.js index 7ee6e09..630181a 100644 --- a/dist/asserts/phone-assert.js +++ b/dist/asserts/phone-assert.js @@ -62,7 +62,7 @@ function phoneAssert() { } if (this.countryCode && !phoneUtil.isValidNumberForRegion(phone, this.countryCode)) { - throw new Error(`Phone does not belong to country "${ this.countryCode }"`); + throw new Error(`Phone does not belong to country "${this.countryCode}"`); } } catch (e) { throw new _validator.Violation(this, value); diff --git a/dist/asserts/uk-modulus-checking-assert.js b/dist/asserts/uk-modulus-checking-assert.js index bfd795c..a56423e 100644 --- a/dist/asserts/uk-modulus-checking-assert.js +++ b/dist/asserts/uk-modulus-checking-assert.js @@ -33,8 +33,8 @@ function ukModulusCheckingAssert() { this.validate = function () { var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - let accountNumber = _ref.accountNumber; - let sortCode = _ref.sortCode; + let accountNumber = _ref.accountNumber, + sortCode = _ref.sortCode; if (typeof accountNumber !== 'string') { throw new _validator.Violation(_this, accountNumber, { accountNumber: _validator.Validator.errorCode.must_be_a_string }); diff --git a/dist/asserts/uri-assert.js b/dist/asserts/uri-assert.js index 26bb733..1af6822 100644 --- a/dist/asserts/uri-assert.js +++ b/dist/asserts/uri-assert.js @@ -42,7 +42,7 @@ function uriAssert(constraints) { (0, _lodash.forEach)(this.constraints, (constraint, key) => { if (!(0, _lodash.has)(URI.prototype, key)) { - throw new Error(`Invalid constraint "${ key }=${ constraint }"`); + throw new Error(`Invalid constraint "${key}=${constraint}"`); } }); diff --git a/dist/asserts/us-subdivision-assert.js b/dist/asserts/us-subdivision-assert.js index 674ea16..5dfbf83 100644 --- a/dist/asserts/us-subdivision-assert.js +++ b/dist/asserts/us-subdivision-assert.js @@ -30,9 +30,9 @@ const keys = Object.keys(subdivisions); */ function usSubdivisionAssert() { - var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$categories = _ref.categories; - var _ref$categories = _ref.categories; let categories = _ref$categories === undefined ? keys : _ref$categories; var _ref$alpha2Only = _ref.alpha2Only; let alpha2Only = _ref$alpha2Only === undefined ? false : _ref$alpha2Only; @@ -48,7 +48,7 @@ function usSubdivisionAssert() { */ if (categories && (0, _lodash.intersection)(keys, categories).length !== categories.length) { - throw new Error(`Unsupported categories "${ (0, _lodash.difference)(categories, keys) }" given`); + throw new Error(`Unsupported categories "${(0, _lodash.difference)(categories, keys)}" given`); } /** diff --git a/package.json b/package.json index 686ae8b..9397d01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "validator.js-asserts", - "version": "3.1.0", + "version": "4.0.0", "description": "A set of extra asserts for validator.js.", "license": "MIT", "contributors": [