@@ -466,25 +466,29 @@ Amount.prototype.parse_human = function(j, opts) {
466
466
467
467
var words = j . split ( ' ' ) . filter ( function ( word ) { return word !== '' ; } ) ;
468
468
469
+ function isNumber ( s ) {
470
+ return isFinite ( s ) && s !== '' ;
471
+ }
472
+
469
473
if ( words . length === 1 ) {
470
- if ( isFinite ( words [ 0 ] ) ) {
474
+ if ( isNumber ( words [ 0 ] ) ) {
471
475
value = words [ 0 ] ;
472
476
currency = 'XRP' ;
473
477
} else {
474
478
value = words [ 0 ] . slice ( 0 , - 3 ) ;
475
479
currency = words [ 0 ] . slice ( - 3 ) ;
476
- if ( ! ( isFinite ( value ) && currency . match ( currency_RE ) ) ) {
480
+ if ( ! ( isNumber ( value ) && currency . match ( currency_RE ) ) ) {
477
481
return Amount . NaN ( ) ;
478
482
}
479
483
}
480
484
} else if ( words . length === 2 ) {
481
- if ( isFinite ( words [ 0 ] ) && words [ 1 ] . match ( hex_RE ) ) {
485
+ if ( isNumber ( words [ 0 ] ) && words [ 1 ] . match ( hex_RE ) ) {
482
486
value = words [ 0 ] ;
483
487
currency = words [ 1 ] ;
484
- } else if ( words [ 0 ] . match ( currency_RE ) && isFinite ( words [ 1 ] ) ) {
488
+ } else if ( words [ 0 ] . match ( currency_RE ) && isNumber ( words [ 1 ] ) ) {
485
489
value = words [ 1 ] ;
486
490
currency = words [ 0 ] ;
487
- } else if ( isFinite ( words [ 0 ] ) && words [ 1 ] . match ( currency_RE ) ) {
491
+ } else if ( isNumber ( words [ 0 ] ) && words [ 1 ] . match ( currency_RE ) ) {
488
492
value = words [ 0 ] ;
489
493
currency = words [ 1 ] ;
490
494
} else {
@@ -826,7 +830,7 @@ Amount.prototype.to_human = function(opts) {
826
830
opts = opts || { } ;
827
831
828
832
if ( ! this . is_valid ( ) ) {
829
- return '' ;
833
+ return 'NaN ' ;
830
834
}
831
835
832
836
// Default options
@@ -960,6 +964,9 @@ Amount.prototype.to_json = function() {
960
964
} ;
961
965
962
966
Amount . prototype . to_text_full = function ( opts ) {
967
+ if ( ! this . is_valid ( ) ) {
968
+ return 'NaN' ;
969
+ }
963
970
return this . _is_native
964
971
? this . to_human ( ) + '/XRP'
965
972
: this . to_text ( ) + '/' + this . _currency . to_json ( ) + '/' + this . _issuer . to_json ( opts ) ;
0 commit comments