pixiu-number-toolkit
Version:
A collection of number utilities.
54 lines (51 loc) • 1.67 kB
TypeScript
import { CurrencyCode, CurrencyUnit } from '../constants/enum.js';
type CurrencyCodeType = keyof typeof CurrencyCode;
type CurrencyStyleType = 'decimal' | 'currency' | 'unit' | 'percent';
type CurrencyUnitType = `${CurrencyUnit}`;
/**
* @link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
*/
interface CurrencyOptions extends Intl.NumberFormatOptions {
locale?: CurrencyCodeType;
style?: CurrencyStyleType;
unit?: CurrencyUnitType;
/**
* 返回内容增加前缀
*/
prefix?: string;
/**
* 返回内容增加后缀
*/
suffix?: string;
}
/**
* 获取当前货币的千位分隔符和小数点符号
* @param locale 货币代码
* @returns 千位分隔符和小数点符号
*/
declare const getCurrencySeparators: (locale?: CurrencyCodeType) => {
groupSeparator: string;
decimalSeparator: string;
};
/**
* 将货币字符串转换为数字
* @param value 货币字符串
* @param locale 货币代码
* @returns 数字
*/
declare const convertCurrencyToNumber: (value: string, locale?: CurrencyCodeType) => number;
/**
* 格式化货币
* @param value 数字或字符串
* @param options 格式化选项
* @returns 格式化后的货币字符串
*/
declare const currency: {
(value: number | string | bigint, options?: CurrencyOptions): string;
/**
* 设置全局默认选项
* @param options 默认选项
*/
setGlobalOptions(options: CurrencyOptions): void;
};
export { type CurrencyCodeType, type CurrencyOptions, type CurrencyStyleType, type CurrencyUnitType, convertCurrencyToNumber, currency, getCurrencySeparators };