Fallback String

fallbackString

Returns the provided fallback value if the given value is null, undefined, or an empty string; otherwise, it returns the original value.

Import

import { fallbackString } from '@fullstacksjs/toolbox';

Signature

function fallbackString<T extends string = string>(value: Nullable<T>, fallbackStringValue: T): NonNullable<T> {}

Examples

fallbackString('', 'd')        // 'd'
fallbackString(' ', 'd')       // ' '
fallbackString('x', 'd')       // 'x'
fallbackString(null, 'd')      // 'd'
fallbackString(undefined, 'd') // 'd'