0.0.0-dev • Published 1 year ago

@yaupon/money v0.0.0-dev

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

💸 Money

Tiny dinero.js@alpha wrapper which provides additional dictionary of currencies, typings and guards for working with currencies and databases in real-world applications and overall bunch of type aliases to simplify workflow in TypeScript.

type CurrencyDictionary = {
    [key in keyof typeof DineroCurrencies & string]: Currency;
};
declare const currencies: CurrencyDictionary;
/**
 * This is a type alias for Dinero.
 */
declare var Money: typeof Dinero;
/**
 * This is a type alias for Dinero.Currency<number>.
 */
type Currency = Dinero.Currency<number>;
type CurrencyCode = Tagged<keyof typeof DineroCurrencies, "currency_code">;
declare function isCurrencyCode(value: unknown): value is CurrencyCode;
declare function assertCurrencyCode(value: unknown): asserts value is CurrencyCode;
/**
 * Returns a Dinero.Currency object for the given currency code.
 *
 * @param currency The ISO-4217 Currency Code.
 */
declare function getCurrencyByCode(currency: CurrencyCode): Currency;
/**
 * Function will validate if provided value is a valid Dinero.Currency object.
 * This is validation which allows definition of custom currency objects once
 * they are compatible with Dinero.Currency<number> type.
 * @param value
 */
declare function isCurrency(value: unknown): value is Currency;
/**
 * Function will validate if provided value is a valid Dinero.Currency object.
 * @param value
 */
declare function assertCurrency(value: unknown): asserts value is Currency;
/**
 * Function will define currency object, this is useful for defining custom currency objects
 * @param currency
 */
declare function defineCurrency(currency: Currency): Currency;