This package has been deprecated

Author message:

This package is no longer maintained. Please use something else.

repeating-amount
TypeScript icon, indicating that this package has built-in type declarations

2.2.2 • Public • Published

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"}

Package Sidebar

Install

npm i repeating-amount

Weekly Downloads

2

Version

2.2.2

License

MIT

Unpacked Size

39.1 kB

Total Files

41

Last publish

Collaborators

  • miikis