Skip to content

Commit

Permalink
Release 4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Lopes committed Feb 18, 2019
1 parent d54d043 commit 79ec420
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 39 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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))

17 changes: 16 additions & 1 deletion dist/asserts/big-number-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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);
}

Expand Down
35 changes: 29 additions & 6 deletions dist/asserts/big-number-equal-to-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -28,23 +51,27 @@ function bigNumberEqualToAssert(value) {
throw new Error('A value is required.');
}

new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(value);

this.value = new BigNumber(value);

/**
* Validation algorithm.
*/

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;
}

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

return this;
}
/**
* Module dependencies.
*/

module.exports = exports['default'];
35 changes: 29 additions & 6 deletions dist/asserts/big-number-greater-than-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -28,23 +51,27 @@ function bigNumberGreaterThanAssert(threshold) {
throw new Error('A threshold value is required.');
}

new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold);

this.threshold = new BigNumber(threshold);

/**
* Validation algorithm.
*/

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;
}

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

return this;
}
/**
* Module dependencies.
*/

module.exports = exports['default'];
35 changes: 29 additions & 6 deletions dist/asserts/big-number-greater-than-or-equal-to-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -28,23 +51,27 @@ function bigNumberGreaterThanOrEqualToAssert(threshold) {
throw new Error('A threshold value is required.');
}

new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold);

this.threshold = new BigNumber(threshold);

/**
* Validation algorithm.
*/

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;
}

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

return this;
}
/**
* Module dependencies.
*/

module.exports = exports['default'];
35 changes: 29 additions & 6 deletions dist/asserts/big-number-less-than-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -28,23 +51,27 @@ function bigNumberLessThan(threshold) {
throw new Error('A threshold value is required.');
}

new Assert().BigNumber({ validateSignificantDigits: validateSignificantDigits }).validate(threshold);

this.threshold = new BigNumber(threshold);

/**
* Validation algorithm.
*/

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;
}

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

return this;
}
/**
* Module dependencies.
*/

module.exports = exports['default'];
Loading

0 comments on commit 79ec420

Please sign in to comment.