Skip to main content

toBoolean()

toBoolean(val): boolean

Returns true for any value not found to be a "false" value.

Parameters

val

unknown

The value to convert to a boolean.

"false" values

  • inherently false values: '' (empty string), 0, false, undefined, null, NaN
  • numeric zero: '0.000' - any number of leading or trailing zeros
  • string literal: 'false' - any capitalizations or space-padding

For more restrictive comparisons against: true, false, on, off, yes, no; see the predicates package (@accelint/predicates).

Returns

boolean

Remarks

pure function

Playground

import { toBoolean } from '@accelint/converters';

console.log(toBoolean(1));          // true
console.log(toBoolean(' FaLsE '));  // false
console.log(toBoolean('  true'));   // true
console.log(toBoolean('000.000'));  // false