File tree Expand file tree Collapse file tree 6 files changed +22
-2
lines changed Expand file tree Collapse file tree 6 files changed +22
-2
lines changed Original file line number Diff line number Diff line change
1
+ <a name =" 1.0.4 " ></a >
2
+ ## [ 1.0.4] ( https://github.com/dreambo8563/vue-lazy-calc/compare/v1.0.3...v1.0.4 ) (2019-03-19)
3
+
4
+
5
+ ### Features
6
+
7
+ * ** operator:** default ([ 74e5381] ( https://github.com/dreambo8563/vue-lazy-calc/commit/74e5381 ) )
8
+
9
+
10
+
1
11
<a name =" 1.0.3 " ></a >
2
12
## [ 1.0.3] ( https://github.com/dreambo8563/vue-lazy-calc/compare/v1.0.2...v1.0.3 ) (2019-03-19)
3
13
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ interface ILazyCalc {
52
52
floor(precision ? : number ): ILazyCalc
53
53
ceil(precision ? : number ): ILazyCalc
54
54
do(fn : operatorFunc ): ILazyCalc
55
+ default(fallback : any ): ILazyCalc
55
56
value(fallback ? : any ): any
56
57
}
57
58
```
@@ -60,6 +61,7 @@ interface ILazyCalc {
60
61
- add/subtract/divide/multiple => + - \* / (simple calculation)
61
62
- round/floor/ceil => deal with precision of the float number
62
63
- value => excute the declared method chain with optional fallBack value(if the result is NaN)
64
+ - default => set default value if previous operations get NaN
63
65
- do => accept a custormized function for the number
64
66
65
67
### Examples
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " vue-lazy-calc" ,
3
- "version" : " 1.0.3 " ,
3
+ "version" : " 1.0.4 " ,
4
4
"private" : false ,
5
5
"author" : " dreambo8563" ,
6
6
"main" : " dist/vue-lazy-calc.umd.min.js" ,
Original file line number Diff line number Diff line change @@ -112,6 +112,12 @@ class LazyCalc {
112
112
// this.operators.unshift(operation);
113
113
return this . clone ( [ operation , ...this . operators ] ) ;
114
114
}
115
+ default ( fallback : any ) {
116
+ const operation = function ( x : number | string ) {
117
+ return Number . isNaN ( + x ) ? fallback : x ;
118
+ } ;
119
+ return this . clone ( [ operation , ...this . operators ] ) ;
120
+ }
115
121
value ( fallback : any = 0 ) {
116
122
const result = this . compose ( this . operators ) ( this . initValue ) ;
117
123
this . initValue = 0 ;
@@ -129,6 +135,7 @@ interface ILazyCalc {
129
135
floor ( precision ?: number ) : ILazyCalc ;
130
136
ceil ( precision ?: number ) : ILazyCalc ;
131
137
do ( fn : operatorFunc ) : ILazyCalc ;
138
+ default ( fallback : any ) : ILazyCalc ;
132
139
value ( fallback ?: any ) : any ;
133
140
}
134
141
export type LzCalcPlugin = {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ interface ILazyCalc {
10
10
floor ( precision ?: number ) : ILazyCalc ;
11
11
ceil ( precision ?: number ) : ILazyCalc ;
12
12
do ( fn : operatorFunc ) : ILazyCalc ;
13
+ default ( fallback : any ) : ILazyCalc ;
13
14
value ( fallback ?: any ) : any ;
14
15
}
15
16
export declare type LzCalcPlugin = {
You can’t perform that action at this time.
0 commit comments