@@ -14,11 +14,14 @@ class LazyStream {
1414 tmp . operators = operators ;
1515 return tmp ;
1616 }
17+ private isInvalid ( x : number | string ) {
18+ return Number . isNaN ( + x ) || ! Number . isFinite ( + x ) ;
19+ }
1720 private createRound ( methodName : CalcMethod , precision : number = 0 ) {
1821 const func = < operatorFunc > Math [ methodName ] ;
19- return function ( number : number | string ) : number {
22+ return ( number : number | string ) : number => {
2023 // const _number = number.value()
21- if ( Number . isNaN ( + number ) || Number . isNaN ( + precision ) ) {
24+ if ( this . isInvalid ( number ) || this . isInvalid ( precision ) ) {
2225 return NaN ;
2326 }
2427 precision =
@@ -45,9 +48,9 @@ class LazyStream {
4548 }
4649
4750 add ( y : LazyCalc ) : LazyStream {
48- const operation = function ( x : number | string ) {
51+ const operation = ( x : number | string ) => {
4952 const _y = y . value ( ) ;
50- if ( Number . isNaN ( + x ) || Number . isNaN ( + _y ) ) {
53+ if ( this . isInvalid ( x ) || this . isInvalid ( _y ) ) {
5154 return NaN ;
5255 }
5356 return + x + + _y ;
@@ -57,8 +60,8 @@ class LazyStream {
5760
5861 subtract ( y : LazyCalc ) : LazyStream {
5962 const _y = y . value ( ) ;
60- const operation = function ( x : number | string ) {
61- if ( Number . isNaN ( + x ) || Number . isNaN ( + _y ) ) {
63+ const operation = ( x : number | string ) => {
64+ if ( this . isInvalid ( x ) || this . isInvalid ( _y ) ) {
6265 return NaN ;
6366 }
6467 return + x - + _y ;
@@ -67,8 +70,8 @@ class LazyStream {
6770 }
6871 multiply ( y : LazyCalc ) : LazyStream {
6972 const _y = y . value ( ) ;
70- const operation = function ( x : number | string ) {
71- if ( Number . isNaN ( + x ) || Number . isNaN ( + _y ) ) {
73+ const operation = ( x : number | string ) => {
74+ if ( this . isInvalid ( x ) || this . isInvalid ( _y ) ) {
7275 return NaN ;
7376 }
7477 return + x * + _y ;
@@ -77,8 +80,8 @@ class LazyStream {
7780 }
7881 divide ( y : LazyCalc ) : LazyStream {
7982 const _y = y . value ( ) ;
80- const operation = function ( x : number | string ) {
81- if ( Number . isNaN ( + x ) || Number . isNaN ( + _y ) ) {
83+ const operation = ( x : number | string ) => {
84+ if ( this . isInvalid ( x ) || this . isInvalid ( _y ) ) {
8285 return NaN ;
8386 }
8487 return + x / + _y ;
@@ -98,16 +101,16 @@ class LazyStream {
98101 const operation = this . createRound ( "floor" , precision ) ;
99102 return this . clone ( [ operation , ...this . operators ] ) ;
100103 }
101- do ( fn : operatorFunc ) : LazyStream {
104+ do ( fn : Function ) : LazyStream {
102105 const operation = function ( y : number | string ) {
103106 return fn ( y ) ;
104107 } ;
105108 // this.operators.unshift(operation);
106109 return this . clone ( [ operation , ...this . operators ] ) ;
107110 }
108111 default ( fallback : any ) : LazyStream {
109- const operation = function ( x : number | string ) {
110- return Number . isNaN ( + x ) ? fallback : + x ;
112+ const operation = ( x : number | string ) => {
113+ return this . isInvalid ( x ) ? fallback : + x ;
111114 } ;
112115 return this . clone ( [ operation , ...this . operators ] ) ;
113116 }
0 commit comments