@technobuddha/library
Version:
A large library of useful functions
56 lines (55 loc) • 2.13 kB
TypeScript
export declare type Options = OptionsCardinal & OptionsIllion;
export declare type OptionsCardinal = {
/** The number of groups to output, each group consists of three digits. */
groups?: number;
/** Use numbers instead of words for the group value, the group name is still output as text */
digits?: boolean;
};
export declare type OptionsIllion = {
/** Word to place after the hundreds. "one hundred and one" vs. "one hundred one" */
and?: string;
/** Places a character between the tens units and the ones units. "twenty-one" vs. "twenty one" */
hyphen?: string;
};
/**
* Convert a number into text (the cardinal number)
*
* @remark There is no limit to the numbers that can be expressed, however Javascript/Typescript can only represent numbers
* up to uncentillions (1e308).
*
* @param input The number
* @param __namedParameters see {@link Options}
* @returns The number spelled out
*
* @default groups Infinity
* @default digits false
* @default and (empty)
* @default hyphen (space)
*/
export declare function cardinal(input: number, { groups, digits, ...options }?: Options): string;
/**
* Get the spelled out word for an exponent
*
* @remarks This is only using the exponent, There is no limit to the numbers this function can represents, however Javascript/Typescript can only represent
* numbers up to 1e308, which limits the numbers that this method can represent to 10^10^308 which is really really big.
*
* @example 6 is "million"
* @example 303 is "centillion"
* @param exponent The exponent to convert
* @returns Order of Magnitude as text
*/
export declare function orderOfMagnitude(exponent: number): string | null;
/**
* Get a short description of a number
*
* @remarks this is a shortcut to calling cardinal with options {groups: 1, digits: true}
*
* @example 1000000 "1 million"
* @example 101323847382459 "101 trillion"
*
* @param input number to convert
* @param options see {@link OptionsIllion}
* @return number as text
*/
export declare function summarize(input: number, options?: OptionsIllion): string;
export default cardinal;