UNPKG

libmodulor

Version:

A TypeScript library to create platform-agnostic applications

48 lines (47 loc) 1.33 kB
import type { NumIndex, UIntQuantity } from '../../dt/index.js'; /** * Assert that the value is defined * @param value * @param key * @see isBlank */ export declare function assertIsDefined<T>(value: T, key: string): asserts value is NonNullable<T>; /** * Checker whether the value is blank or not * * Blank means `undefined`, `null`, `''` (if string), `[]` (if array). * * This is insipred by Ruby's `blank?` method. * * @param value * @returns */ export declare function isBlank<T>(value: T | T[] | undefined | null): value is undefined | null; /** * Get an array filled with `[0 .. n-1]` * @param n * @returns */ export declare function range(n: UIntQuantity): NumIndex[]; /** * Get a random item from the array * * Although the name is inspired by Ruby's, the signature and implementation is not exactly the same (for now). * * @param items * @returns */ export declare function sample<T>(items: T[]): T | null; /** * Get the values of an object with the type inferred correctly, even if there is no index signature (e.g. an interface) * @param obj * @returns */ export declare function valuesIn<T extends object>(obj: T): Array<T[keyof T]>; /** * Get an array of size `n` filled with `val` * @param val * @param n * @returns */ export declare function tupleOf<T>(val: T, n: UIntQuantity): T[];