reports/frontend/node_modules/es-toolkit/dist/compat/util/defaultTo.mjs
jtricerolph 1c411e402e Add settings page for managing forecasting API key and URL via UI
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 14:37:36 +00:00

23 lines
798 B
JavaScript

//#region src/compat/util/defaultTo.ts
/**
* Returns the default value for `null`, `undefined`, and `NaN`.
*
* @template T - The type of the value parameter
* @template D - The type of the defaultValue parameter
* @param value - The value to check.
* @param defaultValue - The default value to return if the first value is null, undefined, or NaN.
* @returns Returns either the first value or the default value.
*
* @example
* defaultTo(null, 'default') // returns 'default'
* defaultTo(undefined, 42) // returns 42
* defaultTo(NaN, 0) // returns 0
* defaultTo('actual', 'default') // returns 'actual'
* defaultTo(123, 0) // returns 123
*/
function defaultTo(value, defaultValue) {
if (value == null || Number.isNaN(value)) return defaultValue;
return value;
}
//#endregion
export { defaultTo };