Skip to main content
Module

x/nameable/deps.ts>ifElse

Cross-check whether it can be used as a package name or domain name
Latest
variable ifElse
import { ifElse } from "https://deno.land/x/nameable@v1.1.0-beta.4/deps.ts";

Return the onTrue or the onFalse value depending upon the result of the condition val.

Examples

Example 1

ifElse(true, 1, 0) // 1
ifElse(false, 1, 0) // 0
ifElse(undefined, 1, 0) // 0
ifElse(() => true, () => 1, () => 0) // 1

type

<V, T, F>(
val: V | AnyFn<any, V>,
onTrue: T | AnyFn<any, T>,
onFalse: F | AnyFn<any, F>,
) => V extends FalsyLike ? F : V extends true ? T : T | F