Skip to content

1.0.4 #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="1.0.4"></a>
## [1.0.4](https://github.com/dreambo8563/vue-lazy-calc/compare/v1.0.3...v1.0.4) (2019-03-19)


### Features

* **operator:** default ([74e5381](https://github.com/dreambo8563/vue-lazy-calc/commit/74e5381))



<a name="1.0.3"></a>
## [1.0.3](https://github.com/dreambo8563/vue-lazy-calc/compare/v1.0.2...v1.0.3) (2019-03-19)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ interface ILazyCalc {
floor(precision?: number): ILazyCalc
ceil(precision?: number): ILazyCalc
do(fn: operatorFunc): ILazyCalc
default(fallback: any): ILazyCalc
value(fallback?: any): any
}
```
Expand All @@ -60,6 +61,7 @@ interface ILazyCalc {
- add/subtract/divide/multiple => + - \* / (simple calculation)
- round/floor/ceil => deal with precision of the float number
- value => excute the declared method chain with optional fallBack value(if the result is NaN)
- default => set default value if previous operations get NaN
- do => accept a custormized function for the number

### Examples
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-lazy-calc",
"version": "1.0.3",
"version": "1.0.4",
"private": false,
"author": "dreambo8563",
"main": "dist/vue-lazy-calc.umd.min.js",
Expand Down
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ class LazyCalc {
// this.operators.unshift(operation);
return this.clone([operation, ...this.operators]);
}
default(fallback: any) {
const operation = function(x: number | string) {
return Number.isNaN(+x) ? fallback : x;
};
return this.clone([operation, ...this.operators]);
}
value(fallback: any = 0) {
const result = this.compose(this.operators)(this.initValue);
this.initValue = 0;
Expand All @@ -129,6 +135,7 @@ interface ILazyCalc {
floor(precision?: number): ILazyCalc;
ceil(precision?: number): ILazyCalc;
do(fn: operatorFunc): ILazyCalc;
default(fallback: any): ILazyCalc;
value(fallback?: any): any;
}
export type LzCalcPlugin = {
Expand Down
1 change: 1 addition & 0 deletions types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ILazyCalc {
floor(precision?: number): ILazyCalc;
ceil(precision?: number): ILazyCalc;
do(fn: operatorFunc): ILazyCalc;
default(fallback: any): ILazyCalc;
value(fallback?: any): any;
}
export declare type LzCalcPlugin = {
Expand Down