r3bl-ts-utils
Version:
The `r3bl-ts-utils` package is a set of useful TypeScript functions and classes that can be used in Node.js and browser environments. They are inspired by Kotlin stdlib, and Rust to write code as expressions rather than statements, colorized text, powerfu
25 lines (24 loc) • 1.71 kB
TypeScript
import { Optional } from "./core";
/**
* https://developer.mozilla.org/en-US/docs/Glossary/Truthy
* @param ctxObject it can be null or undefined
* @param receiverFn lambda that accepts `it`; only runs if `ctxObject` property is truthy
* @return ctxObject the first argument
*/
export declare const _callIfTruthy: <T>(ctxObject: Optional<T>, receiverFn: TruthyReceiverFn<T>) => Optional<T>;
export declare type TruthyReceiverFn<T> = (it: T) => void;
export declare const _callIfTruthyWithReturn: <T, R>(ctxObject: Optional<T>, onTrue: TruthyReceiverWithReturnValueFn<T, R>, onFalse: SimpleReceiverWithReturnValueFn<R>) => R;
export declare type TruthyReceiverWithReturnValueFn<T, R> = (it: T) => R;
/**
* https://developer.mozilla.org/en-US/docs/Glossary/Falsy
* @param ctxObject it can be null or undefined
* @param receiverFn lambda that only runs if `ctxObject` property is falsy
*/
export declare const _callIfFalsy: (ctxObject: unknown, receiverFn: FalsyReceiverFn) => void;
export declare type FalsyReceiverFn = () => void;
export declare const _repeat: (count: number, fun: () => void) => void;
export declare const _callIfTrue: (ctxObject: boolean, onTrueReceiverFn: SimpleReceiverFn, onFalseReceiverFn?: SimpleReceiverFn | undefined) => void;
export declare const _callIfFalse: (ctxObject: boolean, onFalseReceiverFn: SimpleReceiverFn, onTrueReceiverFn?: SimpleReceiverFn | undefined) => void;
export declare type SimpleReceiverFn = () => void;
export declare const _callIfTrueWithReturn: <T>(ctxObject: boolean, onTrueReceiverFn: SimpleReceiverWithReturnValueFn<T>, onFalseReceiverFn: SimpleReceiverWithReturnValueFn<T>) => T;
export declare type SimpleReceiverWithReturnValueFn<T> = () => T;