Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BooleanConverter

Converts arbitrary values to boolean values using extended conversion rules:

  • Numbers: <>0 are true, =0 are false
  • Strings: "true", "yes", "T", "Y", "1" are true; "false", "no", "F", "N" are false
  • DateTime: <>0 total milliseconds are true, =0 are false

Example

let value1 = BooleanConverter.toNullableBoolean(true); // true
let value2 = BooleanConverter.toNullableBoolean("yes"); // true
let value3 = BooleanConverter.toNullableBoolean(123); // true
let value4 = BooleanConverter.toNullableBoolean({}); // null

Hierarchy

  • BooleanConverter

Index

Methods

Static toBoolean

  • toBoolean(value: any): boolean
  • Converts value into boolean or returns false when conversion is not possible.

    see

    toBooleanWithDefault

    Parameters

    • value: any

      the value to convert.

    Returns boolean

    boolean value or false when conversion is not supported.

Static toBooleanWithDefault

  • toBooleanWithDefault(value: any, defaultValue?: boolean): boolean
  • Converts value into boolean or returns default value when conversion is not possible

    see

    toNullableBoolean

    Parameters

    • value: any

      the value to convert.

    • Default value defaultValue: boolean = false

      the default value

    Returns boolean

    boolean value or default when conversion is not supported.

Static toNullableBoolean

  • toNullableBoolean(value: any): boolean
  • Converts value into boolean or returns null when conversion is not possible.

    Parameters

    • value: any

      the value to convert.

    Returns boolean

    boolean value or null when convertion is not supported.

Generated using TypeDoc