@thepassle/app-tools
Version:
Collection of tools I regularly use to build apps. Maybe they're useful to somebody else. Maybe not. Most of these are thin wrappers around native API's, like the native `<dialog>` element, `fetch` API, and `URLPattern`.
18 lines (17 loc) • 368 B
JavaScript
/**
* Syntax sugar to conditionally render a template
*
* @param {boolean} expression
* @param {() => any} trueValue
* @param {() => any} [falseValue]
* @returns {any | undefined}
*/
export function when(expression, trueValue, falseValue) {
if (expression) {
return trueValue();
}
if (falseValue) {
return falseValue();
}
return undefined;
}