npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-lazy-calc

v1.2.0

Published

A simple calculator with lazy evaluation featuer

Downloads

70

Readme

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 just support simple calculation in lazy way. (inspired by lodash)

features

  • vue friendly
  • strong typed
  • lazy evaluation
  • chaining methods

TODO:

  • [x] seperate simple lazy class from base class
  • [x] 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):

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