Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TypeConverter

Converts arbitrary values into objects specific by TypeCodes. For each TypeCode this class calls corresponding converter which applies extended conversion rules to convert the values.

see

TypeCode

Example

let value1 = TypeConverter.toType(TypeCode.Integer, "123.456"); // Result: 123
let value2 = TypeConverter.toType(TypeCode.DateTime, 123); // Result: Date(123)
let value3 = TypeConverter.toType(TypeCode.Boolean, "F"); // Result: false

Hierarchy

  • TypeConverter

Index

Methods

Static toNullableType

  • toNullableType<T>(type: TypeCode, value: any): T
  • Converts value into an object type specified by Type Code or returns null when conversion is not possible.

    see

    toTypeCode

    Type parameters

    • T

    Parameters

    • type: TypeCode

      the TypeCode for the data type into which 'value' is to be converted.

    • value: any

      the value to convert.

    Returns T

    object value of type corresponding to TypeCode, or null when conversion is not supported.

Static toString

  • Converts a TypeCode into its string name.

    Parameters

    • type: TypeCode

      the TypeCode to convert into a string.

    Returns string

    the name of the TypeCode passed as a string value.

Static toType

  • toType<T>(type: TypeCode, value: any): T
  • Converts value into an object type specified by Type Code or returns type default when conversion is not possible.

    see

    toNullableType

    see

    toTypeCode

    Type parameters

    • T

    Parameters

    • type: TypeCode

      the TypeCode for the data type into which 'value' is to be converted.

    • value: any

      the value to convert.

    Returns T

    object value of type corresponding to TypeCode, or type default when conversion is not supported.

Static toTypeCode

  • Gets TypeCode for specific value.

    Parameters

    • value: any

      value whose TypeCode is to be resolved.

    Returns TypeCode

    the TypeCode that corresponds to the passed object's type.

Static toTypeWithDefault

  • toTypeWithDefault<T>(type: TypeCode, value: any, defaultValue: T): T
  • Converts value into an object type specified by Type Code or returns default value when conversion is not possible.

    see

    toNullableType

    see

    toTypeCode

    Type parameters

    • T

    Parameters

    • type: TypeCode

      the TypeCode for the data type into which 'value' is to be converted.

    • value: any

      the value to convert.

    • defaultValue: T

      the default value to return if conversion is not possible (returns null).

    Returns T

    object value of type corresponding to TypeCode, or default value when conversion is not supported.

Generated using TypeDoc