@resk/core
Version:
An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla
125 lines (124 loc) • 5.86 kB
TypeScript
import { ICurrency, ICurrencyFormatters } from "../currency/types";
/**
* Extends the Number interface with additional methods for formatting and abbreviating numbers.
*/
declare global {
interface Number extends ICurrencyFormatters {
/**
* Counts the number of decimal places in the number.
* @returns {number} The number of decimal places.
*/
countDecimals: () => number;
/**
* Formats the number as a currency string.
* @param {ICurrency | string} [symbol] The currency symbol to use (optional).
* @param {number} [decimalDigits] The number of decimal places to display (optional).
* @param {string} [thousandSeparator] The separator to use for thousands (optional).
* @param {string} [decimalSeparator] The separator to use for decimals (optional).
* @param {string} [format] The format to use for the currency string (optional).
* @returns {string} The formatted currency string.
* @example
* ```ts
* (12).formatMoney(); // Output: "12 FCFA"
* (12000).formatMoney(); // Output: "12 000 FCFA"
* ```
*/
formatMoney: (symbol?: ICurrency | string, decimalDigits?: number, thousandSeparator?: string, decimalSeparator?: string, format?: string) => string;
/**
* Formats the number using the specified formatter.
* @param {string} [formatter] The formatter to use (optional).
* @param {boolean} [abreviate] Whether to abbreviate the number (optional).
* @returns {string} The formatted string.
* @example
* ```ts
* (12).format("moneyCAD"); // Output: "CA$12"
* ```
*/
format: (formatter?: string, abreviate?: boolean) => string;
/**
* Formats the number as a formatted number string with thousands separators.
* @param {ICurrency | number} [optionsOrDecimalDigits] The options or decimal digits to use (optional).
* @param {string} [thousandSeparator] The separator to use for thousands (optional).
* @param {string} [decimalSeparator] The separator to use for decimals (optional).
* @returns {string} The formatted number string.
*/
formatNumber: (optionsOrDecimalDigits?: ICurrency | number, thousandSeparator?: string, decimalSeparator?: string) => string;
/**
* Abbreviates the number to a shorter format (e.g. "1K", "1M", etc.).
* @returns {string} The abbreviated string.
*/
abreviate: () => string;
/**
* Abbreviates the number and formats it as a currency string.
* @param {ICurrency | string} [symbol] The currency symbol to use (optional).
* @param {number} [decimalDigits] The number of decimal places to display (optional).
* @param {string} [thousandSeparator] The separator to use for thousands (optional).
* @param {string} [decimalSeparator] The separator to use for decimals (optional).
* @param {string} [format] The format to use for the currency string (optional).
* @returns {string} The formatted and abbreviated currency string.
*/
abreviate2FormatMoney: (symbol?: ICurrency | string, decimalDigits?: number, thousandSeparator?: string, decimalSeparator?: string, format?: string) => string;
}
}
/**
* Represents the result of abbreviating a number.
*/
export type IAbreviateNumberResult = {
/**
* The abbreviated result.
*/
result: string;
/**
* The original value that was abbreviated.
*/
value: number;
/**
* The format used for abbreviation.
*/
format: string;
/**
* The suffix used for abbreviation (e.g. "K", "M", etc.).
*/
suffix: string;
/**
* The formatted value.
*/
formattedValue: string;
};
/**
* Abbreviates a number to a shorter form (e.g. 1000 -> 1K).
*@see : https://stackoverflow.com/questions/10599933/convert-long-number-into-abbreviated-string-in-javascript-with-a-special-shortn
* @param {number} num The number to abbreviate.
* @param {boolean} [returnObject=false] Whether to return an object with additional information.
* @returns {string | IAbreviateNumberResult} The abbreviated number or an object with additional information.
*/
export declare const _abreviateNumber: (num: number, returnObject?: boolean) => string | IAbreviateNumberResult;
/**
* Abbreviates a number to a shorter form (e.g. 1000 -> 1K).
*
* @param {number} num The number to abbreviate.
* @returns {string} The abbreviated number.
*/
export declare const abreviateNumber: (num: number) => string;
/**
* Abbreviates a number and formats it as a monetary value.
*
* @param {number} number The number to abbreviate and format.
* @param {ICurrency | string} [symbol] The currency symbol or name.
* @param {number} [decimalDigits] The number of decimal digits to use.
* @param {string} [thousandSeparator] The thousand separator to use.
* @param {string} [decimalSeparator] The decimal separator to use.
* @param {string} [format] The format string to use.
* @returns {string} The abbreviated and formatted monetary value.
*/
export declare const abreviate2FormatMoney: (number: number, symbol?: ICurrency | string, decimalDigits?: number, thousandSeparator?: string, decimalSeparator?: string, format?: string) => string;
/**
* Returns the first non-zero number from a list of arguments, or 0 if no such number exists.
*
* This function iterates over the arguments and returns the first one that is a non-zero number.
* If no such number is found, it returns 0.
*
* @param args A list of arguments to check.
* @returns The first non-zero number, or 0 if no such number exists.
*/
export declare function defaultNumber(...args: any[]): number;