Package Exports
- monie-utils
- monie-utils/dist/index.js
- monie-utils/dist/index.mjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (monie-utils) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
๐ฐ Monie Utils
A comprehensive TypeScript library for money-related utilities including currency formatting, conversion, validation, and financial calculations.
โจ Features
- ๐ฏ Type-safe - Built with TypeScript for excellent developer experience
- ๐ International - Support for multiple currencies and locales
- ๐ฑ Currency operations - Formatting, conversion, and validation
- ๐งฎ Financial calculations - Interest, loans, investments, and more
- ๐ Business utilities - Payment processing, subscriptions, analytics
- ๐ Lightweight - Tree-shakeable with zero dependencies
- โ Well-tested - Comprehensive test coverage
- ๐ Well-documented - Extensive documentation and examples
๐ Installation
npm install monie-utilsyarn add monie-utilspnpm add monie-utils๐ Quick Start
import {
isValidAmount,
isValidCurrency,
validateMoneyObject
} from 'monie-utils';
// Validate amounts
console.log(isValidAmount(100.50)); // true
console.log(isValidAmount(NaN)); // false
// Validate currencies
console.log(isValidCurrency('USD')); // true
console.log(isValidCurrency('BTC')); // true
console.log(isValidCurrency('INVALID')); // false
// Validate money objects
const money = { amount: 100, currency: 'USD' };
console.log(validateMoneyObject(money)); // true๐ API Reference
Validation Functions
isValidAmount(amount: unknown): amount is number
Checks if a value is a valid money amount.
isValidCurrency(currencyCode: unknown): currencyCode is string
Validates currency codes against ISO 4217 and common cryptocurrencies.
validateMoneyObject(moneyObject: unknown): moneyObject is Money
Validates a complete money object structure.
isPositiveAmount(amount: number): boolean
Checks if an amount is positive.
isWithinRange(amount: number, min: number, max: number): boolean
Checks if an amount is within a specified range.
normalizeAmount(amount: number): number
Normalizes amount to ensure proper precision for money calculations.
Currency Functions
isCryptoCurrency(currencyCode: string): boolean
Checks if a currency is a cryptocurrency.
isFiatCurrency(currencyCode: string): boolean
Checks if a currency is a fiat currency.
๐งช Development
Prerequisites
- Node.js 18+
- npm, yarn, or pnpm
Setup
# Clone the repository
git clone https://github.com/spiderocious/monie-utils.git
cd monie-utils
# Install dependencies
npm install
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Build the library
npm run build
# Lint and format
npm run lint
npm run formatScripts
npm run dev- Start development server with Vitenpm run build- Build the library with tsupnpm test- Run tests with Jestnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage reportnpm run lint- Lint code with ESLintnpm run lint:fix- Fix linting issuesnpm run format- Format code with Prettiernpm run type-check- Run TypeScript type checking
๐ Acknowledgments
- Inspired by financial libraries from Stripe, PayStack, Monnify, and other payment processors
- Built with modern TypeScript and development tools
- Thanks to all contributors and the open-source community
Made with โค๏ธ by Oluwaferanmi (https://github.com/spiderocious)