Giter Site home page Giter Site logo

dreambo8563 / vue-lazy-calc Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 4.0 2.77 MB

simple calculation lib with lazy feature πŸŽ²βž•βž–βž—βœ–οΈ

License: MIT License

JavaScript 7.52% TypeScript 92.48%
lazy-evaluation calculator vue typescript chaining

vue-lazy-calc's Introduction

codecov Codacy Badge All Contributors Build Status Greenkeeper badge Known Vulnerabilities License: MIT npm type definitions npm FOSSA Status

vue-lazy-calc

this is a simple calculation plugin in lazy way. (inspired by lodash)

features

  • vue friendly
  • strong typed
  • lazy evaluation
  • chaining methods
  • code coverage 100%

TODO:

  • seperate simple lazy class from base class
  • support more operator in stream api

Install

npm install vue-lazy-calc --save

Quick Start

import lzCalc from "vue-lazy-calc"
Vue.use(lzCalc)

Methods

  • this.$lzCalc in Component context.
  • Vue.$lzCalc in global.

API list

base

export declare class LazyBase {
  lazy(init?: number): LazyCalc
  stream(s?: LazyCalc): LazyStream
}
  • lazy => init a new instance with optional initValue
  • stream => init a stream to operate between multiple lazy instance with optional init instantce

simple

export declare class LazyCalc {
  add(y: number): LazyCalc
  divide(y: number): LazyCalc
  subtract(y: number): LazyCalc
  multiply(y: number): LazyCalc
  do(fn: operatorFunc): LazyCalc
  ceil(precision?: number): LazyCalc
  floor(precision?: number): LazyCalc
  round(precision?: number): LazyCalc
  default(fallback: any): LazyCalc
  value(): any
}
  • 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
  .lazy(1)
  .add(3)
  .multiply(2)
  .divide(3)
  .round(2)

console.log(result.value()) // 2.67

const addThree = result.add(3)
console.log(addThree.value()) // 2.67+ 3 =>5.67

Stream

declare class LazyStream {
  add(y: LazyCalc): LazyStream
  subtract(y: LazyCalc): LazyStream
  multiply(y: LazyCalc): LazyStream
  divide(y: LazyCalc): LazyStream
  round(precision?: number): LazyStream
  ceil(precision?: number): LazyStream
  floor(precision?: number): LazyStream
  do(fn: operatorFunc): LazyStream
  default(fallback: any): LazyStream
  value(): any
}
const result = this.$lzCalc
  .lazy(1)
  .add(3)
  .multiply(2)
  .divide(3)
  .round(2)

const tmp = this.$lzCalc.lazy(2).add(3)
const s = this.$lzCalc.stream(result).add(tmp)

console.log(s.value()) // 2.67 + 5 => 7.67
  1. when declare the result variable, no calculation excuted until value()
  2. you can reuse the declare variable

License

FOSSA Status

Contributors

Thanks goes to these wonderful people (emoji key):

Vincent Guo
Vincent Guo

πŸ’» πŸ“– πŸš‡

This project follows the all-contributors specification. Contributions of any kind welcome!

vue-lazy-calc's People

Contributors

allcontributors[bot] avatar codacy-badger avatar dreambo8563 avatar fossabot avatar greenkeeper[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vue-lazy-calc's Issues

An in-range update of eslint-plugin-vue is breaking the build 🚨

The devDependency eslint-plugin-vue was updated from 5.2.2 to 5.2.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-vue is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 3 commits.

  • 1064f10 πŸ”– 5.2.3
  • 158c10b chore: update ESLint to v6
  • 082c03d fix: remove eslint internal traverser (#910)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.