Skip to main content
Module

x/unknownutil/mod.ts>maybe

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function maybe
import { maybe } from "https://deno.land/x/unknownutil@v3.18.0/mod.ts";

Returns the input value if it satisfies the provided predicate, or undefined otherwise.

import { is, maybe } from "@core/unknownutil";

const a: unknown = "hello";
const _: string = maybe(a, is.String) ?? "default value";

Parameters

x: unknown

The value to be tested.

pred: Predicate<T>

The predicate function to test the value against.

Returns

T | undefined

The input value x if it satisfies the predicate, or undefined otherwise.