0.3.1 • Published 10 months ago

recurrentry v0.3.1

Weekly downloads
-
License
-
Repository
github
Last release
10 months ago

A highly opinionated TypeScript library for handling recurring payments with precision and flexibility.

I built this library to help me manage my personal finances and automate recurring payments for my income & expense trackking app gider.im.

šŸš€ Key Features

Payment Scheduling

  • ✨ Single and recurring payments (single, weekly, monthly, yearly)
  • šŸ”„ Support for payment modifications (edit, delete)
  • šŸ’¼ Business day adjustments (skip weekends/holidays)
  • ā° Grace period support for payment due dates
  • šŸ“† Day-level precision using Temporal API
  • šŸ›”ļø Type-safe configuration with TypeScript

Advanced Payment Rules

  • šŸ”¢ Flexible payment intervals (every X weeks/months/years)
  • šŸ“… Ordinal day specifications:
    • first-monday, last-friday, first-weekday, last-weekend
    • Supports all combinations of:
      • Position: first, second, third, fourth, fifth, last, nextToLast
      • Type: day, weekday, weekend, or specific day (monday-sunday)
  • šŸ“… Weekly payment features:
    • Specify days of the week (1-7, where 1 is Monday)
    • Skip weeks with the "every" parameter (e.g., bi-weekly payments)
    • Set specific payment days within each week

Modifications

  • āœļø Edit amount, date, or recurrence rules
  • šŸ—‘ļø Delete single or future occurrences
  • šŸ“ Apply changes to future payments

šŸ—“ļø Date Handling

The library operates with day-level precision using the Temporal API:

  • Uses Temporal.PlainDate for all date operations
  • Helper function createDate() provided for easy date creation
  • It's a peer dependency

šŸ“¦ Installation

pnpm install recurrentry
# or
bun install recurrentry
# or
npm install recurrentry
# or
yarn add recurrentry

šŸŽÆ Quick Example

const data = [
  {
    id: 1,
    name: "Single Payment",
    amount: "100.00",
    type: "income",
    date: createDate("2024-01-01"),
    config: {
      period: PERIOD.NONE,
      start: createDate("2024-01-01"),
      interval: 1,
    } satisfies SinglePayment,
  },
  {
    id: 3,
    name: "Weekly Income",
    amount: "255.00",
    type: "income",
    date: createDate("2024-01-01"),
    config: {
      period: PERIOD.WEEK,
      start: createDate("2024-01-01"),
      interval: 5,
      options: {
        every: 1,
        workdaysOnly: true,
      },
    } satisfies WeeklyPayment,
  },
  {
    id: 4,
    name: "Credit Card",
    amount: "1000.00",
    type: "expense",
    date: createDate("2024-01-01"),
    config: {
      period: PERIOD.MONTH,
      start: createDate("2024-01-01"),
      interval: 5,
      options: {
        every: 1,
        workdaysOnly: true,
        gracePeriod: 10,
      },
    } satisfies MonthlyPayment,
  },
];

// Let's generate the payments
const result = generator({
  data,
  modifications: [
    {
      itemId: 3,
      index: 2,
      payload: {
        amount: "411.00",
      },
      restPayload: {
        amount: "300.00",
      },
    },
    {
      itemId: 3,
      index: 4,
      payload: {
        amount: "555.12",
      },
    },
    {
      itemId: 4,
      index: 3,
      payload: {
        date: createDate("2024-01-15"),
        amount: "6087.22",
      },
    },
  ],
  weekendDays: [6, 7], // Saturday and Sunday
  holidays: [createDate("2024-01-01")], // New Year's Day
});

🟰 Example Generator Result

#indexnameamountperiodoccurrence datepayment date
1Single Payment100.00none2024-01-012024-01-01
31Weekly Income255.00week2024-01-012024-01-02
32Weekly Income411.00week2024-01-082024-01-08
33Weekly Income300.00week2024-01-152024-01-15
34Weekly Income555.12week2024-01-222024-01-22
35Weekly Income300.00week2024-01-292024-01-29
41Credit Card1000.00month2024-01-012024-01-11
42Credit Card1000.00month2024-02-012024-02-12
43Credit Card6087.22month2024-01-152024-01-15
44Credit Card1000.00month2024-04-012024-04-11
45Credit Card1000.00month2024-05-012024-05-13

šŸ¤ Contributing

  1. Fork the repository
  2. Create a new branch for your changes
  3. Make your changes and write tests if applicable
  4. Submit a pull request

šŸ“„ License

Licensed under the MIT License.

0.3.1

10 months ago

0.3.0

10 months ago

0.2.0

10 months ago

0.1.0

10 months ago

0.0.2

11 months ago

0.0.1

11 months ago