@type-ddd/money
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

@type-ddd/money

The @type-ddd/money library provides TypeScript type definitions for handling Money in Domain-Driven Design contexts. It facilitates the validation, formatting, and manipulation of monetary values, adhering to DDD principles.


Installation

Install rich-domain and @type-ddd/money with your favorite package manager


npm i rich-domain @type-ddd/money

# OR

yarn add rich-domain @type-ddd/money

Usage

import { Money } from '@type-ddd/money'

// Initialize a Money object with the provided value
const amount = Money.init(100);

// OR

const result = Money.create(100);

// Check if a value is a valid monetary amount
const isValid = Money.isValid(100);

// Sum two monetary values or Money objects
const total = Money.sum(amount, 50);

// Subtract one monetary value or Money object from another
const difference = Money.subtract(total, 25);

// Multiply two monetary values or Money objects
const product = Money.multiply(difference, 2);

// Divide one monetary value or Money object by another
const quotient = Money.divide(product, 4);

// Round down the monetary value to the nearest integer
const floorValue = quotient.floor();

// Round up the monetary value to the nearest integer
const ceilValue = quotient.ceil();

// Calculate compound interest based on the provided rate and periods
const interest = Money.compoundInterest(5, 10);

// Generate a random monetary value within the specified range
const randomAmount = Money.random(10, 100);

// Calculate the average value among the provided Money objects
const average = Money.average([amount, total, difference]);

// Convert the current Money value to another currency using the provided exchange rate
const convertedAmount = amount.convertTo(2);

// Generate a formatted string representing the monetary value in a specific currency and locale
const formattedAmount = amount.coin('USD', 'en-US');

console.log(formattedAmount);
// Output: $100.00 (assuming 100 is the amount in USD)

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.058latest
0.0.4-alpha.058beta

Version History

VersionDownloads (Last 7 Days)Published
0.1.058
0.0.4-alpha.058
0.0.310
0.0.224
0.0.12

Package Sidebar

Install

npm i @type-ddd/money

Weekly Downloads

152

Version

0.1.0

License

MIT

Unpacked Size

35.3 kB

Total Files

4

Last publish

Collaborators

  • alessandro-dev