The @perfective/common/boolean
package provides types and functions to work with the boolean
type.
Proposition<T>
is a boolean
value,
or a nullary function that returns a boolean
value.
-
isTrue(proposition: Proposition): boolean
— returnstrue
if a givenproposition
istrue
or returnstrue
. Otherwise, returnsfalse
. -
isFalse(proposition: Proposition): boolean
— returnstrue
if a givenproposition
isfalse
or returnsfalse
. Otherwise, returnsfalse
. -
negated(proposition: Proposition): boolean
— returnstrue
if a givenproposition
isfalse
or returnsfalse
. Otherwise, returnsfalse
.
Predicate<T>
is a unary function that returns a boolean
value.
-
isBoolean<T>(value: T | boolean): value is boolean
— returnstrue
if a givenvalue
isboolean
. -
isNotBoolean<T>(value: T | boolean): value is T
— returnstrue
if a givenvalue
is notboolean
. -
isTruthy<T>(value: T): boolean
— returnstrue
when the value is neitherundefined
,null
,false
,NaN
,0
,-0
,0n
(aBigInt
zero),""
(an empty string), or thedocument.all
builtin. -
isFalsy<T>(value: T): boolean
— returnstrue
when the value isundefined
,null
,false
,NaN
,0
,-0
,0n
(aBigInt
zero),""
(an empty string), or thedocument.all
builtin. -
is<T>(input: T): Predicate<T>
— creates aPredicate
that istrue
if its argument strictly equals a giveninput
. -
isNot<T>(input: T): Predicate<T>
— creates aPredicate
that istrue
if its argument does not equal a giveninput
. -
not<T>(predicate: Predicate<T>): Predicate<T>
— creates aPredicate
that inverses the result of a givenPredicate
. -
all<T>(…predicates: Predicate<T>[]): Predicate<T>
— creates aPredicate
that istrue
when all givenpredicates
aretrue
(logicalAND
). -
either<T>(…predicates: Predicate<T>[]): Predicate<T>
— creates aPredicate
that istrue
when at least one of givenpredicates
istrue
(logicalOR
). -
neither<T>(…predicates: Predicate<T>[]): Predicate<T>
— creates aPredicate
that istrue
when none of givenpredicates
istrue
. -
atLeast<T>(minimum: number, …predicates: Predicate<T>[]): Predicate<T>
— creates aPredicate
that istrue
when at least a givenminimum
number of givenpredicates
is true. -
atMost<T>(maximum: number, …predicates: Predicate<T>[]): Predicate<T>
— creates aPredicate
that istrue
when no more than a givenmaximum
number of givenpredicates
is true. -
exactly<T>(count: number, …predicates: Predicate<T>[]): Predicate<T>
— creates aPredicate
that istrue
when exactly a givencount
number of givenpredicates
is true.