UNPKG

@activecollab/components

Version:

ActiveCollab Components

56 lines 3.91 kB
export declare const currencyMultiplier: { k: number; m: number; b: number; t: number; }; export declare const fixedDecimalSpaces: (num: number, fixed: number) => number; export declare const getNumberFromString: (number: string | number, thousandSeparator?: string, decimalSeparator?: string) => number; /** * @function formatNumber * @description * Formats a number or string into a human-readable format with options for thousand separators, * decimal precision, and shortening the number using suffixes (K, M, B, T). * It can handle negative numbers and optionally trim decimals and set number of decimal places based on the configuration. * * @param {string | number} n - The number or string to be formatted. * @param {"," | "." | " " | ""} [thousandSeparator=","] - The character to use as a thousand separator. * @param {"," | "."} [decimalSeperator="."] - The character to use as a decimal separator. * @param {boolean} [trimDecimals=true] - Whether to trim decimals to the specified number of decimal spaces. * @param {number} [decimalSpaces=2] - The number of decimal spaces to keep in the formatted output. * @param {"long" | "short"} [format="long"] - The format type, either "long" for full numbers or "short" for shortened numbers with suffixes. * @param {number} [shortenThreshold=1000] - The minimum numeric value at which the number should be shortened * using suffixes. Numbers below this threshold will always be shown in long format. * * @returns {string} - The formatted number as a string with separators and potentially with decimals. * * @example * formatNumber(1500) // "1,500.00" * formatNumber(1500000, ",", ".", true, 2, "short") // "1.5M" */ export declare const formatNumber: (n?: string | number, thousandSeparator?: string, decimalSeperator?: string, trimDecimals?: boolean, decimalSpaces?: number, format?: string, shortenThreshold?: number) => string; export declare const numberWithSeparator: (x: number | string, thousandSeparator?: string, decimalSeparator?: string, format?: boolean) => string | number; /** * @function formatCurrency * @description * Formats a number or string as a currency string with options for thousand separators, * decimal precision, currency code, currency code position, and the use of suffixes (K, M, B, T) if needed. * It can handle negative values and supports customization of the currency code and its position. * * @param {string | number} n - The number or string to be formatted as currency. * @param {"," | "." | " " | ""} [thousandSeparator=","] - The character to use as a thousand separator. * @param {"," | "."} [decimalSeperator="."] - The character to use as a decimal separator. * @param {boolean} [trimDecimals=false] - Whether to trim decimals to the specified number of decimal spaces. * @param {number} [decimalSpaces=2] - The number of decimal spaces to keep in the formatted output. * @param {"long" | "short"} [format="long"] - The format type, either "long" for full numbers or "short" for shortened numbers with suffixes. * @param {string} [currencyCode=""] - The currency code to append or prepend to the formatted number. * @param {"right" | "left"} [currencyCodePosition="right"] - The position of the currency code relative to the formatted number. * * @returns {string} - The formatted currency string, including the currency code if provided. * * @example * formatCurrency(1500, ",", ".", false, 2, "long", "USD", "right") // "1,500.00 USD" * formatCurrency(1500000, ",", ".", true, 2, "short", "JPY", "left") // "JPY 1.5M" */ export declare const formatCurrency: (n?: string | number, thousandSeparator?: string, decimalSeperator?: string, trimDecimals?: boolean, decimalSpaces?: number, format?: string, currencyCode?: string, currencyCodePosition?: string) => string; //# sourceMappingURL=currencyUtils.d.ts.map