Skip to content

Commit 79ec420

Browse files
author
Ricardo Lopes
committed
Release 4.0.0
1 parent d54d043 commit 79ec420

12 files changed

+184
-39
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [v4.0.0](https://github.com/uphold/validator.js-asserts/tree/v4.0.0) (2019-02-18)
4+
[Full Changelog](https://github.com/uphold/validator.js-asserts/compare/v3.1.0...v4.0.0)
5+
6+
**Implemented enhancements:**
7+
8+
- Support bignumber.js@7+ and add optional `validateSignificantDigits` flag [\#174](https://github.com/uphold/validator.js-asserts/pull/174) ([ricardobcl](https://github.com/ricardobcl))
9+
10+
**Merged pull requests:**
11+
12+
- Update google-libphonenumber [\#173](https://github.com/uphold/validator.js-asserts/pull/173) ([rplopes](https://github.com/rplopes))
13+
- Fix mixed content issue preventing page load [\#170](https://github.com/uphold/validator.js-asserts/pull/170) ([hitmanmcc](https://github.com/hitmanmcc))
14+
- Update ownership [\#169](https://github.com/uphold/validator.js-asserts/pull/169) ([ruimarinho](https://github.com/ruimarinho))
15+
- Update README to include new asserts [\#165](https://github.com/uphold/validator.js-asserts/pull/165) ([kurayama](https://github.com/kurayama))
16+
317
## [v3.1.0](https://github.com/uphold/validator.js-asserts/tree/v3.1.0) (2016-10-20)
418
[Full Changelog](https://github.com/uphold/validator.js-asserts/compare/v3.0.2...v3.1.0)
519

@@ -188,3 +202,4 @@
188202

189203
- Expose min and max in `NullOrString` [\#2](https://github.com/uphold/validator.js-asserts/pull/2) ([fixe](https://github.com/fixe))
190204
- Add `Email` assert [\#1](https://github.com/uphold/validator.js-asserts/pull/1) ([fixe](https://github.com/fixe))
205+

dist/asserts/big-number-assert.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ var _validator = require('validator.js');
1212
*/
1313

1414
function bigNumberAssert() {
15+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
16+
_ref$validateSignific = _ref.validateSignificantDigits;
17+
18+
let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific;
19+
1520
/**
1621
* Optional peer dependencies.
1722
*/
1823

1924
const BigNumber = require('bignumber.js');
2025

26+
BigNumber.DEBUG = !!validateSignificantDigits;
27+
2128
/**
2229
* Class name.
2330
*/
@@ -30,8 +37,16 @@ function bigNumberAssert() {
3037

3138
this.validate = value => {
3239
try {
33-
new BigNumber(value); // eslint-disable-line no-new
40+
const number = new BigNumber(value);
41+
42+
if (Number.isNaN(number.toNumber())) {
43+
throw new Error(`[BigNumber Error] Not a number: ${value.toString()}`);
44+
}
3445
} catch (e) {
46+
if (e.message.startsWith('[BigNumber Error]')) {
47+
throw new _validator.Violation(this, value, { message: e.message });
48+
}
49+
3550
throw new _validator.Violation(this, value);
3651
}
3752

dist/asserts/big-number-equal-to-assert.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = bigNumberEqualToAssert;
77

8+
var _bigNumberAssert = require('./big-number-assert');
9+
10+
var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert);
11+
812
var _validator = require('validator.js');
913

14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
1016
/**
1117
* Export `BigNumberEqualToAssert`.
1218
*/
1319

20+
/**
21+
* Module dependencies.
22+
*/
23+
1424
function bigNumberEqualToAssert(value) {
25+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
26+
_ref$validateSignific = _ref.validateSignificantDigits;
27+
28+
let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific;
29+
1530
/**
1631
* Optional peer dependencies.
1732
*/
1833

1934
const BigNumber = require('bignumber.js');
2035

36+
BigNumber.DEBUG = !!validateSignificantDigits;
37+
38+
/**
39+
* Extend `Assert` with `BigNumberAssert`.
40+
*/
41+
42+
const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default });
43+
2144
/**
2245
* Class name.
2346
*/
@@ -28,23 +51,27 @@ function bigNumberEqualToAssert(value) {
2851
throw new Error('A value is required.');
2952
}
3053

54+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value);
55+
3156
this.value = new BigNumber(value);
3257

3358
/**
3459
* Validation algorithm.
3560
*/
3661

3762
this.validate = value => {
63+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value);
64+
3865
try {
3966
const number = new BigNumber(value);
4067

41-
if (!number.equals(this.value)) {
68+
if (!number.isEqualTo(this.value)) {
4269
throw new Error();
4370
}
4471
} catch (e) {
4572
const context = { value: this.value.toString() };
4673

47-
if (e.name === 'BigNumber Error') {
74+
if (e.message.startsWith('[BigNumber Error]')) {
4875
context.message = e.message;
4976
}
5077

@@ -56,8 +83,4 @@ function bigNumberEqualToAssert(value) {
5683

5784
return this;
5885
}
59-
/**
60-
* Module dependencies.
61-
*/
62-
6386
module.exports = exports['default'];

dist/asserts/big-number-greater-than-assert.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = bigNumberGreaterThanAssert;
77

8+
var _bigNumberAssert = require('./big-number-assert');
9+
10+
var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert);
11+
812
var _validator = require('validator.js');
913

14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
1016
/**
1117
* Export `BigNumberGreaterThanAssert`.
1218
*/
1319

20+
/**
21+
* Module dependencies.
22+
*/
23+
1424
function bigNumberGreaterThanAssert(threshold) {
25+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
26+
_ref$validateSignific = _ref.validateSignificantDigits;
27+
28+
let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific;
29+
1530
/**
1631
* Optional peer dependencies.
1732
*/
1833

1934
const BigNumber = require('bignumber.js');
2035

36+
BigNumber.DEBUG = !!validateSignificantDigits;
37+
38+
/**
39+
* Extend `Assert` with `BigNumberAssert`.
40+
*/
41+
42+
const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default });
43+
2144
/**
2245
* Class name.
2346
*/
@@ -28,23 +51,27 @@ function bigNumberGreaterThanAssert(threshold) {
2851
throw new Error('A threshold value is required.');
2952
}
3053

54+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold);
55+
3156
this.threshold = new BigNumber(threshold);
3257

3358
/**
3459
* Validation algorithm.
3560
*/
3661

3762
this.validate = value => {
63+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value);
64+
3865
try {
3966
const number = new BigNumber(value);
4067

41-
if (!number.greaterThan(this.threshold)) {
68+
if (!number.isGreaterThan(this.threshold)) {
4269
throw new Error();
4370
}
4471
} catch (e) {
4572
const context = { threshold: this.threshold.toString() };
4673

47-
if (e.name === 'BigNumber Error') {
74+
if (e.message.startsWith('[BigNumber Error]')) {
4875
context.message = e.message;
4976
}
5077

@@ -56,8 +83,4 @@ function bigNumberGreaterThanAssert(threshold) {
5683

5784
return this;
5885
}
59-
/**
60-
* Module dependencies.
61-
*/
62-
6386
module.exports = exports['default'];

dist/asserts/big-number-greater-than-or-equal-to-assert.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = bigNumberGreaterThanOrEqualToAssert;
77

8+
var _bigNumberAssert = require('./big-number-assert');
9+
10+
var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert);
11+
812
var _validator = require('validator.js');
913

14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
1016
/**
1117
* Export `BigNumberGreaterThanOrEqualToAssert`.
1218
*/
1319

20+
/**
21+
* Module dependencies.
22+
*/
23+
1424
function bigNumberGreaterThanOrEqualToAssert(threshold) {
25+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
26+
_ref$validateSignific = _ref.validateSignificantDigits;
27+
28+
let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific;
29+
1530
/**
1631
* Optional peer dependencies.
1732
*/
1833

1934
const BigNumber = require('bignumber.js');
2035

36+
BigNumber.DEBUG = !!validateSignificantDigits;
37+
38+
/**
39+
* Extend `Assert` with `BigNumberAssert`.
40+
*/
41+
42+
const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default });
43+
2144
/**
2245
* Class name.
2346
*/
@@ -28,23 +51,27 @@ function bigNumberGreaterThanOrEqualToAssert(threshold) {
2851
throw new Error('A threshold value is required.');
2952
}
3053

54+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold);
55+
3156
this.threshold = new BigNumber(threshold);
3257

3358
/**
3459
* Validation algorithm.
3560
*/
3661

3762
this.validate = value => {
63+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value);
64+
3865
try {
3966
const number = new BigNumber(value);
4067

41-
if (!number.greaterThanOrEqualTo(this.threshold)) {
68+
if (!number.isGreaterThanOrEqualTo(this.threshold)) {
4269
throw new Error();
4370
}
4471
} catch (e) {
4572
const context = { threshold: this.threshold.toString() };
4673

47-
if (e.name === 'BigNumber Error') {
74+
if (e.message.startsWith('[BigNumber Error]')) {
4875
context.message = e.message;
4976
}
5077

@@ -56,8 +83,4 @@ function bigNumberGreaterThanOrEqualToAssert(threshold) {
5683

5784
return this;
5885
}
59-
/**
60-
* Module dependencies.
61-
*/
62-
6386
module.exports = exports['default'];

dist/asserts/big-number-less-than-assert.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,42 @@ Object.defineProperty(exports, "__esModule", {
55
});
66
exports.default = bigNumberLessThan;
77

8+
var _bigNumberAssert = require('./big-number-assert');
9+
10+
var _bigNumberAssert2 = _interopRequireDefault(_bigNumberAssert);
11+
812
var _validator = require('validator.js');
913

14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
1016
/**
1117
* Export `BigNumberLessThan`.
1218
*/
1319

20+
/**
21+
* Module dependencies.
22+
*/
23+
1424
function bigNumberLessThan(threshold) {
25+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
26+
_ref$validateSignific = _ref.validateSignificantDigits;
27+
28+
let validateSignificantDigits = _ref$validateSignific === undefined ? true : _ref$validateSignific;
29+
1530
/**
1631
* Optional peer dependencies.
1732
*/
1833

1934
const BigNumber = require('bignumber.js');
2035

36+
BigNumber.DEBUG = !!validateSignificantDigits;
37+
38+
/**
39+
* Extend `Assert` with `BigNumberAssert`.
40+
*/
41+
42+
const Assert = _validator.Assert.extend({ BigNumber: _bigNumberAssert2.default });
43+
2144
/**
2245
* Class name.
2346
*/
@@ -28,23 +51,27 @@ function bigNumberLessThan(threshold) {
2851
throw new Error('A threshold value is required.');
2952
}
3053

54+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold);
55+
3156
this.threshold = new BigNumber(threshold);
3257

3358
/**
3459
* Validation algorithm.
3560
*/
3661

3762
this.validate = value => {
63+
new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value);
64+
3865
try {
3966
const number = new BigNumber(value);
4067

41-
if (!number.lessThan(this.threshold)) {
68+
if (!number.isLessThan(this.threshold)) {
4269
throw new Error();
4370
}
4471
} catch (e) {
4572
const context = { threshold: this.threshold.toString() };
4673

47-
if (e.name === 'BigNumber Error') {
74+
if (e.message.startsWith('[BigNumber Error]')) {
4875
context.message = e.message;
4976
}
5077

@@ -56,8 +83,4 @@ function bigNumberLessThan(threshold) {
5683

5784
return this;
5885
}
59-
/**
60-
* Module dependencies.
61-
*/
62-
6386
module.exports = exports['default'];

0 commit comments

Comments
 (0)