Skip to main content
Module

x/silicon/deps.ts>maybe

Deno module to generate images from source code using Aloxaf/silicon.
Latest
function maybe
import { maybe } from "https://deno.land/x/silicon@v1.0.0/deps.ts";

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

import { maybe } from "./util.ts";
import is from "./is.ts";

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.