UNPKG

2.71 kBTypeScriptView Raw
1import { TypeCode } from './TypeCode';
2/**
3 * Converts arbitrary values into objects specific by TypeCodes.
4 * For each TypeCode this class calls corresponding converter which applies
5 * extended conversion rules to convert the values.
6 *
7 * @see [[TypeCode]]
8 *
9 * ### Example ###
10 *
11 * let value1 = TypeConverter.toType(TypeCode.Integer, "123.456"); // Result: 123
12 * let value2 = TypeConverter.toType(TypeCode.DateTime, 123); // Result: Date(123)
13 * let value3 = TypeConverter.toType(TypeCode.Boolean, "F"); // Result: false
14 */
15export declare class TypeConverter {
16 /**
17 * Gets TypeCode for specific value.
18 *
19 * @param value value whose TypeCode is to be resolved.
20 * @returns the TypeCode that corresponds to the passed object's type.
21 */
22 static toTypeCode(value: any): TypeCode;
23 /**
24 * Converts value into an object type specified by Type Code or returns null when conversion is not possible.
25 *
26 * @param type the TypeCode for the data type into which 'value' is to be converted.
27 * @param value the value to convert.
28 * @returns object value of type corresponding to TypeCode, or null when conversion is not supported.
29 *
30 * @see [[toTypeCode]]
31 */
32 static toNullableType<T>(type: TypeCode, value: any): T;
33 /**
34 * Converts value into an object type specified by Type Code or returns type default when conversion is not possible.
35 *
36 * @param type the TypeCode for the data type into which 'value' is to be converted.
37 * @param value the value to convert.
38 * @returns object value of type corresponding to TypeCode, or type default when conversion is not supported.
39 *
40 * @see [[toNullableType]]
41 * @see [[toTypeCode]]
42 */
43 static toType<T>(type: TypeCode, value: any): T;
44 /**
45 * Converts value into an object type specified by Type Code or returns default value when conversion is not possible.
46 *
47 * @param type the TypeCode for the data type into which 'value' is to be converted.
48 * @param value the value to convert.
49 * @param defaultValue the default value to return if conversion is not possible (returns null).
50 * @returns object value of type corresponding to TypeCode, or default value when conversion is not supported.
51 *
52 * @see [[toNullableType]]
53 * @see [[toTypeCode]]
54 */
55 static toTypeWithDefault<T>(type: TypeCode, value: any, defaultValue: T): T;
56 /**
57 * Converts a TypeCode into its string name.
58 *
59 * @param type the TypeCode to convert into a string.
60 * @returns the name of the TypeCode passed as a string value.
61 */
62 static toString(type: TypeCode): string;
63}