UNPKG

@eclipse-scout/core

Version:
85 lines 3.49 kB
import { RoundingMode } from '../index'; export declare const numbers: { /** * Converts the given decimal number to base-62 (i.e. the same value, but represented by [a-zA-Z0-9] instead of only [0-9]). */ toBase62(number: number): string; /** * Returns a random sequence of characters out of the set [a-zA-Z0-9] with the given length. * @param length The default length is 8. */ randomId(length?: number): string; /** * Returns a random integer between 0 (inclusive) and the given `size` (exclusive). * * @param size The default size is {@link Number.MAX_SAFE_INTEGER}. */ randomInt(size?: number): number; /** @internal */ _correlationCounter: number; /** * Generates a random ID suitable for use as correlation ID. * * Example: * * Hq5JY2kz3n/27 * * The ID is generated from two different alphabets: 1. only letter, 2. only digits. By * always selecting a random digit after two random characters, accidental "rude words" * can be prevented. * * The characters[01olOL] are not used at all because they are easily confused. * * For a length of 11 (default), this method can theoretically generate over 200 trillion * different IDs: * * 46^7 * 8^3 = 223'138'640'494'592 * * To further reduce the risk of collisions, a monotonically increasing counter is added * at the end of the result string (separated by "/"). */ correlationId(length?: number): string; /** * Rounds a number to the given number of fraction digits. * * Numbers should not be rounded with the built-in Number.toFixed() method, since it * behaves differently on different browsers. However, it is safe to apply toFixed() * to the result of this method to ensure a fixed number of fraction digits (filled up * with 0's) because this operation does not involve any rounding anymore. * <p> * If fractionDigits is omitted, the number will be rounded to integer by default. * Rounding mode {@link RoundingMode.HALF_UP} is used as default. */ round(number: number, roundingMode?: RoundingMode, fractionDigits?: number): number; /** * Shifts the decimal point in the given number by a certain distance. While the result is also * number, the method uses string operations to move the decimal point. This prevents rounding * errors as long as the number does not exceed JavaScript's Number precision. * * The argument 'move' describes the distance how far the decimal point should be moved: * 0 = do no move (1.57 --> 1.57) * > 0 = move to right (1.57 --> 15.7) * < 0 = move to left (1.57 --> 0.157) */ shiftDecimalPoint(number: number, move: number): number; /** * Ensures that the given number is really a number. * <p> * If it already is a number, the number will be returned. * Otherwise, a Number is created. * * @param number may be of type number or string. */ ensure(number: number | string): number; /** * Returns true if the given number is of type number but not NaN. */ isNumber(number: any): number is number; /** * Returns true if the given number is an integer. */ isInteger(number: any): number is number; /** @internal */ _setCorrelationCounter(val: number): void; }; //# sourceMappingURL=numbers.d.ts.map