vue-lazy-calc
this is a just support simple calculation in lazy way. (inspired by lodash)
features
- vue friendly
- strong typed
- lazy evaluation
- chaining methods
TODO:
- seperate simple lazy class from base class
- support more operator in stream api
Install
npm install vue-lazy-calc --save
Quick Start
Vue
Methods
- this.$lzCalc in Component context.
- Vue.$lzCalc in global.
API list
base
declare
- lazy => init a new instance with optional initValue
- stream => init a stream to operate between multiple lazy instance with optional init instantce
simple
declare
- add/subtract/divide/multiple => + - * / (simple calculation) between numbers
- round/floor/ceil => deal with precision of the float number
- value => excute the declared method chain
- default => set default value if previous operations get NaN
- do => accept a custormized function for the number
Examples
(1+3)*2/3 with precision 2
const result = this$lzCalc console // 2.67 const addThree = resultconsole // 2.67+ 3 =>5.67
Stream
declare
const result = this$lzCalc const tmp = this$lzCalcconst s = this$lzCalc console // 2.67 + 5 => 7.67
- when declare the result variable, no calculation excuted until value()
- you can reuse the declare variable
License
Contributors
Thanks goes to these wonderful people (emoji key):
Vincent Guo 💻 📖 🚇 |
This project follows the all-contributors specification. Contributions of any kind welcome!