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

@neumatter/monetary-value

v1.0.0

Published

For mathematically accurate monetary calculations in JavaScript and TypeScript.

Downloads

4

Readme

Monetary Value Library

JavaScript Style Guide

Introduction

This TypeScript library provides a robust implementation for handling monetary values. It includes features such as arithmetic operations, currency conversion, comparison, allocation, and scaling of monetary amounts in different currencies. The core of the library revolves around the MonetaryValue class which encapsulates all functionality needed to manipulate monetary amounts with precision.

Installation

To install the Monetary Value Library, you will need Node.js and npm (Node Package Manager) installed on your machine. Once you have those set up, you can install the library via npm:

pnpm add @neumatter/monetary-value --save

Usage

Creating Monetary Values

To create a new monetary value, you can use the MonetaryValue class constructor.

import { MonetaryValue } from '@neumatter/monetary-value'

const amount = MonetaryValue.from('100.00 USD')
const amount2 = new MonetaryValue(10000, 2, 'USD')
console.log(amount.toString()) // Outputs '100.00 USD'
console.log(amount2.toString()) // Outputs '100.00 USD'

Arithmetic Operations

import { MonetaryValue } from '@neumatter/monetary-value'

const amount1 = MonetaryValue.from('100.00 USD')
const amount2 = MonetaryValue.from('50.00 USD')

const sum = amount1.add(amount2)
const difference = amount1.subtract(amount2)
const product = amount1.multiply(2)

console.log(sum.toString()) // Outputs '150.00 USD'
console.log(difference.toString()) // Outputs '50.00 USD'
console.log(product.toString()) // Outputs '200.00 USD'

Comparison and Allocation

import { MonetaryValue } from '@neumatter/monetary-value'

const amount1 = MonetaryValue.from('100.00 USD')
const amount2 = MonetaryValue.from('50.00 USD')

console.log(amount1.isGreaterThan(amount2)) // Outputs true
console.log(amount1.isLessThan(amount2)) // Outputs false
console.log(amount1.isEqualTo(amount2)) // Outputs false

const [allocated1, allocated2] = amount1.allocate([50, 50])
console.log(allocated1.toString()) // Outputs '50.00 USD'
console.log(allocated2.toString()) // Outputs '50.00 USD'