JavaScript
Boolean

Boolean

Boolean utility class that provides various methods for booles.

The Boolean class is extended from the built-in Boolean object. You can continue to use whatever we normally use.

Usage

To use this module, you first need to import the Boolean class:

import { Boolean } from '@ponsetya/core'

Static Methods

Boolean.convert()

The convert() method convert a string to a boolean.

Boolean.convert(value: string): boolean

Throws: When the string cannot be converted to a boolean.

Parameters

value: string
The string to convert.
Returns: boolean
The boolean representation of the string.

Examples

console.log(Boolean.convert('true')) // true
console.log(Boolean.convert('false')) // false

Boolean.is()

The is() method determines whether the passed value is an Boolean.

Boolean.is(value: unknown): boolean

Parameters

value: unkown
The value to be checked.
Returns: boolean
A boolean indicating whether the variable is a boolean.

Examples

console.log(Boolean.is(true)) // true
console.log(Boolean.is(false)) // true
 
console.log(Boolean.is(0)) // false
console.log(Boolean.is(1)) // false