TS-Scribe - v0.6.2
    Preparing search index...

    Function parseBoolean

    • Parses a value and converts it to a boolean. It supports different types of input, including strings, numbers, booleans, null, and undefined.

      • If the value is a boolean, it is returned as-is.
      • If the value is a number, it is interpreted as 0 for false and 1 for true.
      • If the value is a string, it is converted to lowercase and compared against the values 'true', '1', 'false', and '0'.
      • If the value is null or undefined, the provided defaultValue is returned or false if no defaultValue is provided.

      Parameters

      • value: string | number | boolean | undefined

        The value to be parsed as a boolean.

      • OptionaldefaultValue: boolean = false

        The default value to return if the input is null, undefined, or cannot be parsed. Defaults to false.

      Returns boolean

      The parsed boolean value.

      parseBoolean('true'); // Returns true
      parseBoolean(1); // Returns true
      parseBoolean('false'); // Returns false
      parseBoolean(0); // Returns false
      parseBoolean(null, true); // Returns true
      parseBoolean(undefined, true); // Returns true
      parseBoolean('some string', false); // Returns false