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

who-owes-who

v1.7.0

Published

A calculator to work out payments in groups

Downloads

318

Readme

README

Monorepo Build Continuous Deploy

This is a package for tracking payments made by people within a group. After updating a the system with a payment, a list of suggested payments to balance the debts can be generated.

The system is currency agnostic, however this document will refer to dollars for the purposes of ubiquitous language.

addPaymentSetToPerson

Scenario

Greg pays for dinner for Alice and Bob. Dinner was $99 and they agree to split it equally.

A correctly configured payment set added to Greg will set him up as being a 'lender' of $66. Bob and Alice will be 'borrowers' of $33 each.

The payment set in this scenario looks as follows:

const controller = new Controller();
const gregId = controller.addNewPerson();
const bobId = controller.addNewPerson();
const aliceId = controller.addNewPerson();

const paymentSetSetup: PaymentSetDTO = new Set([
  { amount: 3300, to: bobId },
  { amount: 3300, to: aliceId },
]);

const paymentSetId = controller.addPaymentSetToPerson(paymentSetSetup, gregId);

//paymentSetId => 688ca822-a075-4d41-85d5-7a383bac10c8

The system works based in cents, so Bob and Alice owe 3300 cents each.

getPaymentsByPerson

This retrieves a list of payments that have been made for a given person. The list should comprise of payment set ids. These ids are returned to you when you add a payment set to a person.

const paymentSetId = controller.addPaymentSetToPerson(paymentSetSetup, gregId);
//paymentSetId => fa43c43f-7857-451b-89fb-cf3f9a06a1df

const paymentSets = controller.getPaymentsByPerson([paymentSetId], personId);

addNewPerson

Functionality to add a new person to the group. The ID of the new person is returned when you create them.

const newPersonId = controller.addNewPerson();
//newPersonId => ffdec365-376f-4d88-821b-8c425dd13cd5

removePersonById

Functionality to remove a new person from the group. This should be passed the ID returned when the person was created. If a person is removed from the system then the system leaves the following responsibilities to you:

  • Deleting any payment sets owned by that person (this should be done before deleting the person).
controller.deletePaymentsByPerson(
  [...allPaymentSetIdsForPersonBeingRemoved],
  idOfPersonBeingRemoved
);
  • Updating payment sets owned by anyone else to remove that person (this can be achieved by deleting and recreating the payment set with an omission of the person that has now been removed). This action can be done before or after person removal, however, the controller.removePersonById(id) process will return you a list of payment sets that need updating for each person in the system.

deletePaymentSetsForPerson

A function for deleting any number of payment sets for a given person.

const paymentSetId = controller.addPaymentSetToPerson(paymentSetSetup, gregId);

controller.deletePaymentsByPerson([paymentSetId], personId);

getPaymentSetIdsByPerson

Get all of the paymentSetIds for a given person.

getSuggestedPayments

The payments suggested to balance all debts.

[
  {
    from: "05463ea3-4843-47f9-8f2d-dd0514294eb6",
    to: "9b563cc2-7782-49b3-901a-2c52e3e9f0b0",
    amount: 3300
  },
  {
    from: "107c79ed-e170-4bf3-8963-bae9db791483",
    to: "9b563cc2-7782-49b3-901a-2c52e3e9f0b0",
    amount: 3300
  }
];

The from and to properties are the IDs of people.

Exceptions

Attempting to perform an action on a person that does not exist will result in a PersonDoesNotExistError.

Attempting to perform an action on a payment set that does not exist will result in a PaymentSetDoesNotExistError.