UNPKG

1.79 kBTypeScriptView Raw
1/**
2 * Converts arbitrary values into float using extended conversion rules:
3 * - Strings are converted to float values
4 * - DateTime: total number of milliseconds since unix epoсh
5 * - Boolean: 1 for true and 0 for false
6 *
7 * ### Example ###
8 *
9 * let value1 = FloatConverter.toNullableFloat("ABC"); // Result: null
10 * let value2 = FloatConverter.toNullableFloat("123.456"); // Result: 123.456
11 * let value3 = FloatConverter.toNullableFloat(true); // Result: 1
12 * let value4 = FloatConverter.toNullableFloat(new Date()); // Result: current milliseconds
13 */
14export declare class FloatConverter {
15 /**
16 * Converts value into float or returns null when conversion is not possible.
17 *
18 * @param value the value to convert.
19 * @returns float value or null when conversion is not supported.
20 *
21 * @see [[DoubleConverter.toNullableDouble]]
22 */
23 static toNullableFloat(value: any): number;
24 /**
25 * Converts value into float or returns 0 when conversion is not possible.
26 *
27 * @param value the value to convert.
28 * @returns float value or 0 when conversion is not supported.
29 *
30 * @see [[DoubleConverter.toDouble]]
31 * @see [[DoubleConverter.toDoubleWithDefault]]
32 */
33 static toFloat(value: any): number;
34 /**
35 * Converts value into float or returns default when conversion is not possible.
36 *
37 * @param value the value to convert.
38 * @param defaultValue the default value.
39 * @returns float value or default value when conversion is not supported.
40 *
41 * @see [[DoubleConverter.toDoubleWithDefault]]
42 * @see [[DoubleConverter.toNullableDouble]]
43 */
44 static toFloatWithDefault(value: any, defaultValue: number): number;
45}