Skip to content

Commit f1687ea

Browse files
authored
Merge pull request #14 from dreambo8563/release
1.0.4
2 parents f218ea2 + 28906b8 commit f1687ea

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
111
<a name="1.0.3"></a>
212
## [1.0.3](https://github.com/dreambo8563/vue-lazy-calc/compare/v1.0.2...v1.0.3) (2019-03-19)
313

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ interface ILazyCalc {
5252
floor(precision?: number): ILazyCalc
5353
ceil(precision?: number): ILazyCalc
5454
do(fn: operatorFunc): ILazyCalc
55+
default(fallback: any): ILazyCalc
5556
value(fallback?: any): any
5657
}
5758
```
@@ -60,6 +61,7 @@ interface ILazyCalc {
6061
- add/subtract/divide/multiple => + - \* / (simple calculation)
6162
- round/floor/ceil => deal with precision of the float number
6263
- 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
6365
- do => accept a custormized function for the number
6466

6567
### Examples

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-lazy-calc",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"private": false,
55
"author": "dreambo8563",
66
"main": "dist/vue-lazy-calc.umd.min.js",

src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ class LazyCalc {
112112
// this.operators.unshift(operation);
113113
return this.clone([operation, ...this.operators]);
114114
}
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+
}
115121
value(fallback: any = 0) {
116122
const result = this.compose(this.operators)(this.initValue);
117123
this.initValue = 0;
@@ -129,6 +135,7 @@ interface ILazyCalc {
129135
floor(precision?: number): ILazyCalc;
130136
ceil(precision?: number): ILazyCalc;
131137
do(fn: operatorFunc): ILazyCalc;
138+
default(fallback: any): ILazyCalc;
132139
value(fallback?: any): any;
133140
}
134141
export type LzCalcPlugin = {

types/main.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface ILazyCalc {
1010
floor(precision?: number): ILazyCalc;
1111
ceil(precision?: number): ILazyCalc;
1212
do(fn: operatorFunc): ILazyCalc;
13+
default(fallback: any): ILazyCalc;
1314
value(fallback?: any): any;
1415
}
1516
export declare type LzCalcPlugin = {

0 commit comments

Comments
 (0)