/** * @file * Number and String format utilities. */ /** * Returns a formatted string. * * ```js * const text = sprintf('%1$s %2$s a %3$s', 'Polly', 'wants', 'cracker') // 'Polly wants a cracker' * ``` * * #### Format Specification * The placeholders in the format string are marked by `%` and are followed by one or more of these elements, in this order: * * * An optional number followed by a `$` sign that selects which argument index to use for the value. If not specified, arguments are placed in the same order as the placeholders in the input string. * * An optional `+` sign that forces to preceed the result with a plus or minus sign on numeric values. By default, only the `-` sign is used on negative numbers. * * An optional padding specifier that says what character to use for padding, if specified. Possible values are `0` or any other character preceded by a (`'`) (single quote). The default is to pad with *spaces*. * * An optional `-` sign that causes `sprintf` to left-align the result of this placeholder. The default is to right-align the result. * * An optional number that says how many characters the result has. If the value to be returned is shorter than this number, the result is padded. When used with the `j` (JSON) type specifier, the padding length specifies the tab size used for indentation. * * An optional precision modifier, consisting of a `.` (dot) followed by a number, that says how many digits are displayed for floating point numbers. When used with the `g` type specifier, it specifies the number of significant digits. When used on a string, it causes the result to be truncated. * * A type specifier that can be any of the following: * * `%` — yields a literal `%` character * * `b` — yields an integer as a binary number * * `c` — yields an integer as the character with that ASCII value * * `d` or `i` — yields an integer as a signed decimal number * * `e` — yields a float using scientific notation * * `u` — yields an integer as an unsigned decimal number * * `f` — yields a float as is; see notes on precision above * * `g` — yields a float as is; see notes on precision above * * `o` — yields an integer as an octal number * * `s` — yields a string as is * * `t` — yields `true` or `false` * * `T` — yields the type of the argument1 * * `v` — yields the primitive value of the specified argument * * `x` — yields an integer as a hexadecimal number (lower-case) * * `X` — yields an integer as a hexadecimal number (upper-case) * * `j` — yields a JavaScript object or array as a JSON encoded string * * This utility was adapted from [Alexandru's sprintf-js implementation](https://github.com/alexei/sprintf.js). * * @param {string} fmt - The string to format and insert values into. * @param {Any} values - The values to insert into the format string. See specification above. * @public */ export declare function sprintf(key: string, ...rest: any[]): string; /** * Abbreviates a number by rounding to no more than three decimal places and by appending a * suffix: K/M/B. Additionally, the resulting number is formatted using a given locale. * * Examples: * * `99549` returns `99.5K` * * `1159000` returns `1.16M` * * `9500`, `de-de` returns `9,5K` * * @param {Number|String} number The number to abbreviate. * @param {String} [locale='en-us'] * @returns {String} The abbreviated and localized number if `number` is positive. The localized * number if negative. * @public */ export declare function abbreviateNumber(number: number | string, locale?: string): string; /** * Abbreviates a number by rounding to no more than two decimal places and by converting to * binary prefixes (B/KB/MB/GB/TB). Additionally, the resulting number is formatted using a * given locale. * * Examples: * * `100` returns `100 B` * * `1200` returns `1.17 KB` * * `96619136`, `de-de` returns `92,14 MB` * * @param {Number|String} bytes The number of bytes to abbreviate. * @param {String} [locale='en-us'] * @throws {RangeError} If `bytes` is less than zero. * @return {String} The abbreviated and localized number. * @public */ export declare function bytesToFileSize(bytes: number | string, locale?: string): string; /** * Returns `{max}+` if `number` exceeds `max`. Otherwise, returns `number`. * @param {Object} params * @param {Number} params.number * @param {Number} params.max * @returns {String} * @public */ export declare function truncateNumber({ number, max }: { number: number; max: number; }): string; /** * Trim a String by replacing characters in the middle with an ellipsis. * * Examples: * * `1234567890`, `7` returns `123...7890` * * `1234567890`, `10` returns `1234567890` * * `1234567890`, `50` returns `1234567890` * * `1234567890`, `2`, `{ precomposed: true }` returns `1…0` * * @param {String} string The input string. * @param {Number} maxCharsFromString How many characters to take from `string`. * @param {Object} [options] * `precomposed`: Use one ellipsis character (…) * instead of three periods. Defaults to `false`. * @return {String} The trimmed result. Note that the total length might be up to three characters * more than `maxCharsFromString`. If `string` is falsy or if `maxCharsFromString` is less than 1, * `string` is returned. * @public */ export declare function smartTrim(string: string, maxCharsFromString: number, { precomposed }?: { precomposed?: boolean | undefined; }): string;