2.2.2 • Published 5 years ago

repeating-amount v2.2.2

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

npm GitHub Miikis Coverage Status

Repeating Amount

A well-tested, functional library for handling time-based conversions between repeating amounts

Installation

yarn add repeating-amount

Usage

import { Amount, RepeatPeriod, reduce } from "repeating-amount"

// import the units that you need
const {
    yearly,
    twiceAYear,
    quarterly,
    monthly,
    fortnightly,
    weekly,
    daily,
    hourly
} = RepeatPeriod

// Create your amounts
const breakfast = new Amount(5, daily)
const lunch = new Amount(20, weekly)
// You don't have to use the Amount constructor
// You can use an object literal, like below
const dinner = { value: 100, repeated: fortnightly }

// You can now add the amounts together
const foodBudgetForMonth = reduce(breakfast, lunch, dinner)(monthly)
console.log(foodBudgetForMonth) // => {value: 460.21, repeated: "monthly"}

// OR you can convert individual amounts
const breakfastBudgetPerMonth = reduce(breakfast)(monthly)
console.log(breakfastBudgetPerMonth) // => {value: 153.4, repeated: "monthly"}

// You can also override the fundamental unit values
const hourlyPay = new Amount(36, hourly)
const salary = reduce(hourlyPay)(yearly, { hoursPerDay: 8, daysPerWeek: 5 })
console.log(salary) // => {value: 75135.6, repeated: "yearly"}
2.2.1

5 years ago

2.2.2

5 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago