UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines (24 loc) 558 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/option/or.ts /** * `or(target, or)` * * Returns the target value if it's not `null` or `undefined`, otherwise returns the fallback value. Uses the nullish coalescing operator to provide a default value for null or undefined inputs. * * ```ts * or(5, 10); // 5 * or(null, 10); // 10 * or(undefined, 10); // 10 * or(0, 10); // 0 * ``` * * ```ts * pipe(5, or(10)); // 5 * pipe(null, or(10)); // 10 * ``` */ const or = dfdlT((target, or$1) => { return target ?? or$1; }, 2); //#endregion export { or };