33 * Module dependencies.
44 */
55
6- import { Violation } from 'validator.js' ;
6+ import BigNumberAssert from './big-number-assert' ;
7+ import { Assert as BaseAssert , Violation } from 'validator.js' ;
78
89/**
910 * Export `BigNumberGreaterThanOrEqualToAssert`.
1011 */
1112
12- export default function bigNumberGreaterThanOrEqualToAssert ( threshold ) {
13+ export default function bigNumberGreaterThanOrEqualToAssert ( threshold , { validateSignificantDigits = true } = { } ) {
1314 /**
1415 * Optional peer dependencies.
1516 */
1617
1718 const BigNumber = require ( 'bignumber.js' ) ;
1819
20+ BigNumber . DEBUG = ! ! validateSignificantDigits ;
21+
22+ /**
23+ * Extend `Assert` with `BigNumberAssert`.
24+ */
25+
26+ const Assert = BaseAssert . extend ( { BigNumber : BigNumberAssert } ) ;
27+
1928 /**
2029 * Class name.
2130 */
@@ -26,23 +35,27 @@ export default function bigNumberGreaterThanOrEqualToAssert(threshold) {
2635 throw new Error ( 'A threshold value is required.' ) ;
2736 }
2837
38+ new Assert ( ) . BigNumber ( { validateSignificantDigits } ) . validate ( threshold ) ;
39+
2940 this . threshold = new BigNumber ( threshold ) ;
3041
3142 /**
3243 * Validation algorithm.
3344 */
3445
3546 this . validate = value => {
47+ new Assert ( ) . BigNumber ( { validateSignificantDigits } ) . validate ( value ) ;
48+
3649 try {
3750 const number = new BigNumber ( value ) ;
3851
39- if ( ! number . greaterThanOrEqualTo ( this . threshold ) ) {
52+ if ( ! number . isGreaterThanOrEqualTo ( this . threshold ) ) {
4053 throw new Error ( ) ;
4154 }
4255 } catch ( e ) {
4356 const context = { threshold : this . threshold . toString ( ) } ;
4457
45- if ( e . name === ' BigNumber Error' ) {
58+ if ( e . message . startsWith ( '[ BigNumber Error]' ) ) {
4659 context . message = e . message ;
4760 }
4861
0 commit comments