shelving
Version:
Toolkit for using data in JavaScript.
36 lines (35 loc) • 1.82 kB
TypeScript
import { type CurrencyCode } from "../util/currency.js";
import { NumberSchema, type NumberSchemaOptions } from "./NumberSchema.js";
/** Allowed options for `CurrencyAmountSchema`. */
export interface CurrencyAmountSchemaOptions extends NumberSchemaOptions {
readonly symbol?: string | undefined;
readonly currency: CurrencyCode;
}
/**
* Schema representing a numeric amount in a specific currency.
*
* - The validation step is inferred from the currency's minor units.
* - The default formatter renders amounts using shelving's currency helpers.
*
* @example
* const PRICE = new CurrencyAmountSchema({ currency: "GBP", min: 0 });
* PRICE.validate("12.345"); // 12.35
* PRICE.format(12.3); // "£12.30"
*/
export declare class CurrencyAmountSchema extends NumberSchema {
readonly step: number;
readonly currency: CurrencyCode;
readonly symbol: string;
constructor({ currency, one, title, symbol, step, ...options }: CurrencyAmountSchemaOptions);
format(value: number): string;
}
/** Valid non-negative monetary amount in the a currency. */
export declare const CURRENCY_AMOUNT: (currency: CurrencyCode) => CurrencyAmountSchema;
export declare const USD_AMOUNT: CurrencyAmountSchema;
export declare const GBP_AMOUNT: CurrencyAmountSchema;
export declare const EUR_AMOUNT: CurrencyAmountSchema;
/** Valid optional monetary amount in the default currency, or `null`. */
export declare const NULLABLE_CURRENCY_AMOUNT: (currency: CurrencyCode) => import("./NullableSchema.js").NullableSchema<number>;
export declare const NULLABLE_USD_AMOUNT: import("./NullableSchema.js").NullableSchema<number>;
export declare const NULLABLE_GBP_AMOUNT: import("./NullableSchema.js").NullableSchema<number>;
export declare const NULLABLE_EUR_AMOUNT: import("./NullableSchema.js").NullableSchema<number>;